@@ -7,6 +7,8 @@ import sinon from "sinon";
7
7
import { v4 as UUIDv4 } from "uuid" ;
8
8
9
9
import Glean from "../../../src/core/glean" ;
10
+ import PingType from "../../../src/core/pings" ;
11
+ import collectAndStorePing from "../../../src/core/pings/maker" ;
10
12
import PingUploader , { UploadResultStatus } from "../../../src/core/upload" ;
11
13
12
14
const sandbox = sinon . createSandbox ( ) ;
@@ -19,21 +21,15 @@ const sandbox = sinon.createSandbox();
19
21
* @returns The array of identifiers of the pings added to the database.
20
22
*/
21
23
async function fillUpPingsDatabase ( numPings : number ) : Promise < string [ ] > {
22
- const path = "some/random/path/doesnt/matter" ;
23
- const payload = {
24
- ping_info : {
25
- seq : 1 ,
26
- start_time : "2020-01-11+01:00" ,
27
- end_time : "2020-01-12+01:00" ,
28
- } ,
29
- client_info : {
30
- telemetry_sdk_build : "32.0.0"
31
- }
32
- } ;
24
+ const ping = new PingType ( {
25
+ name : "ping" ,
26
+ includeClientId : true ,
27
+ sendIfEmpty : true ,
28
+ } ) ;
33
29
34
30
const identifiers = Array . from ( { length : numPings } , ( ) => UUIDv4 ( ) ) ;
35
31
for ( const identifier of identifiers ) {
36
- await Glean . pingsDatabase . recordPing ( path , identifier , payload ) ;
32
+ await collectAndStorePing ( identifier , ping ) ;
37
33
}
38
34
39
35
return identifiers ;
@@ -190,4 +186,24 @@ describe("PingUploader", function() {
190
186
await waitForGleanUploader ( ) ;
191
187
assert . strictEqual ( stub . callCount , 3 ) ;
192
188
} ) ;
189
+
190
+ it ( "correctly build ping request" , async function ( ) {
191
+ const postSpy = sandbox . spy ( Glean . platform . uploader , "post" ) ;
192
+
193
+ const expectedDocumentId = ( await fillUpPingsDatabase ( 1 ) ) [ 0 ] ;
194
+ await waitForGleanUploader ( ) ;
195
+
196
+ const url = postSpy . firstCall . args [ 0 ] . split ( "/" ) ;
197
+ const documentId = url [ url . length - 1 ] ;
198
+ const headers = postSpy . firstCall . args [ 2 ] || { } ;
199
+
200
+ assert . strictEqual ( documentId , expectedDocumentId ) ;
201
+
202
+ assert . ok ( "Date" in headers ) ;
203
+ assert . ok ( "User-Agent" in headers ) ;
204
+ assert . ok ( "Content-Type" in headers ) ;
205
+ assert . ok ( "X-Client-Type" in headers ) ;
206
+ assert . ok ( "X-Client-Version" in headers ) ;
207
+ assert . ok ( "Content-Length" in headers ) ;
208
+ } ) ;
193
209
} ) ;
0 commit comments