Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #651 from rhelmer/pass-rallyid-to-study-for-glean
Browse files Browse the repository at this point in the history
Pass Rally ID during core-check response, for use by glean in studies.
  • Loading branch information
rhelmer authored Jun 10, 2021
2 parents 209052c + 3a7e5de commit 5088efb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased changes

[Full changelog](https://github.com/mozilla-rally/core-addon/compare/v1.3.2...master)
* [#651](https://github.com/mozilla-rally/rally-core-addon/pull/651): Pass Rally ID during core-check response, for use by glean in studies.

# v1.3.2 (2021-06-08)

Expand Down
5 changes: 4 additions & 1 deletion core-addon/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,13 @@ export default class Core {

switch (message.type) {
case "core-check": {
let enrolled = !!(await this._storage.getRallyID());
let rallyId = await this._storage.getRallyID();
let enrolled = !!(rallyId);

return {
type: "core-check-response",
data: {
rallyId,
enrolled
}
};
Expand Down
23 changes: 17 additions & 6 deletions support/rally.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class Rally {
this._keyId = key.kid;
this._key = key;
this._enableDevMode = Boolean(enableDevMode);
this._rallyId = null;

let hasRally = await this._checkRallyCore().then(() => {
console.debug("Rally.initialize - Found the Core Add-on.");
Expand Down Expand Up @@ -107,13 +108,23 @@ export class Rally {
let response =
await browser.runtime.sendMessage(CORE_ADDON_ID, msg, {});

if (!response
|| response.type !== "core-check-response"
|| response.data.enrolled !== true) {
throw new Error(`Rally._checkRallyCore - unexpected response returned ${response}`);
}
if (response
&& response.type == "core-check-response") {
if (response.data
&& "enrolled" in response.data
&& response.data.enrolled === true
&& "rallyId" in response.data
&& response.data.rallyId !== null) {
this._rallyId = response.data.rallyId;
} else {
throw new Error(`Rally._checkRallyCore - core addon present, but not enrolled in Rally`);
}
} else{
throw new Error(`Rally._checkRallyCore - unexpected response returned ${response}`);
}

} catch (ex) {
throw new Error("Rally._checkRallyCore - core addon not found");
throw new Error(`Rally._checkRallyCore - core addon check failed with: ${ex}`);
}
}

Expand Down
14 changes: 12 additions & 2 deletions tests/support/rally.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,23 @@ describe('Rally', function () {

assert.rejects(
this.rally._checkRallyCore(),
{message: "Rally._checkRallyCore - core addon not found"}
{message: "Rally._checkRallyCore - core addon check failed with: Error: No addon makes this API reject"}
);
});

it('must fail if the core addon is installed, but user is not enrolled in Rally', async function () {
chrome.runtime.sendMessage.yields(
{type: "core-check-response", data: {rallyId: null, enrolled: false}});

assert.rejects(
this.rally._checkRallyCore(),
{message: "Rally._checkRallyCore - core addon check failed with: Error: Rally._checkRallyCore - core addon present, but not enrolled in Rally"}
);
});

it('must succeed if the core addon is installed', async function () {
chrome.runtime.sendMessage.yields(
{type: "core-check-response", data: {enrolled: true}});
{type: "core-check-response", data: {rallyId: "fakeRallyId", enrolled: true}});

await this.rally._checkRallyCore();
});
Expand Down

0 comments on commit 5088efb

Please sign in to comment.