7
7
provideHttpClientTesting ,
8
8
} from '@angular/common/http/testing' ;
9
9
import { TestBed } from '@angular/core/testing' ;
10
+ import { InMemoryBackendConfig } from 'angular-in-memory-web-api' ;
10
11
11
12
import {
12
13
DaffAuthToken ,
@@ -20,7 +21,7 @@ import {
20
21
import { DaffInMemoryLoginService } from './login.service' ;
21
22
22
23
describe ( '@daffodil/auth/driver/in-memory | LoginService' , ( ) => {
23
- let loginService ;
24
+ let service ;
24
25
let httpMock : HttpTestingController ;
25
26
26
27
let registrationFactory : DaffAccountRegistrationFactory ;
@@ -37,13 +38,19 @@ describe('@daffodil/auth/driver/in-memory | LoginService', () => {
37
38
imports : [ ] ,
38
39
providers : [
39
40
DaffInMemoryLoginService ,
41
+ {
42
+ provide : InMemoryBackendConfig ,
43
+ useValue : {
44
+ apiBase : 'api' ,
45
+ } ,
46
+ } ,
40
47
provideHttpClient ( withInterceptorsFromDi ( ) ) ,
41
48
provideHttpClientTesting ( ) ,
42
49
] ,
43
50
} ) ;
44
51
45
52
httpMock = TestBed . inject ( HttpTestingController ) ;
46
- loginService = TestBed . inject ( DaffInMemoryLoginService ) ;
53
+ service = TestBed . inject ( DaffInMemoryLoginService ) ;
47
54
registrationFactory = TestBed . inject ( DaffAccountRegistrationFactory ) ;
48
55
49
56
mockRegistration = registrationFactory . create ( ) ;
@@ -55,7 +62,7 @@ describe('@daffodil/auth/driver/in-memory | LoginService', () => {
55
62
} ) ;
56
63
57
64
it ( 'should be created' , ( ) => {
58
- expect ( loginService ) . toBeTruthy ( ) ;
65
+ expect ( service ) . toBeTruthy ( ) ;
59
66
} ) ;
60
67
61
68
describe ( 'login | getting a token' , ( ) => {
@@ -64,12 +71,12 @@ describe('@daffodil/auth/driver/in-memory | LoginService', () => {
64
71
} ) ;
65
72
66
73
it ( 'should send a post request and return an AuthToken' , done => {
67
- loginService . login ( { email, password } ) . subscribe ( auth => {
74
+ service . login ( { email, password } ) . subscribe ( auth => {
68
75
expect ( auth ) . toEqual ( mockAuth ) ;
69
76
done ( ) ;
70
77
} ) ;
71
78
72
- const req = httpMock . expectOne ( `${ loginService . url } login` ) ;
79
+ const req = httpMock . expectOne ( `${ service . url } / login` ) ;
73
80
expect ( req . request . method ) . toBe ( 'POST' ) ;
74
81
expect ( req . request . body ) . toEqual ( { email, password } ) ;
75
82
@@ -83,12 +90,12 @@ describe('@daffodil/auth/driver/in-memory | LoginService', () => {
83
90
} ) ;
84
91
85
92
it ( 'should send a post request and return an empty Observable' , done => {
86
- loginService . logout ( ) . subscribe ( resp => {
93
+ service . logout ( ) . subscribe ( resp => {
87
94
expect ( resp ) . toBeUndefined ( ) ;
88
95
done ( ) ;
89
96
} ) ;
90
97
91
- const req = httpMock . expectOne ( `${ loginService . url } logout` ) ;
98
+ const req = httpMock . expectOne ( `${ service . url } / logout` ) ;
92
99
expect ( req . request . method ) . toBe ( 'POST' ) ;
93
100
94
101
req . flush ( { success : true } ) ;
0 commit comments