blob: 79053fbb078ea3eb47d50a8c9591ab3fb29488b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
"use strict";
const { PartnerLinkAttribution, CONTEXTUAL_SERVICES_PING_TYPES } =
ChromeUtils.importESModule(
"resource:///modules/PartnerLinkAttribution.sys.mjs"
);
const { sinon } = ChromeUtils.importESModule(
"resource://testing-common/Sinon.sys.mjs"
);
const FAKE_PING = { tile_id: 1, position: 1 };
let sandbox;
let stub;
add_task(function setup() {
sandbox = sinon.createSandbox();
stub = sandbox.stub(
PartnerLinkAttribution._pingCentre,
"sendStructuredIngestionPing"
);
stub.returns(200);
registerCleanupFunction(() => {
sandbox.restore();
});
});
add_task(function test_sendContextualService_success() {
for (const type of Object.values(CONTEXTUAL_SERVICES_PING_TYPES)) {
PartnerLinkAttribution.sendContextualServicesPing(FAKE_PING, type);
Assert.ok(stub.calledOnce, `Should send the ping for ${type}`);
const [payload, endpoint] = stub.firstCall.args;
Assert.ok(!!payload.context_id, "Should add context_id to the payload");
Assert.ok(
endpoint.includes(type),
"Should include the ping type in the endpoint URL"
);
stub.resetHistory();
}
});
add_task(function test_rejectUnknownPingType() {
PartnerLinkAttribution.sendContextualServicesPing(FAKE_PING, "unknown-type");
Assert.ok(stub.notCalled, "Should not send the ping with unknown ping type");
});
|