2019-08-01 23:18:56 +00:00
|
|
|
const db = require('../../data/dbConfig');
|
|
|
|
const Users = require('./usersModel');
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
await db('users').truncate();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Users.addUser', () => {
|
|
|
|
|
|
|
|
it('is able to insert user to the db', async () => {
|
|
|
|
await Users.addUser({
|
|
|
|
email: "gabetest@ls.com",
|
|
|
|
username: "gabetest",
|
|
|
|
password: "1234"
|
|
|
|
});
|
|
|
|
await Users.addUser({
|
|
|
|
email: "gabetest2@ls.com",
|
|
|
|
username: "gabetest2",
|
|
|
|
password: "1234"
|
|
|
|
});
|
|
|
|
|
|
|
|
let users = await Users.findUserById(2);
|
|
|
|
expect(users.username).toBe('gabetest2');
|
|
|
|
});
|
2019-08-01 23:47:48 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('Users.removeUser', () => {
|
|
|
|
it('is able to remove an user', async () => {
|
|
|
|
await Users.addUser({
|
|
|
|
email: "gabetest@ls.com",
|
|
|
|
username: "gabetest",
|
|
|
|
password: "1234"
|
|
|
|
});
|
|
|
|
await Users.addUser({
|
|
|
|
email: "gabetest2@ls.com",
|
|
|
|
username: "gabetest2",
|
|
|
|
password: "1234"
|
|
|
|
});
|
|
|
|
await Users.findUserById(2);
|
|
|
|
|
|
|
|
await Users.removeUser(2);
|
|
|
|
let userDel2 = await Users.findUserById(2);
|
|
|
|
expect(userDel2).toBeUndefined();
|
2019-08-01 23:18:56 +00:00
|
|
|
|
2019-08-01 23:47:48 +00:00
|
|
|
let user1 = await Users.findUserById(1);
|
|
|
|
expect(user1.username).toBe('gabetest');
|
2019-08-01 23:18:56 +00:00
|
|
|
|
2019-08-01 23:47:48 +00:00
|
|
|
await Users.removeUser(1);
|
|
|
|
let userDel = await Users.findUserById(1);
|
|
|
|
expect(userDel).toBeUndefined();
|
|
|
|
});
|
2019-08-01 23:18:56 +00:00
|
|
|
});
|
|
|
|
|
2019-08-01 23:47:48 +00:00
|
|
|
describe('Users.updateUser', () => {
|
|
|
|
it('is able to update a user', async () => {
|
|
|
|
await Users.addUser({
|
|
|
|
email: "gabetest@ls.com",
|
|
|
|
username: "gabetest",
|
|
|
|
password: "1234"
|
|
|
|
});
|
|
|
|
|
|
|
|
let user = await Users.findUserById(1);
|
|
|
|
expect(user.username).toBe('gabetest');
|
|
|
|
|
|
|
|
await Users.updateUser(1, {
|
|
|
|
email: "gabetest@ls.com",
|
|
|
|
username: "gabetestChanged",
|
|
|
|
password: "1234"
|
|
|
|
});
|
|
|
|
|
|
|
|
let updatedUser = await Users.findUserById(1);
|
|
|
|
expect(updatedUser.username).toBe('gabetestChanged');
|
|
|
|
});
|
|
|
|
});
|