Skip to content

Commit

Permalink
test(integration): add case for viewing a request by an author
Browse files Browse the repository at this point in the history
Refs #388, #425
  • Loading branch information
thewilkybarkid committed Nov 12, 2021
1 parent 99280e1 commit 89646b7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
31 changes: 31 additions & 0 deletions integration/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const rapidReviewSchema = z.object({

const requestSchema = z.object({
uuid: z.string(),
isPreprintAuthor: z.boolean(),
})

const templateSchema = z.object({
Expand Down Expand Up @@ -140,6 +141,36 @@ export async function ensureRequest(
.then(response => response.data);
}

export async function ensureRequestByAuthor(
fetch: Fetch,
preprint: string,
): Promise<Request> {
const request = await fetch(`/api/v2/preprints/${preprint}/requests`, {
headers: adminHeaders,
})
.then(response => response.json())
.then(dataSchema(z.array(requestSchema)).parse)
.then(response => response.data)
.then(requests => requests.find(request => request.isPreprintAuthor));

if (request) {
return request;
}

return await fetch(`/api/v2/preprints/${preprint}/requests?isAuthor=true`, {
method: 'POST',
body: JSON.stringify({ preprint }),
headers: {
'Content-Type': 'application/json',
...adminHeaders,
},
})
.then(ensureSuccess)
.then(response => response.json())
.then(dataSchema(requestSchema).parse)
.then(response => response.data);
}

export async function ensureFullReview(
fetch: Fetch,
preprint: string,
Expand Down
13 changes: 13 additions & 0 deletions integration/src/browser/author-requested-a-review.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, test } from './test';
import { screenshot } from './utils';

test.asALoggedInUser('see an author-requested review', async ({ page, preprint, requestByAuthor }) => {
await page.goto(`preprints/${preprint.uuid}`);

await page.click(':text("Add Request")');

const paper = page.locator('.MuiDrawer-paper');

await expect(paper.locator('.MuiAvatarGroup-avatar')).toContainText('Author');
expect(await screenshot(paper)).toMatchSnapshot('with-author-request.png');
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions integration/src/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import {
ensureCommunity,
ensureFullReview,
ensurePreprint,
ensureRequestByAuthor,
ensureTemplate,
findUser,
FullReview,
Preprint,
RapidReview,
Request,
Template,
User,
} from './api';
Expand All @@ -41,6 +43,7 @@ type DataFixtures = {
community: Community;
fullReview: FullReview;
preprint: Preprint;
requestByAuthor: Request;
template: Template;
};

Expand Down Expand Up @@ -115,6 +118,11 @@ export const dataFixtures: Fixtures<

await use(preprint);
},
requestByAuthor: async ({ fetch, preprint }, use) => {
const requestByAuthor = await ensureRequestByAuthor(fetch, preprint.uuid);

await use(requestByAuthor);
},
template: async ({ community, faker, fetch }, use) => {
const template = await ensureTemplate(fetch, community.uuid, {
title: faker.lorem.words(),
Expand Down

0 comments on commit 89646b7

Please sign in to comment.