forked from StateVoicesNational/Spoke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'ag/send-auto-opt-out-response' into stage-main-12-2
- Loading branch information
1 parent
07d10d1
commit 7c22825
Showing
5 changed files
with
202 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { postMessageSave } from "../../../src/extensions/message-handlers/auto-optout"; | ||
import { cacheableData } from "../../../src/server/models"; | ||
const sendMessage = require("../../../src/server/api/mutations/sendMessage"); | ||
|
||
describe("Auto Opt-Out Tests", () => { | ||
let message; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
global.SEND_AUTO_OPT_OUT_RESPONSE = false; | ||
global.DEFAULT_SERVICE = "fakeservice"; | ||
|
||
jest.spyOn(cacheableData.optOut, "save").mockResolvedValue(null); | ||
jest.spyOn(cacheableData.campaignContact, "load").mockResolvedValue({ | ||
id: 1, | ||
assignment_id: 2 | ||
}); | ||
jest.spyOn(sendMessage, "sendRawMessage").mockResolvedValue(null); | ||
|
||
message = { | ||
is_from_contact: true, | ||
contact_number: "+123456", | ||
campaign_contact_id: 1, | ||
text: 'please stop' | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
global.SEND_AUTO_OPT_OUT_RESPONSE = false; | ||
global.DEFAULT_SERVICE = "fakeservice"; | ||
}); | ||
|
||
it("Does not send message without env variable", async () => { | ||
await postMessageSave({ | ||
message, | ||
organization: { id: 1 }, | ||
handlerContext: { autoOptOutReason: "stop" } | ||
}); | ||
|
||
expect(cacheableData.optOut.save).toHaveBeenCalled(); | ||
expect(cacheableData.campaignContact.load).toHaveBeenCalled(); | ||
|
||
expect(sendMessage.sendRawMessage).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("Sends message with env variable", async () => { | ||
global.SEND_AUTO_OPT_OUT_RESPONSE = true; | ||
|
||
await postMessageSave({ | ||
message, | ||
organization: { id: 1 }, | ||
handlerContext: { autoOptOutReason: "stop" } | ||
}); | ||
|
||
expect(cacheableData.optOut.save).toHaveBeenCalled(); | ||
expect(cacheableData.campaignContact.load).toHaveBeenCalled(); | ||
|
||
expect(sendMessage.sendRawMessage).toHaveBeenCalled(); | ||
}); | ||
|
||
it("Does not send with twilio opt-out words", async () => { | ||
global.SEND_AUTO_OPT_OUT_RESPONSE = true; | ||
global.DEFAULT_SERVICE = "twilio"; | ||
|
||
message.text = " stopall "; | ||
|
||
await postMessageSave({ | ||
message, | ||
organization: { id: 1 }, | ||
handlerContext: { autoOptOutReason: "stop" } | ||
}); | ||
|
||
expect(cacheableData.optOut.save).toHaveBeenCalled(); | ||
expect(cacheableData.campaignContact.load).toHaveBeenCalled(); | ||
|
||
expect(sendMessage.sendRawMessage).not.toHaveBeenCalled(); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters