Add test logWriter + more things inside my other tests

This commit is contained in:
Amaury
2021-06-04 13:19:43 +02:00
parent 8b3e2535e2
commit 7fc2e29f0e
10 changed files with 223 additions and 101 deletions

View File

@ -1,11 +1,8 @@
import chai from 'chai';
import chai, { expect } from 'chai';
import sinon from 'ts-sinon';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);
const expect = chai.expect;
import nock, { disableNetConnect, RequestBodyMatcher } from 'nock';
import { DiscordParser } from '../src/discordParser';
@ -20,36 +17,61 @@ const config: DiscordParser.Config = {
token: 'mySecretDiscordToken',
};
//stubed imports
//mockeded imports
import { Channel, ChannelManager, Client } from 'discord.js';
import { utils } from 'mocha';
describe.only('test DiscordParser', function () {
let clientStub: sinon.SinonStubbedInstance<Client>,
channelManagerStub: sinon.SinonStubbedInstance<ChannelManager>;
describe.skip('test DiscordParser', function () {
let clientMockOn: sinon.SinonStub,
clientMockLogin: sinon.SinonStub,
channelStub: sinon.SinonStubbedInstance<Channel>,
channelManagerMockResolve: sinon.SinonStub;
before(() => {
clientStub = sinon.createStubInstance(Client);
clientStub.login.withArgs(config.token).onFirstCall().resolves('ok');
clientStub.login.throws('Error, bad parameter or too much call');
clientMockOn = sinon.stub(Client.prototype, 'on');
clientMockOn.withArgs('message', sinon.match.func).onFirstCall();
clientMockOn.throws('Error, bad parameter or too much call');
channelManagerStub = sinon.createStubInstance(ChannelManager);
channelManagerStub.resolve
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(new Channel(new Client()))
.returns(channelStub);
channelManagerMockResolve
.withArgs(config.channelsId.idChannelYtb)
.onFirstCall()
.returns(new Channel(new Client()));
channelManagerStub.resolve.throws("Error Bad id's or too much call");
.returns(channelStub);
channelManagerMockResolve.throws("Error Bad id's or too much call");
});
after(() => {
clientStub.login.restore();
channelManagerStub.resolve.restore();
clientMockOn.restore();
clientMockLogin.restore();
channelManagerMockResolve.restore();
});
it('it will test the DiscordParser constructor', function () {
it('it will test the DiscordParser constructor', async function () {
//when
const discordParser = new DiscordParser(config);
console.log("c'est bon signe");
// expect
expect(discordParser.token).to.be.eql(config.token);
await discordParser.channels.then((channels) => {
expect(channels.ChannelYtb.id).to.be.eql(
config.channelsId.idChannelYtb
);
});
});
});