Skip to content

Commit ef16e0b

Browse files
committed
Add test coverage
1 parent 3ab1b18 commit ef16e0b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

glean/tests/core/pings/index.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,64 @@ describe("PingType", function() {
107107
const storedPings = await Context.pingsDatabase["store"]._getWholeStore();
108108
assert.strictEqual(Object.keys(storedPings).length, 0);
109109
});
110+
111+
it("runs a validator with no metrics tests", async function() {
112+
const ping = new PingType({
113+
name: "custom",
114+
includeClientId: true,
115+
sendIfEmpty: false,
116+
reasonCodes: ["test"]
117+
});
118+
119+
// We did not call the testing API yet, internals should be undefined.
120+
assert.strictEqual(ping["testResolutionFunction"], undefined);
121+
assert.strictEqual(ping["testValidator"], undefined);
122+
123+
let validatorRun = false;
124+
const p = ping.testBeforeNextSubmit(r => {
125+
assert.strictEqual(r, "test");
126+
validatorRun = true;
127+
return Promise.resolve();
128+
});
129+
130+
// Internals should be defined after the API was called.
131+
assert.notStrictEqual(ping["testResolutionFunction"], undefined);
132+
assert.notStrictEqual(ping["testValidator"], undefined);
133+
134+
ping.submit("test");
135+
await p;
136+
137+
assert.ok(validatorRun);
138+
});
139+
140+
it("runs a validator with metrics tests", async function() {
141+
const TEST_VALUE = 2908;
142+
143+
const ping = new PingType({
144+
name: "custom",
145+
includeClientId: true,
146+
sendIfEmpty: false,
147+
reasonCodes: ["test"]
148+
});
149+
const counter = new CounterMetricType({
150+
category: "aCategory",
151+
name: "aCounterMetric",
152+
sendInPings: ["custom"],
153+
lifetime: Lifetime.Ping,
154+
disabled: false
155+
});
156+
counter.add(TEST_VALUE);
157+
158+
let validatorRun = false;
159+
const p = ping.testBeforeNextSubmit(async r => {
160+
assert.strictEqual(r, "test");
161+
assert.strictEqual(await counter.testGetValue(), TEST_VALUE);
162+
validatorRun = true;
163+
});
164+
165+
ping.submit("test");
166+
await p;
167+
168+
assert.ok(validatorRun);
169+
});
110170
});

0 commit comments

Comments
 (0)