import { HttpTestingController , HttpClientTestingModule , } from '@angular/common/http/testing' ; import { TestBed } from '@angular/core/testing' ; import { DaffAccountRegistration , DaffLoginInfo , } from '@daffodil/auth' ; import { DaffAccountRegistrationFactory } from '@daffodil/auth/testing' ; import { DaffInMemoryRegisterService } from './register.service' ; describe ( 'Driver | InMemory | Auth | RegisterService' , ( ) => { let registerService ; let httpMock ; const registrationFactory = new DaffAccountRegistrationFactory ( ) ; let email ; let password ; let firstName ; let lastName ; let mockRegistration ; let mockLoginInfo ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ HttpClientTestingModule , ] , providers : [ DaffInMemoryRegisterService , ] , } ) ; httpMock = TestBed . inject ( HttpTestingController ) ; registerService = TestBed . inject ( DaffInMemoryRegisterService ) ; mockRegistration = registrationFactory . create ( ) ; firstName = mockRegistration . customer . firstName ; lastName = mockRegistration . customer . lastName ; email = mockRegistration . customer . email ; password = mockRegistration . password ; mockLoginInfo = { email , password , } ; } ) ; it ( 'should be created' , ( ) => { expect ( registerService ) . toBeTruthy ( ) ; } ) ; describe ( 'register | creating a new user' , ( ) => { afterEach ( ( ) => { httpMock . verify ( ) ; } ) ; it ( 'should send a post request' , ( ) => { registerService . register ( mockRegistration ) . subscribe ( auth => { } ) ; const req = httpMock . expectOne ( `${ registerService . url }register` ) ; expect ( req . request . method ) . toBe ( 'POST' ) ; expect ( req . request . body ) . toEqual ( mockRegistration ) ; req . flush ( mockRegistration . customer ) ; } ) ; it ( 'should return a DaffLoginInfo' , ( ) => { registerService . register ( mockRegistration ) . subscribe ( loginInfo => { expect ( loginInfo ) . toEqual ( mockLoginInfo ) ; } ) ; const req = httpMock . expectOne ( `${ registerService . url }register` ) ; req . flush ( mockRegistration . customer ) ; } ) ; } ) ; } ) ;