in progress: loginUser util for testing
This commit is contained in:
19
server/jest/helpers/loginUser.ts
Normal file
19
server/jest/helpers/loginUser.ts
Normal 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;
|
||||
}
|
||||
13
server/jest/tests/util/loginUser.test.ts
Normal file
13
server/jest/tests/util/loginUser.test.ts
Normal 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();
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user