Skip to content

Commit

Permalink
Make tests await async methods for analytics events.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy committed Sep 27, 2024
1 parent 7c6f007 commit 6220cd8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/server/utils/analytics/analytics-event.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,71 @@ describe("AnalyticEvents", () => {
})
})
describe("reportProcessingFinished", () => {
it("should not track the event when analytics disabled", function () {
it("should not track the event when analytics disabled", async function () {
process.env.OPT_OUT_ANALYTICS = "true"
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportProcessingFinished()
await AnalyticsEvent.reportProcessingFinished()
expect(trackMock).not.toHaveBeenCalled()

})
it("should track the event only when analytics enabled", function () {
it("should track the event only when analytics enabled", async function () {
process.env.OPT_OUT_ANALYTICS = "false"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 41 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportProcessingFinished()
await AnalyticsEvent.reportProcessingFinished()
expect(trackMock).toHaveBeenCalled()
})
})

describe("reportLabelCount", () => {
it("should not track the event when analytics disabled", function () {
it("should not track the event when analytics disabled", async function () {
process.env.OPT_OUT_ANALYTICS = "true"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 51 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportDetails(1, 1)
await AnalyticsEvent.reportDetails(1, 1)
expect(trackMock).not.toHaveBeenCalled()

})
it("should track the event only when analytics enabled", function () {
it("should track the event only when analytics enabled", async function () {
process.env.OPT_OUT_ANALYTICS = "false"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 59 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportDetails(1, 1)
await AnalyticsEvent.reportDetails(1, 1)
expect(trackMock).toHaveBeenCalled()
})
})

describe("reportProcessingStarted", () => {
it("should not track the event when analytics disabled", function () {
it("should not track the event when analytics disabled", async function () {
process.env.OPT_OUT_ANALYTICS = "true"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 69 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportProcessingStarted()
await AnalyticsEvent.reportProcessingStarted()
expect(trackMock).not.toHaveBeenCalled()

})
it("should track the event only when analytics enabled", function () {
it("should track the event only when analytics enabled", async function () {
process.env.OPT_OUT_ANALYTICS = "false"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 77 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportProcessingStarted()
await AnalyticsEvent.reportProcessingStarted()
expect(trackMock).toHaveBeenCalled()
})
})
describe("unexpectedError", () => {
it("should not track the event when analytics disabled", function () {
it("should not track the event when analytics disabled", async function () {
process.env.OPT_OUT_ANALYTICS = "true"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 86 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportUnexpectedError(Error("test"))
await AnalyticsEvent.reportUnexpectedError(Error("test"))
expect(trackMock).not.toHaveBeenCalled()

})
it("should track the event only when analytics enabled", function () {
it("should track the event only when analytics enabled", async function () {
process.env.OPT_OUT_ANALYTICS = "false"
jest.spyOn(AnalyticsEvent as any, "getInstanceId").mockResolvedValueOnce("mocked-id");

Check failure on line 94 in src/server/utils/analytics/analytics-event.spec.ts

View workflow job for this annotation

GitHub Actions / build

Extra semicolon
const trackMock = (analytics.track as any).mockResolvedValueOnce(undefined)
AnalyticsEvent.reportUnexpectedError(Error("test"))
await AnalyticsEvent.reportUnexpectedError(Error("test"))
expect(trackMock).toHaveBeenCalled()
})
})
Expand Down

0 comments on commit 6220cd8

Please sign in to comment.