-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): add cases for submitting rapid reviews through the…
… API Adds test cases for submitting rapid reviews as an authenticated API user and an anonymous user. Only one of the cases fails, as it's possible to submit more than once. Refs #388, #408
- Loading branch information
1 parent
749687c
commit 93b75c8
Showing
7 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { expect, test } from './test'; | ||
import { jsonBody } from './utils'; | ||
|
||
test.asAnAuthenticatedAPIUser( | ||
'can submit a rapid review', | ||
async ({ apiFetch, preprint }) => { | ||
const response = await apiFetch(`/api/v2/rapid-reviews`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
preprint: preprint.uuid, | ||
ynNovel: 'N/A', | ||
ynFuture: 'N/A', | ||
ynReproducibility: 'N/A', | ||
ynMethods: 'N/A', | ||
ynCoherent: 'N/A', | ||
ynLimitations: 'N/A', | ||
ynEthics: 'N/A', | ||
ynNewData: 'N/A', | ||
ynAvailableData: 'N/A', | ||
ynAvailableCode: 'N/A', | ||
ynRecommend: 'N/A', | ||
ynPeerReview: 'N/A', | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
expect(response.status).toBe(201); | ||
expect(await jsonBody(response)).toMatchSnapshot('success.json'); | ||
}, | ||
); | ||
|
||
test.asAnAnonymousAPIUser( | ||
'not allowed to submit a rapid review', | ||
async ({ fetch, preprint }) => { | ||
const response = await fetch(`/api/v2/rapid-reviews`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
preprint: preprint.uuid, | ||
ynNovel: 'N/A', | ||
ynFuture: 'N/A', | ||
ynReproducibility: 'N/A', | ||
ynMethods: 'N/A', | ||
ynCoherent: 'N/A', | ||
ynLimitations: 'N/A', | ||
ynEthics: 'N/A', | ||
ynNewData: 'N/A', | ||
ynAvailableData: 'N/A', | ||
ynAvailableCode: 'N/A', | ||
ynRecommend: 'N/A', | ||
ynPeerReview: 'N/A', | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
expect(response.status).toBe(403); | ||
expect(await jsonBody(response)).toMatchSnapshot('no-api-key.json'); | ||
}, | ||
); | ||
|
||
test.asAnAuthenticatedAPIUser( | ||
'not allowed to submit multiple rapid reviews', | ||
async ({ apiFetch, preprint, rapidReview }, { fixme }) => { | ||
const response = await apiFetch(`/api/v2/rapid-reviews`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
preprint: preprint.uuid, | ||
ynNovel: 'N/A', | ||
ynFuture: 'N/A', | ||
ynReproducibility: 'N/A', | ||
ynMethods: 'N/A', | ||
ynCoherent: 'N/A', | ||
ynLimitations: 'N/A', | ||
ynEthics: 'N/A', | ||
ynNewData: 'N/A', | ||
ynAvailableData: 'N/A', | ||
ynAvailableCode: 'N/A', | ||
ynRecommend: 'N/A', | ||
ynPeerReview: 'N/A', | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
fixme(true, 'A successful response is returned'); | ||
|
||
expect(response.status).toBe(403); | ||
expect(await jsonBody(response)).toMatchSnapshot('duplicate.json'); | ||
}, | ||
); |
3 changes: 3 additions & 0 deletions
3
integration/src/api/submitting-a-rapid-review.spec.ts-snapshots/no-api-key-API-linux.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"message": "Access Denied - You don't have permission to: access private pages" | ||
} |
27 changes: 27 additions & 0 deletions
27
integration/src/api/submitting-a-rapid-review.spec.ts-snapshots/success-API-linux.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"status": 201, | ||
"message": "created", | ||
"data": [ | ||
{ | ||
"uuid": "...", | ||
"createdAt": "...", | ||
"updatedAt": "...", | ||
"isPublished": false, | ||
"isFlagged": false, | ||
"ynNovel": "N/A", | ||
"ynFuture": "N/A", | ||
"ynReproducibility": "N/A", | ||
"ynMethods": "N/A", | ||
"ynCoherent": "N/A", | ||
"ynLimitations": "N/A", | ||
"ynEthics": "N/A", | ||
"ynNewData": "N/A", | ||
"ynRecommend": "N/A", | ||
"ynPeerReview": "N/A", | ||
"ynAvailableCode": "N/A", | ||
"ynAvailableData": "N/A", | ||
"author": 0, | ||
"preprint": 0 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { test as baseTest } from '@playwright/test'; | ||
import { | ||
dataFixtures, | ||
fakerFixtures, | ||
httpFixtures, | ||
userDataFixtures, | ||
userFixtures, | ||
} from '../fixtures'; | ||
|
||
const dataTest = baseTest | ||
.extend(fakerFixtures) | ||
.extend(httpFixtures) | ||
.extend(dataFixtures); | ||
|
||
const asAnAnonymousAPIUser = dataTest; | ||
|
||
const asAnAuthenticatedAPIUser = dataTest | ||
.extend(userFixtures) | ||
.extend(userDataFixtures) | ||
.extend({ | ||
storageState: async ({}, use) => { | ||
await use('state/logged-in-user.json'); | ||
}, | ||
}); | ||
|
||
export const test = { | ||
asAnAnonymousAPIUser, | ||
asAnAuthenticatedAPIUser, | ||
}; | ||
|
||
export { expect } from '@playwright/test'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Body } from 'node-fetch'; | ||
|
||
export async function jsonBody<T extends Body>(message: T): Promise<Buffer> { | ||
return Buffer.from( | ||
JSON.stringify(await message.json(), jsonReplacer, 2) + '\n', | ||
); | ||
} | ||
|
||
function jsonReplacer(key: string, value: unknown) { | ||
if (['author', 'createdAt', 'preprint', 'updatedAt', 'uuid'].includes(key)) { | ||
switch (typeof value) { | ||
case 'number': | ||
return 0; | ||
default: | ||
return '...'; | ||
} | ||
} | ||
|
||
return value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters