@@ -9,18 +9,12 @@ import { LoginResponse, RegisterResponse } from "@core/lib/models/auth/http.mode
99
1010describe ( "AuthHttpAdapter" , ( ) => {
1111 let adapter : AuthHttpAdapter ;
12- let api : jasmine . SpyObj < ApiService > ;
13- let tokens : jasmine . SpyObj < TokenService > ;
12+ let api : any ;
13+ let tokens : any ;
1414
1515 function setup ( ) : void {
16- api = jasmine . createSpyObj < ApiService > ( "ApiService" , [
17- "get" ,
18- "post" ,
19- "patch" ,
20- "put" ,
21- "getFile" ,
22- ] ) ;
23- tokens = jasmine . createSpyObj < TokenService > ( "TokenService" , [ "getTokens" ] ) ;
16+ api = { get : vi . fn ( ) , post : vi . fn ( ) , patch : vi . fn ( ) , put : vi . fn ( ) , getFile : vi . fn ( ) } ;
17+ tokens = { getTokens : vi . fn ( ) } ;
2418 TestBed . configureTestingModule ( {
2519 providers : [
2620 AuthHttpAdapter ,
@@ -33,147 +27,149 @@ describe("AuthHttpAdapter", () => {
3327
3428 it ( "login идёт в POST /api/token/ с email/password" , ( ) => {
3529 setup ( ) ;
36- api . post . and . returnValue ( of ( { } as LoginResponse ) ) ;
30+ api . post . mockReturnValue ( of ( { } as LoginResponse ) ) ;
3731
3832 adapter . login ( { email : "u@e.com" , password : "p" } ) . subscribe ( ) ;
3933
40- expect ( api . post ) . toHaveBeenCalledOnceWith ( "/api/token/" , {
34+ expect ( api . post ) . toHaveBeenCalledExactlyOnceWith ( "/api/token/" , {
4135 email : "u@e.com" ,
4236 password : "p" ,
4337 } ) ;
4438 } ) ;
4539
4640 it ( "logout идёт в POST /auth/logout/ с refreshToken из TokenService" , ( ) => {
4741 setup ( ) ;
48- tokens . getTokens . and . returnValue ( { access : "a" , refresh : "r" } ) ;
49- api . post . and . returnValue ( of ( undefined ) ) ;
42+ tokens . getTokens . mockReturnValue ( { access : "a" , refresh : "r" } ) ;
43+ api . post . mockReturnValue ( of ( undefined ) ) ;
5044
5145 adapter . logout ( ) . subscribe ( ) ;
5246
53- expect ( api . post ) . toHaveBeenCalledOnceWith ( "/auth/logout/" , { refreshToken : "r" } ) ;
47+ expect ( api . post ) . toHaveBeenCalledExactlyOnceWith ( "/auth/logout/" , { refreshToken : "r" } ) ;
5448 } ) ;
5549
5650 it ( "register идёт в POST /auth/users/" , ( ) => {
5751 setup ( ) ;
58- api . post . and . returnValue ( of ( { } as RegisterResponse ) ) ;
52+ api . post . mockReturnValue ( of ( { } as RegisterResponse ) ) ;
5953 const data = { email : "e" , password : "p" } as unknown as Parameters < typeof adapter . register > [ 0 ] ;
6054
6155 adapter . register ( data ) . subscribe ( ) ;
6256
63- expect ( api . post ) . toHaveBeenCalledOnceWith ( "/auth/users/" , data ) ;
57+ expect ( api . post ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/" , data ) ;
6458 } ) ;
6559
6660 it ( "downloadCV идёт в getFile /auth/users/download_cv/" , ( ) => {
6761 setup ( ) ;
68- api . getFile . and . returnValue ( of ( new Blob ( ) ) ) ;
62+ api . getFile . mockReturnValue ( of ( new Blob ( ) ) ) ;
6963
7064 adapter . downloadCV ( ) . subscribe ( ) ;
7165
72- expect ( api . getFile ) . toHaveBeenCalledOnceWith ( "/auth/users/download_cv/" ) ;
66+ expect ( api . getFile ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/download_cv/" ) ;
7367 } ) ;
7468
7569 it ( "getProfile идёт в GET /auth/users/current/" , ( ) => {
7670 setup ( ) ;
77- api . get . and . returnValue ( of ( { } as User ) ) ;
71+ api . get . mockReturnValue ( of ( { } as User ) ) ;
7872
7973 adapter . getProfile ( ) . subscribe ( ) ;
8074
81- expect ( api . get ) . toHaveBeenCalledOnceWith ( "/auth/users/current/" ) ;
75+ expect ( api . get ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/current/" ) ;
8276 } ) ;
8377
8478 it ( "getUserRoles идёт в GET /auth/users/types/" , ( ) => {
8579 setup ( ) ;
86- api . get . and . returnValue ( of ( [ [ 1 , "r" ] ] as [ [ number , string ] ] ) ) ;
80+ api . get . mockReturnValue ( of ( [ [ 1 , "r" ] ] as [ [ number , string ] ] ) ) ;
8781
8882 adapter . getUserRoles ( ) . subscribe ( ) ;
8983
90- expect ( api . get ) . toHaveBeenCalledOnceWith ( "/auth/users/types/" ) ;
84+ expect ( api . get ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/types/" ) ;
9185 } ) ;
9286
9387 it ( "getLeaderProjects идёт в GET /auth/users/projects/leader/" , ( ) => {
9488 setup ( ) ;
95- api . get . and . returnValue ( of ( { count : 0 , results : [ ] , next : "" , previous : "" } ) ) ;
89+ api . get . mockReturnValue ( of ( { count : 0 , results : [ ] , next : "" , previous : "" } ) ) ;
9690
9791 adapter . getLeaderProjects ( ) . subscribe ( ) ;
9892
99- expect ( api . get ) . toHaveBeenCalledOnceWith ( "/auth/users/projects/leader/" ) ;
93+ expect ( api . get ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/projects/leader/" ) ;
10094 } ) ;
10195
10296 it ( "getChangeableRoles идёт в GET /auth/users/roles/" , ( ) => {
10397 setup ( ) ;
104- api . get . and . returnValue ( of ( [ [ 1 , "r" ] ] as [ [ number , string ] ] ) ) ;
98+ api . get . mockReturnValue ( of ( [ [ 1 , "r" ] ] as [ [ number , string ] ] ) ) ;
10599
106100 adapter . getChangeableRoles ( ) . subscribe ( ) ;
107101
108- expect ( api . get ) . toHaveBeenCalledOnceWith ( "/auth/users/roles/" ) ;
102+ expect ( api . get ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/roles/" ) ;
109103 } ) ;
110104
111105 it ( "getUser идёт в GET /auth/users/:id/" , ( ) => {
112106 setup ( ) ;
113- api . get . and . returnValue ( of ( { } as User ) ) ;
107+ api . get . mockReturnValue ( of ( { } as User ) ) ;
114108
115109 adapter . getUser ( 7 ) . subscribe ( ) ;
116110
117- expect ( api . get ) . toHaveBeenCalledOnceWith ( "/auth/users/7/" ) ;
111+ expect ( api . get ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/7/" ) ;
118112 } ) ;
119113
120114 it ( "saveAvatar идёт в PATCH /auth/users/:pid с avatar" , ( ) => {
121115 setup ( ) ;
122- api . patch . and . returnValue ( of ( { } as User ) ) ;
116+ api . patch . mockReturnValue ( of ( { } as User ) ) ;
123117
124118 adapter . saveAvatar ( "https://x/a.png" , 7 ) . subscribe ( ) ;
125119
126- expect ( api . patch ) . toHaveBeenCalledOnceWith ( "/auth/users/7/" , { avatar : "https://x/a.png" } ) ;
120+ expect ( api . patch ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/7/" , {
121+ avatar : "https://x/a.png" ,
122+ } ) ;
127123 } ) ;
128124
129125 it ( "saveProfile идёт в PATCH /auth/users/:id/ с частичными данными" , ( ) => {
130126 setup ( ) ;
131- api . patch . and . returnValue ( of ( { } as User ) ) ;
127+ api . patch . mockReturnValue ( of ( { } as User ) ) ;
132128 const profile : Partial < User > = { id : 7 , firstName : "A" } ;
133129
134130 adapter . saveProfile ( profile ) . subscribe ( ) ;
135131
136- expect ( api . patch ) . toHaveBeenCalledOnceWith ( "/auth/users/7/" , profile ) ;
132+ expect ( api . patch ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/7/" , profile ) ;
137133 } ) ;
138134
139135 it ( "setOnboardingStage идёт в PUT /auth/users/:pid/set_onboarding_stage/" , ( ) => {
140136 setup ( ) ;
141- api . put . and . returnValue ( of ( { } as User ) ) ;
137+ api . put . mockReturnValue ( of ( { } as User ) ) ;
142138
143139 adapter . setOnboardingStage ( 2 , 7 ) . subscribe ( ) ;
144140
145- expect ( api . put ) . toHaveBeenCalledOnceWith ( "/auth/users/7/set_onboarding_stage/" , {
141+ expect ( api . put ) . toHaveBeenCalledExactlyOnceWith ( "/auth/users/7/set_onboarding_stage/" , {
146142 onboardingStage : 2 ,
147143 } ) ;
148144 } ) ;
149145
150146 it ( "resetPassword идёт в POST /auth/reset_password/ c email" , ( ) => {
151147 setup ( ) ;
152- api . post . and . returnValue ( of ( undefined ) ) ;
148+ api . post . mockReturnValue ( of ( undefined ) ) ;
153149
154150 adapter . resetPassword ( "u@e.com" ) . subscribe ( ) ;
155151
156- expect ( api . post ) . toHaveBeenCalledOnceWith ( "/auth/reset_password/" , { email : "u@e.com" } ) ;
152+ expect ( api . post ) . toHaveBeenCalledExactlyOnceWith ( "/auth/reset_password/" , { email : "u@e.com" } ) ;
157153 } ) ;
158154
159155 it ( "setPassword идёт в POST /auth/reset_password/confirm/ c password/token" , ( ) => {
160156 setup ( ) ;
161- api . post . and . returnValue ( of ( undefined ) ) ;
157+ api . post . mockReturnValue ( of ( undefined ) ) ;
162158
163159 adapter . setPassword ( "newpass" , "tok" ) . subscribe ( ) ;
164160
165- expect ( api . post ) . toHaveBeenCalledOnceWith ( "/auth/reset_password/confirm/" , {
161+ expect ( api . post ) . toHaveBeenCalledExactlyOnceWith ( "/auth/reset_password/confirm/" , {
166162 password : "newpass" ,
167163 token : "tok" ,
168164 } ) ;
169165 } ) ;
170166
171167 it ( "resendEmail идёт в POST /auth/resend_email/ c email" , ( ) => {
172168 setup ( ) ;
173- api . post . and . returnValue ( of ( { } as User ) ) ;
169+ api . post . mockReturnValue ( of ( { } as User ) ) ;
174170
175171 adapter . resendEmail ( "u@e.com" ) . subscribe ( ) ;
176172
177- expect ( api . post ) . toHaveBeenCalledOnceWith ( "/auth/resend_email/" , { email : "u@e.com" } ) ;
173+ expect ( api . post ) . toHaveBeenCalledExactlyOnceWith ( "/auth/resend_email/" , { email : "u@e.com" } ) ;
178174 } ) ;
179175} ) ;
0 commit comments