More api/auth tests

This commit is contained in:
Jori Lallo
2016-09-11 23:14:43 -07:00
parent 969243c3e4
commit ef91cc17d5
4 changed files with 65 additions and 63 deletions

View File

@ -1,3 +1,42 @@
exports[`#auth.login should login with email 1`] = `
Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
}
`;
exports[`#auth.login should login with username 1`] = `
Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
}
`;
exports[`#auth.login should require either username or email 1`] = `
Object {
"error": "username or email is required",
"ok": false
}
`;
exports[`#auth.login should require password 1`] = `
Object {
"error": "password is required",
"ok": false
}
`;
exports[`#auth.login should validate password 1`] = `
Object {
"error": "Invalid password",
"ok": false
}
`;
exports[`#auth.signup should require params 1`] = ` exports[`#auth.signup should require params 1`] = `
Object { Object {
"error": "name is required", "error": "name is required",
@ -25,42 +64,3 @@ Object {
"ok": false "ok": false
} }
`; `;
exports[`#login should login with email 1`] = `
Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
}
`;
exports[`#login should login with username 1`] = `
Object {
"avatarUrl": "http://example.com/avatar.png",
"id": "86fde1d4-0050-428f-9f0b-0bf77f8bdf61",
"name": "User 1",
"username": "user1"
}
`;
exports[`#login should require either username or email 1`] = `
Object {
"error": "username or email is required",
"ok": false
}
`;
exports[`#login should require password 1`] = `
Object {
"error": "password is required",
"ok": false
}
`;
exports[`#login should validate password 1`] = `
Object {
"error": "Invalid password",
"ok": false
}
`;

View File

@ -1,11 +1,11 @@
exports[`test should require authentication 1`] = ` exports[`#user.info should require authentication 1`] = `
Object { Object {
"error": "Authentication required", "error": "Authentication required",
"ok": false "ok": false
} }
`; `;
exports[`test should return known user 1`] = ` exports[`#user.info should return known user 1`] = `
Object { Object {
"data": Object { "data": Object {
"avatarUrl": "http://example.com/avatar.png", "avatarUrl": "http://example.com/avatar.png",

View File

@ -86,7 +86,7 @@ describe('#auth.signup', async () => {
}); });
}); });
describe('#login', () => { describe('#auth.login', () => {
test('should login with email', async () => { test('should login with email', async () => {
await seed(); await seed();
const res = await server.post('/api/auth.login', { const res = await server.post('/api/auth.login', {

View File

@ -11,7 +11,8 @@ beforeEach(flushdb);
afterAll(() => server.close()); afterAll(() => server.close());
afterAll(() => sequelize.close()); afterAll(() => sequelize.close());
it('should return known user', async () => { describe('#user.info', async () => {
it('should return known user', async () => {
await seed(); await seed();
const user = await User.findOne({ const user = await User.findOne({
where: { where: {
@ -26,13 +27,14 @@ it('should return known user', async () => {
expect(res.status).toEqual(200); expect(res.status).toEqual(200);
expect(body).toMatchSnapshot(); expect(body).toMatchSnapshot();
}); });
it('should require authentication', async () => { it('should require authentication', async () => {
await seed(); await seed();
const res = await server.post('/api/user.info'); const res = await server.post('/api/user.info');
const body = await res.json(); const body = await res.json();
expect(res.status).toEqual(401); expect(res.status).toEqual(401);
expect(body).toMatchSnapshot(); expect(body).toMatchSnapshot();
});
}); });