import { TestBed } from '@angular/core/testing' ; import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ; import { RegisterService } from './register.service' ; import { ApplicationConfigService } from 'app/core/config/application-config.service' ; import { Registration } from './register.model' ; describe ( 'RegisterService Service' , ( ) => { let service ; let httpMock ; let applicationConfigService ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ HttpClientTestingModule ] , } ) ; service = TestBed . inject ( RegisterService ) ; applicationConfigService = TestBed . inject ( ApplicationConfigService ) ; httpMock = TestBed . inject ( HttpTestingController ) ; } ) ; afterEach ( ( ) => { httpMock . verify ( ) ; } ) ; describe ( 'Service methods' , ( ) => { it ( 'should call register endpoint with correct values' , ( ) => { const login = 'abc' ; const email = 'test@test.com' ; const password = 'pass' ; const langKey = 'FR' ; const registration = new Registration ( login , email , password , langKey ) ; service . save ( registration ) . subscribe ( ) ; const testRequest = httpMock . expectOne ( { method : 'POST' , url : applicationConfigService . getEndpointFor ( 'api/register' ) , } ) ; expect ( testRequest . request . body ) . toEqual ( { email , langKey , login , password } ) ; } ) ; } ) ; } ) ;