Skip to content

Commit

Permalink
fix(UserAgent): change shape of user agent to reflect other flavours (#…
Browse files Browse the repository at this point in the history
…109)

We decided to change the user agent to `insights-js (<version>)` for easier parsing in looker and more consistency with other flavours.
  • Loading branch information
tkrugg authored Apr 11, 2019
1 parent 11d6c02 commit cc1babf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
18 changes: 6 additions & 12 deletions lib/__tests__/_algoliaAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ describe("algoliaAgent", () => {
});

it("should initialize the client with a default algoliaAgent string", () => {
expect(AlgoliaInsights._ua).toEqual(
"Algolia insights for JavaScript (1.0.1)"
);
expect(AlgoliaInsights._uaURIEncoded).toEqual(
"Algolia%20insights%20for%20JavaScript%20(1.0.1)"
);
expect(AlgoliaInsights._ua).toEqual("insights-js (1.0.1)");
expect(AlgoliaInsights._uaURIEncoded).toEqual("insights-js%20(1.0.1)");
});

it("should allow adding a string to algoliaAgent", () => {
AlgoliaInsights.addAlgoliaAgent("other string");
expect(AlgoliaInsights._ua).toEqual(
"Algolia insights for JavaScript (1.0.1); other string"
);
expect(AlgoliaInsights._ua).toEqual("insights-js (1.0.1); other string");
expect(AlgoliaInsights._uaURIEncoded).toEqual(
"Algolia%20insights%20for%20JavaScript%20(1.0.1)%3B%20other%20string"
"insights-js%20(1.0.1)%3B%20other%20string"
);
});

Expand All @@ -31,10 +25,10 @@ describe("algoliaAgent", () => {
AlgoliaInsights.addAlgoliaAgent("duplicated string");

expect(AlgoliaInsights._ua).toEqual(
"Algolia insights for JavaScript (1.0.1); duplicated string"
"insights-js (1.0.1); duplicated string"
);
expect(AlgoliaInsights._uaURIEncoded).toEqual(
"Algolia%20insights%20for%20JavaScript%20(1.0.1)%3B%20duplicated%20string"
"insights-js%20(1.0.1)%3B%20duplicated%20string"
);
});
});
4 changes: 2 additions & 2 deletions lib/__tests__/_sendEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("sendEvent", () => {
const { query } = url.parse(requestUrl);
expect(querystring.parse(query)).toEqual({
"X-Algolia-API-Key": "testKey",
"X-Algolia-Agent": "Algolia insights for JavaScript (1.0.1)",
"X-Algolia-Agent": "insights-js (1.0.1)",
"X-Algolia-Application-Id": "testId"
});
});
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("sendEvent", () => {
const { query } = url.parse(requestUrl);
expect(querystring.parse(query)).toEqual({
"X-Algolia-API-Key": "testKey",
"X-Algolia-Agent": "Algolia insights for JavaScript (1.0.1)",
"X-Algolia-Agent": "insights-js (1.0.1)",
"X-Algolia-Application-Id": "testId"
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/_algoliaAgent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { version } from "../package.json";

export const DEFAULT_ALGOLIA_AGENT = `Algolia insights for JavaScript (${version})`;
export const DEFAULT_ALGOLIA_AGENT = `insights-js (${version})`;

export function addAlgoliaAgent(algoliaAgent) {
if (this._ua.indexOf(`; ${algoliaAgent}`) === -1) {
Expand Down

0 comments on commit cc1babf

Please sign in to comment.