Skip to content
Permalink
6c9d819d88
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
97 lines (82 sloc) 2.62 KB
'use strict'
const Accounts = require('../modules/user.js')
describe('register()', () => {
test('register a valid account', async done => {
expect.assertions(1)
const account = await new Accounts()
const register = await account.register('doej', 'password')
expect(register).toBe(true)
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 resData = { 'id': 1, 'profile': 'undefined', 'user': 'doej' }
const valid = await account.login('doej', 'password')
expect(valid).toEqual(resData)
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()
})
})
describe('Get Selected User', () => {
test('Get User', async done => {
expect.assertions(1)
const account = await new Accounts()
await account.register('doej', 'password')
const users = await account.getUserDetails({ user: 'doej' })
const resData = { 'id': 1, 'profile': 'undefined','user': 'doej' }
expect(users).toEqual(resData)
done()
})
/*test('error if password is weak', async done => {
expect.assertions(1)
const account = await new Accounts()
await expect( account.register('doej', 'pa') )
.rejects.toEqual( Error('weak password') )
done()
})*/
})