1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var tslib_1 = require("tslib");
|
4 | var http_1 = require("../../commons/utils/http");
|
5 | var event_1 = require("../core/event");
|
6 | var vtex_runner_1 = require("./vtex-runner");
|
7 | var vtexRunner = new vtex_runner_1.VTEXRunner();
|
8 | beforeEach(function () {
|
9 | var post = jest.fn().mockReturnValue({ status: 204 });
|
10 | post.mockClear();
|
11 | http_1.Http.post = post;
|
12 | });
|
13 | test("send api click event", function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
14 | var clickData;
|
15 | return tslib_1.__generator(this, function (_a) {
|
16 | switch (_a.label) {
|
17 | case 0:
|
18 | clickData = Buffer.from(JSON.stringify({
|
19 | uniqueId: "emailmkt",
|
20 | product: "1",
|
21 | })).toString("base64");
|
22 | window.history.pushState({}, "", "/?baa=" + clickData);
|
23 | return [4 , vtexRunner.start()];
|
24 | case 1:
|
25 | _a.sent();
|
26 | expect(http_1.Http.post).toHaveBeenCalledTimes(2);
|
27 | expect(http_1.Http.post).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({ type: event_1.EventType.SessionPing }));
|
28 | expect(http_1.Http.post).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
|
29 | type: event_1.EventType.ApiClick,
|
30 | uniqueId: "emailmkt",
|
31 | product: "1",
|
32 | }));
|
33 | return [2 ];
|
34 | }
|
35 | });
|
36 | }); });
|
37 | test("send mail click event", function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
38 | var clickData;
|
39 | return tslib_1.__generator(this, function (_a) {
|
40 | switch (_a.label) {
|
41 | case 0:
|
42 | clickData = Buffer.from(JSON.stringify({
|
43 | id: "123456",
|
44 | product: "1",
|
45 | attempt: "1",
|
46 | })).toString("base64");
|
47 | window.history.pushState({}, "", "/?bma=" + clickData);
|
48 | return [4 , vtexRunner.start()];
|
49 | case 1:
|
50 | _a.sent();
|
51 | expect(http_1.Http.post).toHaveBeenCalledTimes(2);
|
52 | expect(http_1.Http.post).toHaveBeenNthCalledWith(1, expect.any(String), expect.objectContaining({ type: event_1.EventType.SessionPing }));
|
53 | expect(http_1.Http.post).toHaveBeenNthCalledWith(2, expect.any(String), expect.objectContaining({
|
54 | type: event_1.EventType.MailClick,
|
55 | id: "123456",
|
56 | product: "1",
|
57 | attempt: "1",
|
58 | }));
|
59 | return [2 ];
|
60 | }
|
61 | });
|
62 | }); });
|
63 |
|
\ | No newline at end of file |