2017-12-15 16:24:29 +01:00
|
|
|
const chai = require('chai');
|
|
|
|
const expect = chai.expect;
|
|
|
|
const chaiHttp = require('chai-http');
|
2017-12-15 21:21:33 +01:00
|
|
|
const { host } = require('../../config/speechConfig.js').site;
|
2017-12-15 23:10:34 +01:00
|
|
|
const requestTimeout = 20000;
|
|
|
|
const publishTimeout = 120000;
|
|
|
|
const fs = require('fs');
|
2017-12-15 16:24:29 +01:00
|
|
|
|
|
|
|
chai.use(chaiHttp);
|
|
|
|
|
2017-12-15 21:28:02 +01:00
|
|
|
function testFor200StatusResponse (host, url) {
|
2017-12-15 23:10:34 +01:00
|
|
|
return it(`should receive a status code 200 within ${requestTimeout}ms`, function (done) {
|
2017-12-15 16:24:29 +01:00
|
|
|
chai.request(host)
|
|
|
|
.get(url)
|
|
|
|
.end(function (err, res) {
|
|
|
|
expect(err).to.be.null;
|
|
|
|
expect(res).to.have.status(200);
|
|
|
|
done();
|
|
|
|
});
|
2017-12-15 23:10:34 +01:00
|
|
|
}).timeout(requestTimeout);
|
2017-12-15 16:24:29 +01:00
|
|
|
}
|
|
|
|
|
2017-12-15 21:28:02 +01:00
|
|
|
function testShowRequestFor200StatusResponse (host, url) {
|
2017-12-15 23:10:34 +01:00
|
|
|
return it(`should receive a status code 200 within ${requestTimeout}ms`, function (done) {
|
2017-12-15 16:24:29 +01:00
|
|
|
chai.request(host)
|
|
|
|
.get(url)
|
|
|
|
.set('accept', 'text/html')
|
|
|
|
.end(function (err, res) {
|
|
|
|
expect(err).to.be.null;
|
|
|
|
expect(res).to.have.status(200);
|
|
|
|
done();
|
|
|
|
});
|
2017-12-15 23:10:34 +01:00
|
|
|
}).timeout(requestTimeout);
|
2017-12-15 16:24:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('end-to-end', function () {
|
|
|
|
describe('serve requests not from browser', function () {
|
|
|
|
const claimUrl = '/doitlive.jpg';
|
|
|
|
const claimUrlWithShortClaimId = '/d/doitlive.jpg';
|
|
|
|
const claimUrlWithLongClaimId = '/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg';
|
|
|
|
|
|
|
|
describe(claimUrl, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testFor200StatusResponse(host, claimUrl);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
describe(claimUrlWithShortClaimId, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testFor200StatusResponse(host, claimUrlWithShortClaimId);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
describe(claimUrlWithLongClaimId, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testFor200StatusResponse(host, claimUrlWithShortClaimId);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('show requests from browser', function () {
|
|
|
|
const claimUrl = '/doitlive';
|
|
|
|
const claimUrlWithShortClaimId = '/d/doitlive';
|
|
|
|
const claimUrlWithLongClaimId = '/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive';
|
|
|
|
|
|
|
|
describe(claimUrl, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testShowRequestFor200StatusResponse(host, claimUrl);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
describe(claimUrlWithShortClaimId, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
describe(claimUrlWithLongClaimId, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('serve requests browser (show lite)', function () {
|
|
|
|
const claimUrl = '/doitlive.jpg';
|
|
|
|
const claimUrlWithShortClaimId = '/d/doitlive.jpg';
|
|
|
|
const claimUrlWithLongClaimId = '/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg';
|
|
|
|
|
|
|
|
describe(claimUrl, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testShowRequestFor200StatusResponse(host, claimUrl);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
describe(claimUrlWithShortClaimId, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
describe(claimUrlWithLongClaimId, function () {
|
2017-12-15 21:28:02 +01:00
|
|
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId);
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|
|
|
|
});
|
2017-12-15 23:10:34 +01:00
|
|
|
|
|
|
|
describe('publish', function () {
|
|
|
|
const publishUrl = '/api/claim-publish';
|
2017-12-18 23:18:42 +01:00
|
|
|
const date = new Date();
|
|
|
|
const name = `test-publish-${date.getFullYear()}-${date.getMonth()}-${date.getDate()}-${date.getTime()}`;
|
2017-12-19 00:23:23 +01:00
|
|
|
const filePath = './test/mock-data/bird.jpeg';
|
2017-12-15 23:10:34 +01:00
|
|
|
const fileName = 'byrd.jpeg';
|
|
|
|
|
|
|
|
describe(publishUrl, function () {
|
2017-12-19 00:23:23 +01:00
|
|
|
it(`should receive a status code 200 within ${publishTimeout}ms @usesLbc`, function (done) {
|
2017-12-15 23:10:34 +01:00
|
|
|
chai.request(host)
|
|
|
|
.post(publishUrl)
|
|
|
|
.type('form')
|
|
|
|
.attach('file', fs.readFileSync(filePath), fileName)
|
|
|
|
.field('name', name)
|
|
|
|
.end(function (err, res) {
|
|
|
|
// expect(err).to.be.null;
|
|
|
|
expect(res).to.have.status(200);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}).timeout(publishTimeout);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-12-15 16:24:29 +01:00
|
|
|
});
|