Skip to content
Permalink
3749913d51
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
81 lines (68 sloc) 2.04 KB
'use strict'
const Accounts = require('../modules/user.js')
describe('register()', () => {
test('register a valid account', async done => {
expect.assertions(1)
try {
const account = await new Accounts()
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', async done => {
expect.assertions(1)
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()
})
})