Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BB-692: Add test for checkValidRevisionID #963

Merged
merged 5 commits into from Mar 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions test/src/server/routes/revision.js
@@ -0,0 +1,51 @@
/* eslint-disable sort-keys */
import {createEditor, truncateEntities} from '../../../test-helpers/create-entities';
import app from '../../../../src/server/app';
import chai from 'chai';
import chaiHttp from 'chai-http';
import orm from '../../../bookbrainz-data';
MonkeyDo marked this conversation as resolved.
Show resolved Hide resolved


chai.use(chaiHttp);
const {expect} = chai;
const {Revision} = orm;
const revisionAttribs = {
authorId: 1,
id: 1
};

describe('checkValidRevisionId', () => {
before(async () => {
await createEditor(1);
await new Revision(revisionAttribs).save(null, {method: 'insert'});
});
after(truncateEntities);

it('should not throw an error when revision id is valid and found', async () => {
const revisionId = 1;
const res = await chai.request(app).get(`/revision/${revisionId}`);
expect(res.ok).to.be.true;
expect(res).to.have.status(200);
});
it('should throw an error if requested id is invalid', async () => {
const revisionId = 'hello';
const res = await chai.request(app).get(`/revision/${revisionId}`);
expect(res.ok).to.be.false;
expect(res).to.have.status(400);
MonkeyDo marked this conversation as resolved.
Show resolved Hide resolved
expect(res.res.statusMessage).to.equal(`Invalid revision id: ${revisionId}`);
});
it('should throw an error when revision id is a decimal', async () => {
const revisionId = 1.367;
const res = await chai.request(app).get(`/revision/${revisionId}`);
expect(res.ok).to.be.false;
expect(res).to.have.status(400);
expect(res.res.statusMessage).to.equal(`Invalid revision id: ${revisionId}`);
});
it('should throw an error when revision id is unavailable', async () => {
const revisionId = 1367;
const res = await chai.request(app).get(`/revision/${revisionId}`);
expect(res.ok).to.be.false;
expect(res).to.have.status(404);
expect(res.res.statusMessage).to.equal(`Revision #${revisionId} not found`);
});
});