import { Connection } from "typeorm" ; import * as faker from "faker" ; import { invalidLogin , confirmEmailError } from "./errorMessages" ; import { User } from "../../../entity/User" ; import { TestClient } from "../../../utils/TestClient" ; import { createTestConn } from "../../../testUtils/createTestConn" ; faker . seed ( Date . now ( ) + 1 ) ; const email = faker . internet . email ( ) ; const password = faker . internet . password ( ) ; const client = new TestClient ( process . env . TEST_HOST as string ) ; let conn ; beforeAll ( async ( ) => { conn = await createTestConn ( ) ; } ) ; afterAll ( async ( ) => { conn . close ( ) ; } ) ; const loginExpectError = async ( e , p , errMsg ) => { const response = await client . login ( e , p ) ; expect ( response . data ) . toEqual ( { login : [ { path : "email" , message : errMsg } ] } ) ; } ; describe ( "login" , ( ) => { test ( "email not found send back error" , async ( ) => { await loginExpectError ( faker . internet . email ( ) , faker . internet . password ( ) , invalidLogin ) ; } ) ; test ( "email not confirmed" , async ( ) => { await client . register ( email , password ) ; await loginExpectError ( email , password , confirmEmailError ) ; await User . update ( { email } , { confirmed : true } ) ; await loginExpectError ( email , faker . internet . password ( ) , invalidLogin ) ; const response = await client . login ( email , password ) ; expect ( response . data ) . toEqual ( { login : null } ) ; } ) ; } ) ;