@@ -7,6 +7,8 @@ import sinon from "sinon";
77import { v4 as UUIDv4 } from "uuid" ;
88
99import Glean from "../../../src/core/glean" ;
10+ import PingType from "../../../src/core/pings" ;
11+ import collectAndStorePing from "../../../src/core/pings/maker" ;
1012import PingUploader , { UploadResultStatus } from "../../../src/core/upload" ;
1113
1214const sandbox = sinon . createSandbox ( ) ;
@@ -19,21 +21,15 @@ const sandbox = sinon.createSandbox();
1921 * @returns The array of identifiers of the pings added to the database.
2022 */
2123async 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+ } ) ;
3329
3430 const identifiers = Array . from ( { length : numPings } , ( ) => UUIDv4 ( ) ) ;
3531 for ( const identifier of identifiers ) {
36- await Glean . pingsDatabase . recordPing ( path , identifier , payload ) ;
32+ await collectAndStorePing ( identifier , ping ) ;
3733 }
3834
3935 return identifiers ;
@@ -190,4 +186,24 @@ describe("PingUploader", function() {
190186 await waitForGleanUploader ( ) ;
191187 assert . strictEqual ( stub . callCount , 3 ) ;
192188 } ) ;
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+ } ) ;
193209} ) ;
0 commit comments