Skip to content

Commit

Permalink
Merge 70b48d6 into f78561c
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyDo committed Apr 7, 2020
2 parents f78561c + 70b48d6 commit f3c40f0
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 43 deletions.
4 changes: 3 additions & 1 deletion src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ function cleanupFunction() {
/* eslint-enable no-console */

// Run cleanup function
appCleanup(cleanupFunction);
if (process.env.NODE_ENV !== 'test') {
appCleanup(cleanupFunction);
}

export default server;
5 changes: 4 additions & 1 deletion src/server/helpers/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export function makeEntityLoader(modelName, additionalRels, errMessage) {

return async (req, res, next, bbid) => {
const {orm} = req.app.locals;
if (commonUtils.isValidBBID(bbid)) {
if (req.path === '/create') {
return next('route');
}
else if (commonUtils.isValidBBID(bbid)) {
try {
const entity = await orm.func.entity.getEntity(orm, modelName, bbid, relations);
if (!entity.dataId) {
Expand Down
47 changes: 47 additions & 0 deletions test/src/server/routes/entity/author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {createAuthor, getRandomUUID, truncateEntities} from '../../../../test-helpers/create-entities';

import app from '../../../../../src/server/app';
import chai from 'chai';
import chaiHttp from 'chai-http';


chai.use(chaiHttp);
const {expect} = chai;

describe('Author routes', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';

before(async () => {
await createAuthor(aBBID);
});
after(truncateEntities);

it('should throw an error if requested BBID is invalid', (done) => {
chai.request(app)
.get(`/author/${inValidBBID}`)
.end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(400);
done();
});
});
it('should not throw an error if creating new author', async () => {
const res = await chai.request(app)
.get('/author/create');
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error if requested author BBID exists', async () => {
const res = await chai.request(app)
.get(`/author/${aBBID}`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error trying to edit an existing author', async () => {
const res = await chai.request(app)
.get(`/author/${aBBID}/edit`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
});
47 changes: 47 additions & 0 deletions test/src/server/routes/entity/edition-group.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {createEditionGroup, getRandomUUID, truncateEntities} from '../../../../test-helpers/create-entities';

import app from '../../../../../src/server/app';
import chai from 'chai';
import chaiHttp from 'chai-http';


chai.use(chaiHttp);
const {expect} = chai;

describe('Edition Group routes', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';

before(async () => {
await createEditionGroup(aBBID);
});
after(truncateEntities);

it('should throw an error if requested BBID is invalid', (done) => {
chai.request(app)
.get(`/edition-group/${inValidBBID}`)
.end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(400);
done();
});
});
it('should not throw an error if creating new edition-group', async () => {
const res = await chai.request(app)
.get('/edition-group/create');
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error if requested edition group BBID exists', async () => {
const res = await chai.request(app)
.get(`/edition-group/${aBBID}`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error trying to edit an existing edition group', async () => {
const res = await chai.request(app)
.get(`/edition-group/${aBBID}/edit`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
});
47 changes: 47 additions & 0 deletions test/src/server/routes/entity/edition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {createEdition, getRandomUUID, truncateEntities} from '../../../../test-helpers/create-entities';

import app from '../../../../../src/server/app';
import chai from 'chai';
import chaiHttp from 'chai-http';


chai.use(chaiHttp);
const {expect} = chai;

describe('Edition routes', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';

before(async () => {
await createEdition(aBBID);
});
after(truncateEntities);

it('should throw an error if requested BBID is invalid', (done) => {
chai.request(app)
.get(`/edition/${inValidBBID}`)
.end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(400);
done();
});
});
it('should not throw an error if creating new edition', async () => {
const res = await chai.request(app)
.get('/edition/create');
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error if requested edition BBID exists', async () => {
const res = await chai.request(app)
.get(`/edition/${aBBID}`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error trying to edit an existing edition', async () => {
const res = await chai.request(app)
.get(`/edition/${aBBID}/edit`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
});
47 changes: 47 additions & 0 deletions test/src/server/routes/entity/publisher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {createPublisher, getRandomUUID, truncateEntities} from '../../../../test-helpers/create-entities';

import app from '../../../../../src/server/app';
import chai from 'chai';
import chaiHttp from 'chai-http';


chai.use(chaiHttp);
const {expect} = chai;

describe('Publisher routes', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';

before(async () => {
await createPublisher(aBBID);
});
after(truncateEntities);

it('should throw an error if requested BBID is invalid', (done) => {
chai.request(app)
.get(`/publisher/${inValidBBID}`)
.end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(400);
done();
});
});
it('should not throw an error if creating new publisher', async () => {
const res = await chai.request(app)
.get('/publisher/create');
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error if requested publisher BBID exists', async () => {
const res = await chai.request(app)
.get(`/publisher/${aBBID}`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error trying to edit an existing publisher', async () => {
const res = await chai.request(app)
.get(`/publisher/${aBBID}/edit`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
});
47 changes: 47 additions & 0 deletions test/src/server/routes/entity/work.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {createWork, getRandomUUID, truncateEntities} from '../../../../test-helpers/create-entities';

import app from '../../../../../src/server/app';
import chai from 'chai';
import chaiHttp from 'chai-http';


chai.use(chaiHttp);
const {expect} = chai;

describe('Work routes', () => {
const aBBID = getRandomUUID();
const inValidBBID = 'have-you-seen-the-fnords';

before(async () => {
await createWork(aBBID);
});
after(truncateEntities);

it('should throw an error if requested BBID is invalid', (done) => {
chai.request(app)
.get(`/work/${inValidBBID}`)
.end((err, res) => {
expect(err).to.be.null;
expect(res).to.have.status(400);
done();
});
});
it('should not throw an error if creating new work', async () => {
const res = await chai.request(app)
.get('/work/create');
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error if requested work BBID exists', async () => {
const res = await chai.request(app)
.get(`/work/${aBBID}`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should not throw an error trying to edit an existing work', async () => {
const res = await chai.request(app)
.get(`/work/${aBBID}/edit`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
});

0 comments on commit f3c40f0

Please sign in to comment.