-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from jhotmann/card-support
Update device config links on password change
- Loading branch information
Showing
6 changed files
with
155 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); | ||
const { User } = require('../models/User'); | ||
const { Group } = require('../models/Group'); | ||
|
||
// Create agents to save cookies | ||
const jesterAgent = request.agent(app); | ||
const friendAgent = request.agent(app); | ||
|
||
let jester; | ||
let friend; | ||
let group; | ||
|
||
beforeAll(async () => { | ||
// Create test users | ||
jester = await User.create('jester-group', 'jester'); | ||
friend = await User.create('jester-friend', 'jester'); | ||
|
||
// Login | ||
await jesterAgent.post('/login') | ||
.type('form') | ||
.send({ username: 'jester-group' }) | ||
.send({ password: 'jester' }); | ||
|
||
await friendAgent.post('/login') | ||
.type('form') | ||
.send({ username: 'jester-friend' }) | ||
.send({ password: 'jester' }); | ||
}); | ||
|
||
afterAll(async () => { | ||
// Delete all test groups | ||
await Group.remove({ adminId: jester._id }, { multi: true }); | ||
|
||
// Delete test users | ||
if (jester) await jester.remove(); | ||
if (friend) await friend.remove(); | ||
}); | ||
|
||
describe('Create a group', () => { | ||
test('A user can create a group that they administer', async () => { | ||
const response = await jesterAgent.post('/group/create') | ||
.type('form') | ||
.send({ groupName: 'Court Jesters' }); | ||
expect(response.text).toBe('Add Successful'); | ||
group = await Group.findOne({ name: 'Court Jesters', adminId: jester._id }); | ||
expect(group).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('Invite to group', () => { | ||
test('A user can inite user to their groups', async () => { | ||
const response = await jesterAgent.post(`/group/${group._id}/invite`) | ||
.type('form') | ||
.send({ members: friend._id }); | ||
expect(response.text).toBe('Done'); | ||
group = await Group.findOne({ name: 'Court Jesters', adminId: jester._id }); | ||
expect(group.members.length).toBe(2); | ||
}); | ||
}); |
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,30 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); | ||
const { User } = require('../models/User'); | ||
|
||
let jester; | ||
const jesterAgent = request.agent(app); | ||
|
||
beforeAll(async () => { | ||
jester = await User.create('jester-logout', 'jester'); | ||
await jesterAgent.post('/login') | ||
.type('form') | ||
.send({ username: 'jester-logout' }) | ||
.send({ password: 'jester' }); | ||
}); | ||
|
||
afterAll(async () => { | ||
if (jester) await jester.remove(); | ||
}); | ||
|
||
describe('Logout', () => { | ||
test('The user should be redirected to the home page', async () => { | ||
const response = await jesterAgent.get('/logout'); | ||
expect(response.statusCode).toBe(302); | ||
}); | ||
|
||
test('The logged out user should be redirected from the user page', async () => { | ||
const response = await jesterAgent.get('/user'); | ||
expect(response.statusCode).toBe(302); | ||
}); | ||
}); |
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,56 @@ | ||
const request = require('supertest'); | ||
const app = require('../app'); | ||
const { User } = require('../models/User'); | ||
const { Registration } = require('../models/Registration'); | ||
|
||
const registrations = []; | ||
|
||
beforeAll(async () => { | ||
// Create registration entries | ||
registrations.push(await Registration.create()); | ||
registrations.push(await Registration.create()); | ||
}); | ||
|
||
afterAll(async () => { | ||
// Delete registration entries | ||
await Registration.remove({ guid: { $in: registrations } }, { multi: true }); | ||
|
||
// Delete new users | ||
await User.remove({ username: 'jester-register' }); | ||
}); | ||
|
||
describe('Get /register page', () => { | ||
test('With valid id', async () => { | ||
const response = await request(app).get(`/register/${registrations[0]}`); | ||
expect(response.statusCode).toBe(200); | ||
expect(response.text).toMatch('Pinpoint Registration'); | ||
}); | ||
|
||
|
||
test('With invalid id', async () => { | ||
const response = await request(app).get('/register/abc123'); | ||
expect(response.text).toBe('Registration Used, please request a new link.'); | ||
}); | ||
}); | ||
|
||
describe('Use registration code', () => { | ||
test('With valid id', async () => { | ||
const response = await request(app).post(`/register/${registrations[0]}`) | ||
.type('form') | ||
.send({ username: 'jester-register' }) | ||
.send({ password: 'jester' }); | ||
expect(response.statusCode).toBe(200); | ||
expect(response.text).toBe('Register Successful'); | ||
expect((await User.find({ username: 'jester-register' })).length).toBe(1); | ||
}); | ||
|
||
|
||
test('With invalid id', async () => { | ||
const response = await request(app).post(`/register/abc123`) | ||
.type('form') | ||
.send({ username: 'jester-register2' }) | ||
.send({ password: 'jester' }); | ||
expect(response.statusCode).toBe(200); | ||
expect(response.text).toBe('Registration Used, please request a new link.'); | ||
}); | ||
}); |
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