feat: Add an analytics module and local and posthog providers (#12505)
* feat: Add an analytics module and local and posthog providers * fix: Add tests and wire up in missing places * fix: Address feedback and add missing module typing * fix: Address feedback and add missing module typing --------- Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
Oli Juhl
parent
52bd9f9a53
commit
b9a51e217d
@@ -0,0 +1,105 @@
|
||||
import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { Modules } from "@medusajs/framework/utils"
|
||||
import { resolve } from "path"
|
||||
import { IAnalyticsModuleService } from "@medusajs/types"
|
||||
import { AnalyticsProviderServiceFixtures } from "../__fixtures__/providers/default-provider"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
const moduleOptions = {
|
||||
providers: [
|
||||
{
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
"/integration-tests/__fixtures__/providers/default-provider"
|
||||
),
|
||||
id: "default-provider",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
moduleIntegrationTestRunner<IAnalyticsModuleService>({
|
||||
moduleName: Modules.ANALYTICS,
|
||||
moduleOptions: moduleOptions,
|
||||
testSuite: ({ service }) => {
|
||||
describe("Analytics Module Service", () => {
|
||||
let spies: {
|
||||
track: jest.SpyInstance
|
||||
identify: jest.SpyInstance
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
spies = {
|
||||
track: jest.spyOn(
|
||||
AnalyticsProviderServiceFixtures.prototype,
|
||||
"track"
|
||||
),
|
||||
identify: jest.spyOn(
|
||||
AnalyticsProviderServiceFixtures.prototype,
|
||||
"identify"
|
||||
),
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
jest.clearAllMocks()
|
||||
})
|
||||
|
||||
it("should call the provider's track method", async () => {
|
||||
await service.track({
|
||||
event: "test-event",
|
||||
actor_id: "test-user",
|
||||
properties: {
|
||||
test: "test",
|
||||
},
|
||||
})
|
||||
|
||||
expect(spies.track).toHaveBeenCalledWith({
|
||||
event: "test-event",
|
||||
actor_id: "test-user",
|
||||
properties: {
|
||||
test: "test",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should call the provider's identify method to identify an actor", async () => {
|
||||
await service.identify({
|
||||
actor_id: "test-user",
|
||||
properties: {
|
||||
test: "test",
|
||||
},
|
||||
})
|
||||
|
||||
expect(spies.identify).toHaveBeenCalledWith({
|
||||
actor_id: "test-user",
|
||||
properties: {
|
||||
test: "test",
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
it("should call the provider's identify method to identify a group", async () => {
|
||||
await service.identify({
|
||||
group: {
|
||||
type: "organization",
|
||||
id: "test-organization",
|
||||
},
|
||||
properties: {
|
||||
test: "test",
|
||||
},
|
||||
})
|
||||
|
||||
expect(spies.identify).toHaveBeenCalledWith({
|
||||
group: {
|
||||
type: "organization",
|
||||
id: "test-organization",
|
||||
},
|
||||
properties: {
|
||||
test: "test",
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user