-
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(general): trimming values and tests
- Loading branch information
1 parent
f3e0f62
commit 8bf7a22
Showing
12 changed files
with
736 additions
and
16 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
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,109 @@ | ||
const { startServer, stopServer } = require('../../lib/server.js'); | ||
const { request } = require('../scripts/helpers'); | ||
const generator = require('../scripts/generator'); | ||
|
||
describe('My permissions body', () => { | ||
beforeAll(async () => { | ||
await startServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stopServer(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await generator.clearAll(); | ||
}); | ||
|
||
test('should list the global permission that is assigned to a circle user is member of', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const permission = await generator.createPermission({ scope: 'global', action: 'action', object: 'object' }); | ||
const circle = await generator.createCircle(); | ||
await generator.createCirclePermission(circle, permission); | ||
await generator.createCircleMembership(circle, user); | ||
|
||
const res = await request({ | ||
uri: '/my_permissions', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0].combined).toEqual('global:action:object'); | ||
}); | ||
|
||
test('should not list the local permissions that is assigned to a circle user is member of', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const permission = await generator.createPermission({ scope: 'local', action: 'action', object: 'object' }); | ||
const circle = await generator.createCircle(); | ||
await generator.createCirclePermission(circle, permission); | ||
await generator.createCircleMembership(circle, user); | ||
|
||
const res = await request({ | ||
uri: '/my_permissions', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body.data.length).toEqual(0); | ||
}); | ||
|
||
test('should list the global permission that is assigned to a circle user is indirectly a member of', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const permission = await generator.createPermission({ scope: 'global', action: 'action', object: 'object' }); | ||
const firstCircle = await generator.createCircle(); | ||
const secondCircle = await generator.createCircle({ parent_circle_id: firstCircle.id }); | ||
const thirdCircle = await generator.createCircle({ parent_circle_id: secondCircle.id }); | ||
|
||
await generator.createCirclePermission(firstCircle, permission); | ||
await generator.createCircleMembership(thirdCircle, user); | ||
|
||
const res = await request({ | ||
uri: '/my_permissions', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body.data.length).toEqual(1); | ||
expect(res.body.data[0].combined).toEqual('global:action:object'); | ||
}); | ||
|
||
test('should not list the global permission that is assigned to a circle user is not a member of', async () => { | ||
const user = await generator.createUser(); | ||
const token = await generator.createAccessToken({}, user); | ||
|
||
const permission = await generator.createPermission({ scope: 'global', action: 'action', object: 'object' }); | ||
const circle = await generator.createCircle(); | ||
await generator.createCirclePermission(circle, permission); | ||
|
||
const res = await request({ | ||
uri: '/my_permissions', | ||
method: 'GET', | ||
headers: { 'X-Auth-Token': token.value } | ||
}); | ||
|
||
expect(res.statusCode).toEqual(200); | ||
expect(res.body.success).toEqual(true); | ||
expect(res.body).not.toHaveProperty('errors'); | ||
expect(res.body).toHaveProperty('data'); | ||
expect(res.body.data.length).toEqual(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,72 @@ | ||
const { startServer, stopServer } = require('../../lib/server.js'); | ||
const generator = require('../scripts/generator'); | ||
const { Body } = require('../../models'); | ||
|
||
describe('Bodies testing', () => { | ||
beforeAll(async () => { | ||
await startServer(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await stopServer(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await generator.clearAll(); | ||
}); | ||
|
||
test('should fail with invalid email', async () => { | ||
try { | ||
await generator.createBody({ email: 'not-valid' }); | ||
expect(1).toEqual(0); | ||
} catch (err) { | ||
expect(err).toHaveProperty('errors'); | ||
expect(err.errors.length).toEqual(1); | ||
expect(err.errors[0].path).toEqual('email'); | ||
} | ||
}); | ||
|
||
test('should fail with null body_code', async () => { | ||
try { | ||
await generator.createBody({ code: null }); | ||
expect(1).toEqual(0); | ||
} catch (err) { | ||
expect(err).toHaveProperty('errors'); | ||
expect(err.errors.length).toEqual(1); | ||
expect(err.errors[0].path).toEqual('code'); | ||
} | ||
}); | ||
|
||
test('should fail with not set body_code', async () => { | ||
try { | ||
const body = generator.generateBody(); | ||
delete body.code; | ||
|
||
await Body.create(body); | ||
|
||
expect(1).toEqual(0); | ||
} catch (err) { | ||
expect(err).toHaveProperty('errors'); | ||
expect(err.errors.length).toEqual(1); | ||
expect(err.errors[0].path).toEqual('code'); | ||
} | ||
}); | ||
|
||
test('should work with email not set', async () => { | ||
const data = generator.generateBody({ email: null }); | ||
const body = await Body.create(data); | ||
|
||
expect(body.email).toEqual(null); | ||
}); | ||
|
||
test('should normalize fields', async () => { | ||
const data = generator.generateBody({ | ||
code: '\t\t\ttest\t\t\t', | ||
email: ' \t test@TeSt.Io\t \t', | ||
}); | ||
|
||
const body = await Body.create(data); | ||
expect(body.code).toEqual('TEST'); | ||
expect(body.email).toEqual('test@test.io'); | ||
}); | ||
}); |
Oops, something went wrong.