Skip to content

Commit

Permalink
test(api): Fix author creation helper
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkeyDo committed Jun 19, 2020
1 parent e791a62 commit 6f90f7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
11 changes: 6 additions & 5 deletions test/src/api/routes/test-author.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ describe('Browse Author', () => {
const authorBBID = getRandomUUID();
const authorAttribs = {
bbid: authorBBID,
typeId
// Make type id alternate between "person" (1) and "group" (2)
typeId: (typeId % 2) + 1
};
await createAuthor(authorBBID, authorAttribs);
authorBBIDs.push(authorBBID);
Expand Down Expand Up @@ -245,10 +246,10 @@ describe('Browse Author', () => {
});

it('should return list of authors associated with the work (with Type filter)', async () => {
const res = await chai.request(app).get(`/author?work=${work.get('bbid')}&type=Author+Type+1`);
const res = await chai.request(app).get(`/author?work=${work.get('bbid')}&type=Person`);
await browseAuthorBasicTests(res);
expect(res.body.authors.length).to.equal(1);
expect(_.toLower(res.body.authors[0].entity.authorType)).to.equal('author type 1');
expect(res.body.authors[0].entity.authorType).to.equal('Person');
});

it('should return 0 authors (with Incorrect Type filter)', async () => {
Expand All @@ -258,10 +259,10 @@ describe('Browse Author', () => {
});

it('should allow params to be case insensitive', async () => {
const res = await chai.request(app).get(`/aUThor?wOrk=${work.get('bbid')}&tYPe=AuTHor+TyPe+1`);
const res = await chai.request(app).get(`/aUThor?wOrk=${work.get('bbid')}&tYPe=pERsOn`);
await browseAuthorBasicTests(res);
expect(res.body.authors.length).to.equal(1);
expect(_.toLower(res.body.authors[0].entity.authorType)).to.equal('author type 1');
expect(res.body.authors[0].entity.authorType).to.equal('Person');
});

it('should NOT throw an error if there is no related entity', async () => {
Expand Down
9 changes: 3 additions & 6 deletions test/test-helpers/create-entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ const entityAttribs = {
relationshipSetId: 1,
revisionId: 1
};
const authorTypeAttribs = {
id: random.number()
};

export function createEditor(editorId) {
return orm.bookshelf.knex.transaction(async (transacting) => {
Expand Down Expand Up @@ -332,21 +329,21 @@ export async function createAuthor(optionalBBID, optionalAuthorAttribs = {}) {
endYear: 2012,
ended: true,
genderId: editorAttribs.genderId,
typeId: authorTypeAttribs.id,
typeId: 1,
...optionalAuthorAttribs
};
await new Area({gid: uuidv4(), id: areaId, name: 'Rlyeh'})
.save(null, {method: 'insert'});
// Front-end requires 'Person' and 'Group' types
try {
await new AuthorType({id: authorTypeAttribs.id, label: 'Person'})
await new AuthorType({id: 1, label: 'Person'})
.save(null, {method: 'insert'});
}
catch (error) {
// Type already exists
}
try {
await new AuthorType({id: random.number(), label: 'Group'})
await new AuthorType({id: 2, label: 'Group'})
.save(null, {method: 'insert'});
}
catch (error) {
Expand Down

0 comments on commit 6f90f7a

Please sign in to comment.