Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
117 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,81 @@ | ||
|
||
'use strict' | ||
|
||
const Accounts = require('../modules/accounts.js') | ||
const Accounts = require('../modules/user.js') | ||
|
||
describe('register()', () => { | ||
|
||
test('register a valid account', async done => { | ||
expect.assertions(1) | ||
try { | ||
const account = await new Accounts() | ||
// test goes here | ||
const register = await account.register('doej', 'password') | ||
expect(register).toBe(true) | ||
} catch(err) { | ||
done.fail(err) | ||
} finally { | ||
done() | ||
} | ||
}) | ||
|
||
test('register a duplicate username', async done => { | ||
expect.assertions(1) | ||
const account = await new Accounts() | ||
await account.register('doej', 'password') | ||
await expect( account.register('doej', 'password') ) | ||
.rejects.toEqual( Error('username "doej" already in use') ) | ||
done() | ||
}) | ||
|
||
test('error if blank username', async done => { | ||
expect.assertions(1) | ||
const account = await new Accounts() | ||
await expect( account.register('', 'password') ) | ||
.rejects.toEqual( Error('missing username') ) | ||
done() | ||
}) | ||
|
||
test('error if blank password', async done => { | ||
expect.assertions(1) | ||
const account = await new Accounts() | ||
await expect( account.register('doej', '') ) | ||
.rejects.toEqual( Error('missing password') ) | ||
done() | ||
}) | ||
|
||
}) | ||
|
||
describe('uploadPicture()', () => { | ||
// this would have to be done by mocking the file system | ||
// perhaps using mock-fs? | ||
}) | ||
|
||
describe('login()', () => { | ||
test('log in with valid credentials', done => { | ||
test('log in with valid credentials', async done => { | ||
expect.assertions(1) | ||
try { | ||
const account = await new Accounts() | ||
// test goes here | ||
} catch(err) { | ||
done.fail(err) | ||
} finally { | ||
done() | ||
} | ||
const account = await new Accounts() | ||
await account.register('doej', 'password') | ||
const valid = await account.login('doej', 'password') | ||
expect(valid).toBe(true) | ||
done() | ||
}) | ||
|
||
test('invalid username', async done => { | ||
expect.assertions(1) | ||
const account = await new Accounts() | ||
await account.register('doej', 'password') | ||
await expect( account.login('roej', 'password') ) | ||
.rejects.toEqual( Error('username "roej" not found') ) | ||
done() | ||
}) | ||
|
||
test('invalid password', async done => { | ||
expect.assertions(1) | ||
const account = await new Accounts() | ||
await account.register('doej', 'password') | ||
await expect( account.login('doej', 'bad') ) | ||
.rejects.toEqual( Error('invalid password for account "doej"') ) | ||
done() | ||
}) | ||
|
||
}) |