@@ -19,13 +19,13 @@ import { FirebaseError } from '@firebase/util';
19
19
import { expect } from 'chai' ;
20
20
import { SinonStub , stub } from 'sinon' ;
21
21
import { CreateInstallationResponse } from '../interfaces/api-response' ;
22
- import { AppConfig } from '../interfaces/installation-impl' ;
22
+ import { FirebaseInstallationsImpl } from '../interfaces/installation-impl' ;
23
23
import {
24
24
InProgressInstallationEntry ,
25
25
RequestStatus
26
26
} from '../interfaces/installation-entry' ;
27
27
import { compareHeaders } from '../testing/compare-headers' ;
28
- import { getFakeAppConfig } from '../testing/fake-generators' ;
28
+ import { getFakeInstallations } from '../testing/fake-generators' ;
29
29
import '../testing/setup' ;
30
30
import {
31
31
INSTALLATIONS_API_URL ,
@@ -38,13 +38,13 @@ import { createInstallationRequest } from './create-installation-request';
38
38
const FID = 'defenders-of-the-faith' ;
39
39
40
40
describe ( 'createInstallationRequest' , ( ) => {
41
- let appConfig : AppConfig ;
41
+ let fakeInstallations : FirebaseInstallationsImpl ;
42
42
let fetchSpy : SinonStub < [ RequestInfo , RequestInit ?] , Promise < Response > > ;
43
43
let inProgressInstallationEntry : InProgressInstallationEntry ;
44
44
let response : CreateInstallationResponse ;
45
45
46
46
beforeEach ( ( ) => {
47
- appConfig = getFakeAppConfig ( ) ;
47
+ fakeInstallations = getFakeInstallations ( ) ;
48
48
49
49
inProgressInstallationEntry = {
50
50
fid : FID ,
@@ -71,7 +71,7 @@ describe('createInstallationRequest', () => {
71
71
72
72
it ( 'registers a pending InstallationEntry' , async ( ) => {
73
73
const registeredInstallationEntry = await createInstallationRequest (
74
- appConfig ,
74
+ fakeInstallations ,
75
75
inProgressInstallationEntry
76
76
) ;
77
77
expect ( registeredInstallationEntry . registrationStatus ) . to . equal (
@@ -83,12 +83,13 @@ describe('createInstallationRequest', () => {
83
83
const expectedHeaders = new Headers ( {
84
84
'Content-Type' : 'application/json' ,
85
85
Accept : 'application/json' ,
86
- 'x-goog-api-key' : 'apiKey'
86
+ 'x-goog-api-key' : 'apiKey' ,
87
+ 'x-firebase-client' : 'a/1.2.3 b/2.3.4'
87
88
} ) ;
88
89
const expectedBody = {
89
90
fid : FID ,
90
91
authVersion : INTERNAL_AUTH_VERSION ,
91
- appId : appConfig . appId ,
92
+ appId : fakeInstallations . appConfig . appId ,
92
93
sdkVersion : PACKAGE_VERSION
93
94
} ;
94
95
const expectedRequest : RequestInit = {
@@ -98,7 +99,10 @@ describe('createInstallationRequest', () => {
98
99
} ;
99
100
const expectedEndpoint = `${ INSTALLATIONS_API_URL } /projects/projectId/installations` ;
100
101
101
- await createInstallationRequest ( appConfig , inProgressInstallationEntry ) ;
102
+ await createInstallationRequest (
103
+ fakeInstallations ,
104
+ inProgressInstallationEntry
105
+ ) ;
102
106
expect ( fetchSpy ) . to . be . calledOnceWith ( expectedEndpoint , expectedRequest ) ;
103
107
const actualHeaders = fetchSpy . lastCall . lastArg . headers ;
104
108
compareHeaders ( expectedHeaders , actualHeaders ) ;
@@ -117,7 +121,7 @@ describe('createInstallationRequest', () => {
117
121
fetchSpy . resolves ( new Response ( JSON . stringify ( response ) ) ) ;
118
122
119
123
const registeredInstallationEntry = await createInstallationRequest (
120
- appConfig ,
124
+ fakeInstallations ,
121
125
inProgressInstallationEntry
122
126
) ;
123
127
expect ( registeredInstallationEntry . fid ) . to . equal ( FID ) ;
@@ -138,7 +142,10 @@ describe('createInstallationRequest', () => {
138
142
) ;
139
143
140
144
await expect (
141
- createInstallationRequest ( appConfig , inProgressInstallationEntry )
145
+ createInstallationRequest (
146
+ fakeInstallations ,
147
+ inProgressInstallationEntry
148
+ )
142
149
) . to . be . rejectedWith ( FirebaseError ) ;
143
150
} ) ;
144
151
@@ -157,7 +164,10 @@ describe('createInstallationRequest', () => {
157
164
fetchSpy . onCall ( 1 ) . resolves ( new Response ( JSON . stringify ( response ) ) ) ;
158
165
159
166
await expect (
160
- createInstallationRequest ( appConfig , inProgressInstallationEntry )
167
+ createInstallationRequest (
168
+ fakeInstallations ,
169
+ inProgressInstallationEntry
170
+ )
161
171
) . to . be . fulfilled ;
162
172
expect ( fetchSpy ) . to . be . calledTwice ;
163
173
} ) ;
0 commit comments