Skip to content

Commit

Permalink
test(backend): add test cases for resolving a known DOI
Browse files Browse the repository at this point in the history
This change adds test cases for resolving a preprint with a DOI that is already known, including a failing case where the DOI used is in a different case (as it should be case insensitive).

Refs #388, #430
  • Loading branch information
thewilkybarkid committed Dec 14, 2021
1 parent 1b545a5 commit 835c740
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
26 changes: 25 additions & 1 deletion test/backend/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import faker from 'faker';
import { StatusCodes } from 'http-status-codes';
import nock from 'nock';
import request from 'supertest';
import { createServer } from '../setup';
import { createPreprint, createServer } from '../setup';
import { fakeDoi, isoDateTime, uuid } from '../utils';

describe('resolve', () => {
Expand Down Expand Up @@ -46,4 +46,28 @@ describe('resolve', () => {
uuid: expect.stringMatching(uuid),
});
});

it('returns already-known preprints', async () => {
const preprint = await createPreprint({ handle: 'doi:10.5555/abcdef' });

const response = await request(await createServer())
.get('/api/v2/resolve')
.query({ identifier: '10.5555/abcdef' });

expect(response.status).toBe(StatusCodes.OK);
expect(response.type).toBe('application/json');
expect(response.body).toMatchObject({ uuid: preprint.uuid });
});

it.skip('treats DOIs as case insensitive', async () => {
const preprint = await createPreprint({ handle: 'doi:10.5555/abcdef' });

const response = await request(await createServer())
.get('/api/v2/resolve')
.query({ identifier: '10.5555/AbCdEf' });

expect(response.status).toBe(StatusCodes.OK);
expect(response.type).toBe('application/json');
expect(response.body).toMatchObject({ uuid: preprint.uuid });
});
});
7 changes: 5 additions & 2 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MikroORM } from '@mikro-orm/core';
import { EntityData, MikroORM } from '@mikro-orm/core';
import { PostgreSqlDriver } from '@mikro-orm/postgresql';
import faker from 'faker';
import { RequestListener } from 'http';
Expand Down Expand Up @@ -43,12 +43,15 @@ global.afterAll(async () => {
await orm.close(true);
});

export async function createPreprint(): Promise<Preprint> {
export async function createPreprint(
data?: EntityData<Preprint>,
): Promise<Preprint> {
const preprints = preprintModelWrapper(orm);

const preprint = preprints.create({
handle: `doi:${fakeDoi()}`,
title: faker.lorem.sentence(),
...data,
});

await preprints.persistAndFlush(preprint);
Expand Down

0 comments on commit 835c740

Please sign in to comment.