Skip to content

Commit

Permalink
feat: validate admin list updates in admins.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshthite committed Jan 12, 2024
1 parent 16de91f commit d8119ec
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/server/api/admins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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')
Expand All @@ -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 => {
Expand Down

0 comments on commit d8119ec

Please sign in to comment.