Skip to content

Commit

Permalink
Update user update to check if there is a user
Browse files Browse the repository at this point in the history
  • Loading branch information
RobAndrewHurst committed Aug 27, 2024
1 parent ef72c1e commit 64763c0
Showing 1 changed file with 71 additions and 68 deletions.
139 changes: 71 additions & 68 deletions tests/mod/user/update.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,77 @@
* This function is used as an entry point for the changeEndTest
* @function updateTest
*/
export async function updateTest(mapview) {

await codi.describe('User: update', async () => {

/**
* ### update endpoint should be able to process a body
* The user update endpoint should be able to take a body as the request.
* @function it
*/
await codi.it('update endpoint should be able to process a body', async () => {

let params = {
url: '/test/api/user/update',
body: JSON.stringify(
{
email: '[email protected]',
admin: false,
approved: false,
verified: false
}
)
};

await mapp.utils.xhr(params);

params = {
url: '/test/api/user/update',
body: JSON.stringify(
{
email: '[email protected]',
admin: true,
approved: true,
verified: false
}
)
}

await mapp.utils.xhr(params);

const acl = await mapp.utils.xhr('/test/api/user/list');
const test_user = acl.filter(user => user.email === '[email protected]')[0];

await codi.assertEqual(test_user.email, '[email protected]', 'The users email address should be [email protected]')
await codi.assertFalse(test_user.verified, 'The user should be not verified')
await codi.assertTrue(test_user.admin, 'The user should an admin')
await codi.assertTrue(test_user.approved, 'The user should be approved')
export async function updateTest() {

if (mapp.user) {
await codi.describe('User: update', async () => {

console.log(mapp);
/**
* ### update endpoint should be able to process a body
* The user update endpoint should be able to take a body as the request.
* @function it
*/
await codi.it('update endpoint should be able to process a body', async () => {

let params = {
url: '/test/api/user/update',
body: JSON.stringify(
{
email: '[email protected]',
admin: false,
approved: false,
verified: false
}
)
};

await mapp.utils.xhr(params);

params = {
url: '/test/api/user/update',
body: JSON.stringify(
{
email: '[email protected]',
admin: true,
approved: true,
verified: false
}
)
}

await mapp.utils.xhr(params);

const acl = await mapp.utils.xhr('/test/api/user/list');
const test_user = acl.filter(user => user.email === '[email protected]')[0];

await codi.assertEqual(test_user.email, '[email protected]', 'The users email address should be [email protected]')
await codi.assertFalse(test_user.verified, 'The user should be not verified')
await codi.assertTrue(test_user.admin, 'The user should an admin')
await codi.assertTrue(test_user.approved, 'The user should be approved')

});

/**
### update endpoint should be able to be just params
* The user update endpoint should be able to take a body as the request.
* @function it
*/
await codi.it('update endpoint should be able to be just params', async () => {

const url = `/test/api/user/[email protected]&field=admin&value=false`
await mapp.utils.xhr(url);

const acl = await mapp.utils.xhr('/test/api/user/list');
const test_user = acl.filter(user => user.email === '[email protected]')[0];

await codi.assertEqual(test_user.email, '[email protected]', 'The users email address should be [email protected]')
await codi.assertFalse(test_user.verified, 'The user should be not verified')
await codi.assertFalse(test_user.admin, 'The user should an admin')
await codi.assertTrue(test_user.approved, 'The user should be approved')

});

});

/**
### update endpoint should be able to be just params
* The user update endpoint should be able to take a body as the request.
* @function it
*/
await codi.it('update endpoint should be able to be just params', async () => {

const url = `/test/api/user/[email protected]&field=admin&value=false`
await mapp.utils.xhr(url);

const acl = await mapp.utils.xhr('/test/api/user/list');
const test_user = acl.filter(user => user.email === '[email protected]')[0];

await codi.assertEqual(test_user.email, '[email protected]', 'The users email address should be [email protected]')
await codi.assertFalse(test_user.verified, 'The user should be not verified')
await codi.assertFalse(test_user.admin, 'The user should an admin')
await codi.assertTrue(test_user.approved, 'The user should be approved')

});

});
}
}

0 comments on commit 64763c0

Please sign in to comment.