routing/tests/discord-spec.ts

78 lines
2.3 KiB
TypeScript

import chai, { expect } from 'chai';
import sinon from 'ts-sinon';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);
import { DiscordParser } from '../src/discordParser';
//data
const config: DiscordParser.Config = {
channelsId: {
idChannelPeerTube: 'peertubeID',
idChannelYtb: 'ytbChannel',
},
keyWord: 'myDiscordKeyword',
name: 'DiscordTestedInterface',
token: 'mySecretDiscordToken',
};
//mockeded imports
import { Channel, ChannelManager, Client } from 'discord.js';
describe.skip('test DiscordParser', function () {
let clientMockOn: sinon.SinonStub,
clientMockLogin: sinon.SinonStub,
channelStub: sinon.SinonStubbedInstance<Channel>,
channelManagerMockResolve: sinon.SinonStub;
before(() => {
clientMockOn = sinon.stub(Client.prototype, 'on');
clientMockOn.withArgs('message', sinon.match.func).onFirstCall();
clientMockOn.throws('Error, bad parameter or too much call');
clientMockLogin = sinon.stub(Client.prototype, 'login');
clientMockLogin
.withArgs(config.token)
.onFirstCall()
.resolves('ok')
.returnsThis();
clientMockLogin.throws('Error, bad parameter or too much call');
channelStub = sinon.createStubInstance(Channel);
channelManagerMockResolve = sinon.stub(
ChannelManager.prototype,
'resolve'
);
channelManagerMockResolve
.withArgs(config.channelsId.idChannelPeerTube)
.onFirstCall()
.returns(channelStub);
channelManagerMockResolve
.withArgs(config.channelsId.idChannelYtb)
.onFirstCall()
.returns(channelStub);
channelManagerMockResolve.throws("Error Bad id's or too much call");
});
after(() => {
clientMockOn.restore();
clientMockLogin.restore();
channelManagerMockResolve.restore();
});
it('it will test the DiscordParser constructor', async function () {
//when
const discordParser = new DiscordParser(config);
// expect
expect(discordParser.token).to.be.eql(config.token);
await discordParser.channels.then((channels) => {
expect(channels.ChannelYtb.id).to.be.eql(
config.channelsId.idChannelYtb
);
});
});
});