-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validate admin list updates in admins.test.ts
- Loading branch information
1 parent
16de91f
commit d8119ec
Showing
1 changed file
with
26 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,16 +46,22 @@ test.serial('GET /admins - not allowed', async t => { | |
test.serial('POST /admins - add admins', async t => { | ||
t.context.hasAdminPermissionForRequestStub.resolves(true) | ||
|
||
const response = await t.context.server.inject({ | ||
// Add a new admin | ||
await t.context.server.inject({ | ||
method: 'POST', | ||
url: '/v1/admins', | ||
payload: '[email protected]', | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
headers: { 'Content-Type': 'text/plain' } | ||
}) | ||
|
||
t.is(response.statusCode, 200, 'returns a status code of 200') | ||
// Fetch the list of admins to verify the addition | ||
const response = await t.context.server.inject({ | ||
method: 'GET', | ||
url: '/v1/admins' | ||
}) | ||
|
||
t.is(response.statusCode, 200, 'returns a status code of 200 after adding admin') | ||
t.deepEqual(response.body.split('\n'), ['[email protected]'], 'Admin list should contain only the new admin') | ||
}) | ||
|
||
test.serial('POST /admins - not allowed', async t => { | ||
|
@@ -65,9 +71,7 @@ test.serial('POST /admins - not allowed', async t => { | |
method: 'POST', | ||
url: '/v1/admins', | ||
payload: '[email protected]', | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
headers: { 'Content-Type': 'text/plain' } | ||
}) | ||
|
||
t.is(response.statusCode, 403, 'returns a status code of 403') | ||
|
@@ -76,16 +80,25 @@ test.serial('POST /admins - not allowed', async t => { | |
test.serial('DELETE /admins - remove admins', async t => { | ||
t.context.hasAdminPermissionForRequestStub.resolves(true) | ||
|
||
const response = await t.context.server.inject({ | ||
// Remove an admin | ||
await t.context.server.inject({ | ||
method: 'DELETE', | ||
url: '/v1/admins', | ||
payload: '[email protected]', | ||
headers: { | ||
'Content-Type': 'text/plain' | ||
} | ||
headers: { 'Content-Type': 'text/plain' } | ||
}) | ||
|
||
t.is(response.statusCode, 200, 'returns a status code of 200') | ||
// Fetch the list of admins to verify the removal | ||
const response = await t.context.server.inject({ | ||
method: 'GET', | ||
url: '/v1/admins' | ||
}) | ||
|
||
t.is(response.statusCode, 200, 'returns a status code of 200 after removing admin') | ||
|
||
// Filter out empty strings from the response body | ||
const adminList = response.body.split('\n').filter(admin => admin.trim() !== '') | ||
t.deepEqual(adminList, [], 'Admin list should be empty after removal') | ||
}) | ||
|
||
test.serial('DELETE /admins - not allowed', async t => { | ||
|