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'); }); }); 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(); let user1 = await Users.findUserById(1); expect(user1.username).toBe('gabetest'); await Users.removeUser(1); let userDel = await Users.findUserById(1); expect(userDel).toBeUndefined(); }); }); 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'); }); });