in progress: loginUser util for testing

This commit is contained in:
Mikayla Dobson
2022-12-16 09:16:54 -06:00
parent 977f1d373a
commit a38bc2793f
5 changed files with 44 additions and 10 deletions

View File

@@ -0,0 +1,19 @@
import request from 'supertest';
const agent = request('localhost:8080');
export default async function loginUser(auth: { token: any }) {
const onResponse = (err: any, res: any) => {
if (err) throw err;
auth.token = res.body.token;
}
agent.post('/auth/login')
.send({
email: "verifieduser@test.com",
password: "verifieduser"
})
.end(onResponse);
return auth;
}

View File

@@ -0,0 +1,13 @@
import loginUser from "../../helpers/loginUser"
describe('login user', () => {
let auth = { token: undefined }
beforeAll(async () => {
auth = await loginUser(auth);
})
it('authenticates a hard-coded user', () => {
console.log(auth);
expect(auth.token).toBeDefined();
})
})