Skip to content

Commit

Permalink
tryfix ci test unitaire
Browse files Browse the repository at this point in the history
  • Loading branch information
Shamzic committed Dec 4, 2023
1 parent 91cba61 commit dd14c9a
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions tests/unit/lib/state/messaging/messaging-sms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
filterInitialSurveySms,
} from "@backend/lib/messaging/sending.js"
import dayjs from "dayjs"
import utc from "dayjs/plugin/utc"
dayjs.extend(utc)

describe("shouldSendSurveyBySms condition tests", () => {
let followup
Expand Down Expand Up @@ -84,10 +86,13 @@ describe("shouldSendSurveyBySms condition tests", () => {
})

describe("filterInitialSurveySms tests", () => {
it("should filter followup with the correct condition for sending initial survey", async () => {
const limit = 10
let mockFollowups
const limit = 10

beforeEach(() => {
jest.useFakeTimers().setSystemTime(new Date("2023-11-25"))
const mockFollowups = [

mockFollowups = [
{
// should not be included because it has already a sms survey
_id: "mock-0",
Expand All @@ -110,7 +115,7 @@ describe("filterInitialSurveySms tests", () => {
surveys: [
{
type: "track-click-on-simulation-usefulness-email",
createdAt: dayjs("2023-11-22").toDate(),
createdAt: dayjs("2023-11-21").toDate(),
answers: [],
},
],
Expand Down Expand Up @@ -148,18 +153,40 @@ describe("filterInitialSurveySms tests", () => {
sentAt: dayjs("2023-11-17").toDate(),
},
]
})

const result = await filterInitialSurveySms(mockFollowups, limit)
afterEach(() => {
jest.useRealTimers()
})

it("should not include followup with sms survey", async () => {
const result = await filterInitialSurveySms([mockFollowups[0]], limit)
expect(result).not.toContainEqual(
expect.objectContaining({ _id: "mock-0" })
)
})

it("should include followup with no sms survey and has a phone and respects the email delay", async () => {
const result = await filterInitialSurveySms([mockFollowups[1]], limit)
expect(result).toContainEqual(expect.objectContaining({ _id: "mock-1" }))
})

it("should not include followup with no sms survey and has a phone but does not respect the email delay", async () => {
const result = await filterInitialSurveySms([mockFollowups[2]], limit)
expect(result).not.toContainEqual(
expect.objectContaining({ _id: "mock-2" })
)
})

it("should not include followup without a phone", async () => {
const result = await filterInitialSurveySms([mockFollowups[3]], limit)
expect(result).not.toContainEqual(
expect.objectContaining({ _id: "mock-3" })
)
})

it("should include followup with a phone, no sms survey, and no email", async () => {
const result = await filterInitialSurveySms([mockFollowups[4]], limit)
expect(result).toContainEqual(expect.objectContaining({ _id: "mock-4" }))
expect(result).toHaveLength(2)
jest.useRealTimers()
})
})

0 comments on commit dd14c9a

Please sign in to comment.