|
1 | 1 | import AlgoliaInsights from "../insights";
|
2 | 2 | import * as url from "url";
|
| 3 | +import * as querystring from "querystring"; |
| 4 | + |
| 5 | +jest.mock("../../package.json", () => ({ |
| 6 | + version: "1.0.1" |
| 7 | +})); |
3 | 8 |
|
4 | 9 | const credentials = {
|
5 |
| - apiKey: "test", |
6 |
| - appId: "test" |
| 10 | + apiKey: "testKey", |
| 11 | + appId: "testId" |
7 | 12 | };
|
8 | 13 |
|
9 | 14 | describe("sendEvent", () => {
|
@@ -54,6 +59,20 @@ describe("sendEvent", () => {
|
54 | 59 | ]
|
55 | 60 | });
|
56 | 61 | });
|
| 62 | + it("should include X-Algolia-* query parameters", () => { |
| 63 | + (AlgoliaInsights as any).sendEvent("click", { |
| 64 | + eventName: "my-event", |
| 65 | + index: "my-index", |
| 66 | + objectIDs: ["1"] |
| 67 | + }); |
| 68 | + const requestUrl = XMLHttpRequest.open.mock.calls[0][1]; |
| 69 | + const { query } = url.parse(requestUrl); |
| 70 | + expect(querystring.parse(query)).toEqual({ |
| 71 | + "X-Algolia-API-Key": "testKey", |
| 72 | + "X-Algolia-Agent": "Algolia insights for JavaScript (1.0.1)", |
| 73 | + "X-Algolia-Application-Id": "testId" |
| 74 | + }); |
| 75 | + }); |
57 | 76 | });
|
58 | 77 |
|
59 | 78 | describe("with sendBeacon", () => {
|
@@ -100,6 +119,20 @@ describe("sendEvent", () => {
|
100 | 119 | ]
|
101 | 120 | });
|
102 | 121 | });
|
| 122 | + it("should include X-Algolia-* query parameters", () => { |
| 123 | + (AlgoliaInsights as any).sendEvent("click", { |
| 124 | + eventName: "my-event", |
| 125 | + index: "my-index", |
| 126 | + objectIDs: ["1"] |
| 127 | + }); |
| 128 | + const requestUrl = sendBeacon.mock.calls[0][0]; |
| 129 | + const { query } = url.parse(requestUrl); |
| 130 | + expect(querystring.parse(query)).toEqual({ |
| 131 | + "X-Algolia-API-Key": "testKey", |
| 132 | + "X-Algolia-Agent": "Algolia insights for JavaScript (1.0.1)", |
| 133 | + "X-Algolia-Application-Id": "testId" |
| 134 | + }); |
| 135 | + }); |
103 | 136 | });
|
104 | 137 |
|
105 | 138 | describe("init", () => {
|
@@ -277,6 +310,7 @@ describe("sendEvent", () => {
|
277 | 310 | });
|
278 | 311 | });
|
279 | 312 | });
|
| 313 | + |
280 | 314 | describe("filters", () => {
|
281 | 315 | it("should pass over provided filters", () => {
|
282 | 316 | (AlgoliaInsights as any).sendEvent("click", {
|
|
0 commit comments