Testing #307
6 changed files with 157 additions and 92 deletions
|
@ -1,2 +1,3 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
public/
|
public/
|
||||||
|
test
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
],
|
],
|
||||||
"semi": [
|
"semi": [
|
||||||
"error",
|
"error",
|
||||||
"always",
|
"always",
|
||||||
{ "omitLastInOneLineBlock": true }
|
{ "omitLastInOneLineBlock": true }
|
||||||
],
|
],
|
||||||
"key-spacing": [
|
"key-spacing": [
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "a single-serving site that reads and publishes images to and from the LBRY blockchain",
|
"description": "a single-serving site that reads and publishes images to and from the LBRY blockchain",
|
||||||
"main": "speech.js",
|
"main": "speech.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha",
|
"test": "mocha --recursive",
|
||||||
"start": "node speech.js",
|
"start": "node speech.js",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"fix": "eslint . --fix",
|
"fix": "eslint . --fix",
|
||||||
|
@ -40,6 +40,8 @@
|
||||||
"nodemon": "^1.11.0",
|
"nodemon": "^1.11.0",
|
||||||
"passport": "^0.4.0",
|
"passport": "^0.4.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
|
"request": "^2.83.0",
|
||||||
|
"request-promise": "^4.2.2",
|
||||||
"sequelize": "^4.1.0",
|
"sequelize": "^4.1.0",
|
||||||
"sequelize-cli": "^3.0.0-3",
|
"sequelize-cli": "^3.0.0-3",
|
||||||
"sleep": "^5.1.1",
|
"sleep": "^5.1.1",
|
||||||
|
@ -48,6 +50,8 @@
|
||||||
"winston-slack-webhook": "billbitt/winston-slack-webhook"
|
"winston-slack-webhook": "billbitt/winston-slack-webhook"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"chai": "^4.1.2",
|
||||||
|
"chai-http": "^3.0.0",
|
||||||
"eslint": "3.19.0",
|
"eslint": "3.19.0",
|
||||||
"eslint-config-standard": "10.2.1",
|
"eslint-config-standard": "10.2.1",
|
||||||
"eslint-plugin-import": "^2.2.0",
|
"eslint-plugin-import": "^2.2.0",
|
||||||
|
|
81
test/end-to-end/end-to-end.tests.js
Normal file
81
test/end-to-end/end-to-end.tests.js
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
const chai = require('chai');
|
||||||
|
const expect = chai.expect;
|
||||||
|
const chaiHttp = require('chai-http');
|
||||||
|
const host = 'http://dev1.spee.ch';
|
||||||
|
|
||||||
|
chai.use(chaiHttp);
|
||||||
|
|
||||||
|
function testFor200StatusResponse (host, url, timeout) {
|
||||||
|
return it(`should receive a status code 200 within ${timeout}ms`, function (done) {
|
||||||
|
chai.request(host)
|
||||||
|
.get(url)
|
||||||
|
.end(function (err, res) {
|
||||||
|
expect(err).to.be.null;
|
||||||
|
expect(res).to.have.status(200);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}).timeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testShowRequestFor200StatusResponse (host, url, timeout) {
|
||||||
|
return it(`should receive a status code 200 within ${timeout}ms`, function (done) {
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
}).timeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 () {
|
||||||
|
testFor200StatusResponse(host, claimUrl, 10000);
|
||||||
|
});
|
||||||
|
describe(claimUrlWithShortClaimId, function () {
|
||||||
|
testFor200StatusResponse(host, claimUrlWithShortClaimId, 10000);
|
||||||
|
});
|
||||||
|
describe(claimUrlWithLongClaimId, function () {
|
||||||
|
testFor200StatusResponse(host, claimUrlWithShortClaimId, 10000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('show requests from browser', function () {
|
||||||
|
const claimUrl = '/doitlive';
|
||||||
|
const claimUrlWithShortClaimId = '/d/doitlive';
|
||||||
|
const claimUrlWithLongClaimId = '/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive';
|
||||||
|
|
||||||
|
describe(claimUrl, function () {
|
||||||
|
testShowRequestFor200StatusResponse(host, claimUrl, 10000);
|
||||||
|
});
|
||||||
|
describe(claimUrlWithShortClaimId, function () {
|
||||||
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId, 10000);
|
||||||
|
});
|
||||||
|
describe(claimUrlWithLongClaimId, function () {
|
||||||
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId, 10000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('serve requests browser (show lite)', function () {
|
||||||
|
const claimUrl = '/doitlive.jpg';
|
||||||
|
const claimUrlWithShortClaimId = '/d/doitlive.jpg';
|
||||||
|
const claimUrlWithLongClaimId = '/ca3023187e901df9e9aabd95d6ae09b6cc69b3f0/doitlive.jpg';
|
||||||
|
|
||||||
|
describe(claimUrl, function () {
|
||||||
|
testShowRequestFor200StatusResponse(host, claimUrl, 10000);
|
||||||
|
});
|
||||||
|
describe(claimUrlWithShortClaimId, function () {
|
||||||
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId, 10000);
|
||||||
|
});
|
||||||
|
describe(claimUrlWithLongClaimId, function () {
|
||||||
|
testShowRequestFor200StatusResponse(host, claimUrlWithShortClaimId, 10000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
68
test/helpers/publishHelpers.test.js
Normal file
68
test/helpers/publishHelpers.test.js
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
describe('publishHelpers.js', function () {
|
||||||
|
const publishHelpers = require('../../helpers/publishHelpers.js');
|
||||||
|
|
||||||
|
describe('#parsePublishApiRequestBody()', function () {
|
||||||
|
it('should throw an error if no body', function () {
|
||||||
|
assert.throws(publishHelpers.parsePublishApiRequestBody.bind(this, null), Error);
|
||||||
|
});
|
||||||
|
it('should throw an error if no body.name', function () {
|
||||||
|
const bodyNoName = {};
|
||||||
|
assert.throws(publishHelpers.parsePublishApiRequestBody.bind(this, bodyNoName), Error);
|
||||||
|
});
|
||||||
|
it('should throw an error if no body.name', function () {
|
||||||
|
const body = {
|
||||||
|
name: 'bob',
|
||||||
|
};
|
||||||
|
assert.doesNotThrow(publishHelpers.parsePublishApiRequestBody.bind(this, body), Error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#parsePublishApiRequestFiles()', function () {
|
||||||
|
it('should throw an error if no files', function () {
|
||||||
|
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, null), Error);
|
||||||
|
});
|
||||||
|
it('should throw an error if no files.file', function () {
|
||||||
|
const filesNoFile = {};
|
||||||
|
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoFile), Error);
|
||||||
|
});
|
||||||
|
it('should throw an error if file.size is too large', function () {
|
||||||
|
const filesTooBig = {
|
||||||
|
file: {
|
||||||
|
name: 'file.jpg',
|
||||||
|
path: '/path/to/file.jpg',
|
||||||
|
type: 'image/jpg',
|
||||||
|
size: 10000001,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesTooBig), Error);
|
||||||
|
});
|
||||||
|
it('should throw error if not an accepted file type', function () {
|
||||||
|
const filesNoProblems = {
|
||||||
|
file: {
|
||||||
|
name: 'file.jpg',
|
||||||
|
path: '/path/to/file.jpg',
|
||||||
|
type: 'someType/ext',
|
||||||
|
size: 10000000,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
||||||
|
});
|
||||||
|
it('should throw NO error if no problems', function () {
|
||||||
|
const filesNoProblems = {
|
||||||
|
file: {
|
||||||
|
name: 'file.jpg',
|
||||||
|
path: '/path/to/file.jpg',
|
||||||
|
type: 'image/jpg',
|
||||||
|
size: 10000000,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert.doesNotThrow(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#parsePublishApiChannel()', function () {
|
||||||
|
it('should pass the tests I write here');
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,89 +0,0 @@
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
describe('api', function () {
|
|
||||||
describe('api/publish', function () {
|
|
||||||
describe('publishHelpers.js', function () {
|
|
||||||
const publishHelpers = require('../helpers/publishHelpers.js');
|
|
||||||
|
|
||||||
describe('#parsePublishApiRequestBody()', function () {
|
|
||||||
it('should throw an error if no body', function () {
|
|
||||||
assert.throws(publishHelpers.parsePublishApiRequestBody.bind(this, null), Error);
|
|
||||||
});
|
|
||||||
it('should throw an error if no body.name', function () {
|
|
||||||
const bodyNoName = {};
|
|
||||||
assert.throws(publishHelpers.parsePublishApiRequestBody.bind(this, bodyNoName), Error);
|
|
||||||
});
|
|
||||||
it('should throw an error if no body.name', function () {
|
|
||||||
const body = {
|
|
||||||
name: 'bob',
|
|
||||||
};
|
|
||||||
assert.doesNotThrow(publishHelpers.parsePublishApiRequestBody.bind(this, body), Error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#parsePublishApiRequestFiles()', function () {
|
|
||||||
it('should throw an error if no files', function () {
|
|
||||||
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, null), Error);
|
|
||||||
});
|
|
||||||
it('should throw an error if no files.file', function () {
|
|
||||||
const filesNoFile = {};
|
|
||||||
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoFile), Error);
|
|
||||||
});
|
|
||||||
it('should throw an error if file.size is too large', function () {
|
|
||||||
const filesTooBig = {
|
|
||||||
file: {
|
|
||||||
name: 'file.jpg',
|
|
||||||
path: '/path/to/file.jpg',
|
|
||||||
type: 'image/jpg',
|
|
||||||
size: 10000001,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesTooBig), Error);
|
|
||||||
});
|
|
||||||
it('should throw error if not an accepted file type', function () {
|
|
||||||
const filesNoProblems = {
|
|
||||||
file: {
|
|
||||||
name: 'file.jpg',
|
|
||||||
path: '/path/to/file.jpg',
|
|
||||||
type: 'someType/ext',
|
|
||||||
size: 10000000,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
|
||||||
});
|
|
||||||
it('should throw NO error if no problems', function () {
|
|
||||||
const filesNoProblems = {
|
|
||||||
file: {
|
|
||||||
name: 'file.jpg',
|
|
||||||
path: '/path/to/file.jpg',
|
|
||||||
type: 'image/jpg',
|
|
||||||
size: 10000000,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
assert.doesNotThrow(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('#parsePublishApiChannel()', function () {
|
|
||||||
it('should return a channel name if one is provided', function () {
|
|
||||||
// assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, null), Error);
|
|
||||||
});
|
|
||||||
it('should return a password if one is provided', function () {
|
|
||||||
// assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoFile), Error);
|
|
||||||
});
|
|
||||||
it('should return a channel name if one is provided in req.user', function () {
|
|
||||||
// assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesTooBig), Error);
|
|
||||||
});
|
|
||||||
it('should return a password if one is provided in req.user', function () {
|
|
||||||
// assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
|
||||||
});
|
|
||||||
it('should return anonymous === true if meant to be anonymous even if req.user is filled', function () {
|
|
||||||
// assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
|
||||||
});
|
|
||||||
it('should return anonymous === false a channel is provided', function () {
|
|
||||||
// assert.throws(publishHelpers.parsePublishApiRequestFiles.bind(this, filesNoProblems), Error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
Loading…
Reference in a new issue