1 import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
2 import { Modules } from "@medusajs/framework/utils"
3 import { resolve } from "path"
4 import { IAnalyticsModuleService } from "@medusajs/types"
5 import { AnalyticsProviderServiceFixtures } from "../__fixtures__/providers/default-provider"
6
7 jest.setTimeout(100000)
8
9 const moduleOptions = {
10 providers: [
11 {
12 resolve: resolve(
13 process.cwd() +
14 "/integration-tests/__fixtures__/providers/default-provider"
15 ),
16 id: "default-provider",
17 },
18 ],
19 }
20
21 moduleIntegrationTestRunner<IAnalyticsModuleService>({
22 moduleName: Modules.ANALYTICS,
23 moduleOptions: moduleOptions,
24 testSuite: ({ service }) => {
25 describe("Analytics Module Service", () => {
26 let spies: {
27 track: jest.SpyInstance
28 identify: jest.SpyInstance
29 }
30
31 beforeAll(async () => {
32 spies = {
33 track: jest.spyOn(
34 AnalyticsProviderServiceFixtures.prototype,
35 "track"
36 ),
37 identify: jest.spyOn(
38 AnalyticsProviderServiceFixtures.prototype,
39 "identify"
40 ),
41 }
42 })
43
44 afterEach(async () => {
45 jest.clearAllMocks()
46 })
47
48 it("should call the provider's track method", async () => {
49 await service.track({
50 event: "test-event",
51 actor_id: "test-user",
52 properties: {
53 test: "test",
54 },
55 })
56
57 expect(spies.track).toHaveBeenCalledWith({
58 event: "test-event",
59 actor_id: "test-user",
60 properties: {
61 test: "test",
62 },
63 })
64 })
65
66 it("should call the provider's identify method to identify an actor", async () => {
67 await service.identify({
68 actor_id: "test-user",
69 properties: {
70 test: "test",
71 },
72 })
73
74 expect(spies.identify).toHaveBeenCalledWith({
75 actor_id: "test-user",
76 properties: {
77 test: "test",
78 },
79 })
80 })
81
82 it("should call the provider's identify method to identify a group", async () => {
83 await service.identify({
84 group: {
85 type: "organization",
86 id: "test-organization",
87 },
88 properties: {
89 test: "test",
90 },
91 })
92
93 expect(spies.identify).toHaveBeenCalledWith({
94 group: {
95 type: "organization",
96 id: "test-organization",
97 },
98 properties: {
99 test: "test",
100 },
101 })
102 })
103 })
104 },
105 })