1- import { BrowserXSRFService } from './browser-xsrf.service' ;
21import { HttpClient } from '@angular/common/http' ;
3- import { RESTURLCombiner } from '../url-combiner/rest-url-combiner' ;
2+ import {
3+ HttpClientTestingModule ,
4+ HttpTestingController ,
5+ } from '@angular/common/http/testing' ;
46import { TestBed } from '@angular/core/testing' ;
5- import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ;
7+
8+ import { RESTURLCombiner } from '../url-combiner/rest-url-combiner' ;
9+ import { BrowserXSRFService } from './browser-xsrf.service' ;
610
711describe ( `BrowserXSRFService` , ( ) => {
812 let service : BrowserXSRFService ;
@@ -14,28 +18,30 @@ describe(`BrowserXSRFService`, () => {
1418 beforeEach ( ( ) => {
1519 TestBed . configureTestingModule ( {
1620 imports : [ HttpClientTestingModule ] ,
17- providers : [ BrowserXSRFService ]
21+ providers : [ BrowserXSRFService ] ,
1822 } ) ;
1923 httpClient = TestBed . inject ( HttpClient ) ;
2024 httpTestingController = TestBed . inject ( HttpTestingController ) ;
2125 service = TestBed . inject ( BrowserXSRFService ) ;
2226 } ) ;
2327
2428 describe ( `initXSRFToken` , ( ) => {
25- it ( `should perform a POST to the csrf endpoint` , ( ) => {
29+ it ( `should perform a GET to the csrf endpoint` , ( done : DoneFn ) => {
2630 service . initXSRFToken ( httpClient ) ( ) ;
2731
2832 const req = httpTestingController . expectOne ( {
2933 url : endpointURL ,
30- method : 'POST'
34+ method : 'GET' ,
3135 } ) ;
3236
3337 req . flush ( { } ) ;
3438 httpTestingController . verify ( ) ;
39+ expect ( ) . nothing ( ) ;
40+ done ( ) ;
3541 } ) ;
3642
37- describe ( `when the POST succeeds` , ( ) => {
38- it ( `should set tokenInitialized$ to true` , ( ) => {
43+ describe ( `when the GET succeeds` , ( ) => {
44+ it ( `should set tokenInitialized$ to true` , ( done : DoneFn ) => {
3945 service . initXSRFToken ( httpClient ) ( ) ;
4046
4147 const req = httpTestingController . expectOne ( endpointURL ) ;
@@ -44,19 +50,7 @@ describe(`BrowserXSRFService`, () => {
4450 httpTestingController . verify ( ) ;
4551
4652 expect ( service . tokenInitialized$ . getValue ( ) ) . toBeTrue ( ) ;
47- } ) ;
48- } ) ;
49-
50- describe ( `when the POST fails` , ( ) => {
51- it ( `should set tokenInitialized$ to true` , ( ) => {
52- service . initXSRFToken ( httpClient ) ( ) ;
53-
54- const req = httpTestingController . expectOne ( endpointURL ) ;
55-
56- req . error ( new ErrorEvent ( '415' ) ) ;
57- httpTestingController . verify ( ) ;
58-
59- expect ( service . tokenInitialized$ . getValue ( ) ) . toBeTrue ( ) ;
53+ done ( ) ;
6054 } ) ;
6155 } ) ;
6256
0 commit comments