-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(members): add endpoints for searching and retrieving email (#249)
* feat(members): add endpoints for searching and retrieving email * chore(test): add tests * chore(email): reduce info returned * chore(test): uncomment test
- Loading branch information
Showing
4 changed files
with
427 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
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,142 @@ | ||
const { startServer, stopServer } = require('../../lib/server.js'); | ||
const { request } = require('../scripts/helpers'); | ||
const generator = require('../scripts/generator'); | ||
|
||
describe('Users list', () => { | ||
beforeAll(async () => { | ||
await startServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stopServer(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await generator.clearAll(); | ||
}); | ||
|
||
test('should fail if no permission', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const res = await request({ | ||
uri: '/members_email', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(403); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should succeed when everything is okay', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'mail', object: 'member' }); | ||
|
||
const res = await request({ | ||
uri: '/members_email', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0].id).toEqual(user.id); | ||
}); | ||
|
||
test('should find one by id', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'mail', object: 'member' }); | ||
|
||
const res = await request({ | ||
uri: '/members_email?query=' + user.id, | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0].id).toEqual(user.id); | ||
}); | ||
|
||
test('should find multiple by id array', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const secondUser = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'mail', object: 'member' }); | ||
|
||
const res = await request({ | ||
uri: '/members_email?query=' + user.id + ',' + secondUser.id, | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(2); | ||
expect([user.id, secondUser.id]).toContainEqual(res.body.data[0].id); | ||
expect([user.id, secondUser.id]).toContainEqual(res.body.data[1].id); | ||
}); | ||
|
||
test('should fail when query is not a string of ids seperated by commas', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'mail', object: 'member' }); | ||
|
||
const res = await request({ | ||
uri: '/members_email?query=a,b', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(400); | ||
expect(res.body.success).toEqual(false); | ||
expect(res.body).toHaveProperty('message'); | ||
expect(res.body).not.toHaveProperty('data'); | ||
}); | ||
|
||
test('should only return id and notification email', async () => { | ||
const user = await generator.createUser({ superadmin: true }); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
await generator.createPermission({ scope: 'global', action: 'mail', object: 'member' }); | ||
|
||
const res = await request({ | ||
uri: '/members_email', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
const expectedOutput = { | ||
id: user.id, | ||
notification_email: user.notification_email | ||
}; | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
|
||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0]).toEqual(expectedOutput); | ||
}); | ||
}); |
Oops, something went wrong.