Writted peertube and discordParser class, and added many test.
This commit is contained in:
55
tests/discord-spec.ts
Normal file
55
tests/discord-spec.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import chai 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';
|
||||
|
||||
//data
|
||||
const config: DiscordParser.Config = {
|
||||
channelsId: {
|
||||
idChannelPeerTube: 'peertubeID',
|
||||
idChannelYtb: 'ytbChannel',
|
||||
},
|
||||
keyWord: 'myDiscordKeyword',
|
||||
name: 'DiscordTestedInterface',
|
||||
token: 'mySecretDiscordToken',
|
||||
};
|
||||
|
||||
//stubed 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>;
|
||||
before(() => {
|
||||
clientStub = sinon.createStubInstance(Client);
|
||||
clientStub.login.withArgs(config.token).onFirstCall().resolves('ok');
|
||||
clientStub.login.throws('Error, bad parameter or too much call');
|
||||
|
||||
channelManagerStub = sinon.createStubInstance(ChannelManager);
|
||||
channelManagerStub.resolve
|
||||
.withArgs(config.channelsId.idChannelPeerTube)
|
||||
.onFirstCall()
|
||||
.returns(new Channel(new Client()))
|
||||
.withArgs(config.channelsId.idChannelYtb)
|
||||
.onFirstCall()
|
||||
.returns(new Channel(new Client()));
|
||||
channelManagerStub.resolve.throws("Error Bad id's or too much call");
|
||||
});
|
||||
|
||||
after(() => {
|
||||
clientStub.login.restore();
|
||||
channelManagerStub.resolve.restore();
|
||||
});
|
||||
it('it will test the DiscordParser constructor', function () {
|
||||
const discordParser = new DiscordParser(config);
|
||||
|
||||
console.log("c'est bon signe");
|
||||
});
|
||||
});
|
@ -1,54 +1,54 @@
|
||||
import chai from "chai";
|
||||
import sinon from "ts-sinon";
|
||||
import sinonChai from "sinon-chai";
|
||||
import chai from 'chai';
|
||||
import sinon from 'ts-sinon';
|
||||
import sinonChai from 'sinon-chai';
|
||||
|
||||
chai.use(sinonChai)
|
||||
chai.use(sinonChai);
|
||||
const expect = chai.expect;
|
||||
|
||||
import { withFile } from "tmp-promise"
|
||||
import { writeFileSync } from "fs";
|
||||
|
||||
import { Router } from "../src/index";
|
||||
import { DiscordParser } from "../src/discordParser";
|
||||
import { LogWriter } from "../src/logWriter";
|
||||
import { PeerTubeRequester } from "../src/peertubeRequester";
|
||||
import { withFile } from 'tmp-promise';
|
||||
import { writeFileSync } from 'fs';
|
||||
|
||||
import { Router } from '../src/index';
|
||||
import { DiscordParser } from '../src/discordParser';
|
||||
import { LogWriter } from '../src/logWriter';
|
||||
import { PeerTubeRequester } from '../src/peertubeRequester';
|
||||
|
||||
// const path = require("path");
|
||||
const well_build_routing_file: Router.GlobalConfig = require("./rsrc/wellBuildedRoutingFile.json");
|
||||
const well_build_routing_file: Router.GlobalConfig = require('./rsrc/wellBuildedRoutingFile.json');
|
||||
|
||||
describe("testing the routing part", function () {
|
||||
describe("testing the building part", function () {
|
||||
it("it will test a normal building", async function () {
|
||||
await withFile(async (file) => {
|
||||
const edit_config = {
|
||||
...well_build_routing_file,
|
||||
logWriter: {
|
||||
...well_build_routing_file.logWriter,
|
||||
...{path: file.path}
|
||||
}
|
||||
};
|
||||
const r = new Router(edit_config);
|
||||
describe('testing the routing part', function () {
|
||||
describe('testing the building part', function () {
|
||||
it('it will test a normal building', async function () {
|
||||
await withFile(
|
||||
async (file) => {
|
||||
const edit_config = {
|
||||
...well_build_routing_file,
|
||||
logWriter: {
|
||||
...well_build_routing_file.logWriter,
|
||||
...{ path: file.path },
|
||||
},
|
||||
};
|
||||
const r = new Router(edit_config);
|
||||
|
||||
expect(r.api_array['Discord']).to.be.instanceOf(DiscordParser);
|
||||
expect(r.api_array['logWriter']).to.be.instanceOf(LogWriter);
|
||||
expect(r.api_array['peertubeRequester']).to.be.instanceOf(PeerTubeRequester);
|
||||
|
||||
}, {postfix: '.log'})
|
||||
|
||||
})
|
||||
})
|
||||
describe("testing the data transmission", function () {
|
||||
it("it will emit a upload request message", function () {
|
||||
|
||||
})
|
||||
it("it will emit a new listener request", function () {
|
||||
|
||||
})
|
||||
})
|
||||
describe("testing the data reception", function () {
|
||||
it("it will received a new entries notification", function() {
|
||||
|
||||
})
|
||||
})
|
||||
});
|
||||
expect(r.api_array['Discord']).to.be.instanceOf(
|
||||
DiscordParser
|
||||
);
|
||||
expect(r.api_array['logWriter']).to.be.instanceOf(
|
||||
LogWriter
|
||||
);
|
||||
expect(r.api_array['peertubeRequester']).to.be.instanceOf(
|
||||
PeerTubeRequester
|
||||
);
|
||||
},
|
||||
{ postfix: '.log' }
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('testing the data transmission', function () {
|
||||
it('it will emit a upload request message', function () {});
|
||||
it('it will emit a new listener request', function () {});
|
||||
});
|
||||
describe('testing the data reception', function () {
|
||||
it('it will received a new entries notification', function () {});
|
||||
});
|
||||
});
|
||||
|
123
tests/peertubeRequeter-spec.ts
Normal file
123
tests/peertubeRequeter-spec.ts
Normal file
@ -0,0 +1,123 @@
|
||||
import chai 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 { ImplementableApi } from '../src';
|
||||
import { PeerTubeRequester } from '../src/peertubeRequester';
|
||||
import { Request } from 'node-fetch';
|
||||
|
||||
const paramsPeerTube: PeerTubeRequester.Config = {
|
||||
name: 'testedRequester',
|
||||
domain_name: 'myApiAddress.yolo',
|
||||
password: 'mySuperSecretPassphrase',
|
||||
username: 'myUsername',
|
||||
};
|
||||
|
||||
const newEntriesMessage: ImplementableApi.Message = {
|
||||
type: 'newEntriesNotify',
|
||||
rawContent: {
|
||||
items: [
|
||||
{
|
||||
author: 'channel1',
|
||||
link: 'link1',
|
||||
title: 'title1',
|
||||
},
|
||||
{
|
||||
author: 'channel2',
|
||||
link: 'link2',
|
||||
title: 'title2',
|
||||
},
|
||||
{
|
||||
author: 'channel3',
|
||||
link: 'link3',
|
||||
title: 'title3',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const UploadInstruction = {
|
||||
channelID: 'undefined', //todo uncompleted test but incompleted function too
|
||||
targetUrl: 'myTargerUrl',
|
||||
};
|
||||
|
||||
// nock data
|
||||
const expectedReplyOauthClient = {
|
||||
client_id: 'expectedClientID',
|
||||
client_secret: 'expectedClientSecret',
|
||||
};
|
||||
|
||||
const expectedReplyTokenAddress = {
|
||||
access_token: 'expectedAccessToken',
|
||||
};
|
||||
|
||||
const bodyTokenRequest: RequestBodyMatcher = {
|
||||
client_id: expectedReplyOauthClient.client_id,
|
||||
client_secret: expectedReplyOauthClient.client_secret,
|
||||
grant_type: 'password',
|
||||
response_type: 'code',
|
||||
username: paramsPeerTube.username,
|
||||
password: paramsPeerTube.password,
|
||||
};
|
||||
describe('PeerTube Requester Test', function () {
|
||||
before(function () {
|
||||
disableNetConnect();
|
||||
});
|
||||
|
||||
after(function () {
|
||||
nock.cleanAll();
|
||||
});
|
||||
|
||||
it('it will test the upload function', async function () {
|
||||
// given
|
||||
const scope = nock(`https://${paramsPeerTube.domain_name}/api/v1`)
|
||||
.get(`/oauth-clients/local`)
|
||||
.times(3)
|
||||
.reply(200, expectedReplyOauthClient)
|
||||
.post(`/users/token`, bodyTokenRequest)
|
||||
.times(3)
|
||||
.reply(200, expectedReplyTokenAddress)
|
||||
.post(`/videos/imports`, {
|
||||
channelID: 'undefined',
|
||||
targeUrl: newEntriesMessage.rawContent.items[0].link,
|
||||
})
|
||||
.matchHeader(
|
||||
'Authorization',
|
||||
`Bearer ${expectedReplyTokenAddress.access_token}`
|
||||
)
|
||||
.reply(200)
|
||||
.post(`/videos/imports`, {
|
||||
channelID: 'undefined',
|
||||
targeUrl: newEntriesMessage.rawContent.items[1].link,
|
||||
})
|
||||
.matchHeader(
|
||||
'Authorization',
|
||||
`Bearer ${expectedReplyTokenAddress.access_token}`
|
||||
)
|
||||
.reply(200)
|
||||
.post(`/videos/imports`, {
|
||||
channelID: 'undefined',
|
||||
targeUrl: newEntriesMessage.rawContent.items[2].link,
|
||||
})
|
||||
.matchHeader(
|
||||
'Authorization',
|
||||
`Bearer ${expectedReplyTokenAddress.access_token}`
|
||||
)
|
||||
.reply(200);
|
||||
|
||||
if (scope.isDone()) console.log(scope.activeMocks());
|
||||
|
||||
const requester = new PeerTubeRequester(paramsPeerTube);
|
||||
|
||||
// when
|
||||
await requester.receivedMessage(newEntriesMessage);
|
||||
|
||||
//expected
|
||||
if (scope.isDone()) console.log(scope.activeMocks());
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user