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 'lp_fix_convo_link' into lp_zapier
- Loading branch information
Showing
60 changed files
with
2,849 additions
and
1,751 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,13 @@ describe("UserMenu", () => { | |
id: 1, | ||
displayName: "TestName", | ||
email: "[email protected]", | ||
organizations: [ | ||
superVolOrganizations: [ | ||
{ | ||
id: 2, | ||
name: "testOrg" | ||
} | ||
], | ||
texterOrganizations: [ | ||
{ | ||
id: 2, | ||
name: "testOrg" | ||
|
@@ -46,7 +52,8 @@ describe("UserMenu", () => { | |
id: 1, | ||
displayName: "TestName", | ||
email: "[email protected]", | ||
organizations: [ | ||
superVolOrganizations: [], | ||
texterOrganizations: [ | ||
{ | ||
id: 2, | ||
name: "testOrg" | ||
|
177 changes: 177 additions & 0 deletions
177
__test__/integrations/message-handlers/profanity-tagger.test.js
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,177 @@ | ||
import { r, cacheableData } from "../../../src/server/models"; | ||
import { | ||
postMessageSave, | ||
available, | ||
DEFAULT_PROFANITY_REGEX_BASE64 | ||
} from "../../../src/integrations/message-handlers/profanity-tagger"; | ||
|
||
import { | ||
setupTest, | ||
cleanupTest, | ||
createStartedCampaign, | ||
sendMessage | ||
} from "../../test_helpers"; | ||
|
||
beforeEach(async () => { | ||
// Set up an entire working campaign | ||
await setupTest(); | ||
global.MESSAGE_HANDLERS = "profanity-tagger"; | ||
}, global.DATABASE_SETUP_TEARDOWN_TIMEOUT); | ||
|
||
afterEach(async () => { | ||
await cleanupTest(); | ||
if (r.redis) r.redis.flushdb(); | ||
global.MESSAGE_HANDLERS = undefined; | ||
}, global.DATABASE_SETUP_TEARDOWN_TIMEOUT); | ||
|
||
describe("Message Hanlder: profanity-tagger", () => { | ||
it("default regex works", () => { | ||
const re = new RegExp( | ||
Buffer.from(DEFAULT_PROFANITY_REGEX_BASE64, "base64").toString(), | ||
"i" | ||
); | ||
expect(re.test("blah blah fakeslur blah blah")).toBe(true); | ||
expect("brass shoe eddie homonym Saturday".match(re)).toBe(null); | ||
}); | ||
|
||
it("Contact profanity is flagged", async () => { | ||
// SETUP | ||
const c = await createStartedCampaign(); | ||
await r.knex("tag").insert([ | ||
{ | ||
name: "Contact Profanity", | ||
description: "mean contact", | ||
organization_id: c.organizationId | ||
}, | ||
{ | ||
name: "Texter language flag", | ||
description: "texter inappropriate", | ||
organization_id: c.organizationId | ||
} | ||
]); | ||
await r | ||
.knex("organization") | ||
.update( | ||
"features", | ||
'{"EXPERIMENTAL_TAGS": "1", "PROFANITY_CONTACT_TAG_ID": "1", "PROFANITY_TEXTER_TAG_ID": "2", "PROFANITY_TEXTER_SUSPEND_COUNT": "1"}' | ||
); | ||
await cacheableData.organization.clear(c.organizationId); | ||
const org = await cacheableData.organization.load(c.organizationId); | ||
await sendMessage(c.testContacts[1].id, c.testTexterUser, { | ||
userId: c.testTexterUser.id, | ||
contactNumber: c.testContacts[1].cell, | ||
text: "brass shoe eddie homonym", | ||
assignmentId: c.assignmentId | ||
}); | ||
// a little stupidly updating messageservice_sid is necessary | ||
// because it's not await'd | ||
await r | ||
.knex("message") | ||
.where("user_id", c.testTexterUser.id) | ||
.update("messageservice_sid", "fakeservice"); | ||
await cacheableData.message.save({ | ||
contact: c.testContacts[1], | ||
messageInstance: { | ||
is_from_contact: true, | ||
text: "go to fakeslur!", | ||
contact_number: c.testContacts[1].cell, | ||
service: "fakeservice", | ||
messageservice_sid: "fakeservice", | ||
send_status: "DELIVERED" | ||
} | ||
}); | ||
|
||
const text1 = await r | ||
.knex("tag_campaign_contact") | ||
.select("tag_id", "campaign_contact_id"); | ||
expect(text1).toEqual([{ tag_id: 1, campaign_contact_id: 2 }]); | ||
const user = await cacheableData.user.userHasRole( | ||
c.testTexterUser, | ||
c.organizationId, | ||
"TEXTER" | ||
); | ||
expect(user).toBe(true); | ||
}); | ||
|
||
it("Texter profanity is flagged", async () => { | ||
// SETUP | ||
const c = await createStartedCampaign(); | ||
await r.knex("tag").insert([ | ||
{ | ||
name: "Contact Profanity", | ||
description: "mean contact", | ||
organization_id: c.organizationId | ||
}, | ||
{ | ||
name: "Texter language flag", | ||
description: "texter inappropriate", | ||
organization_id: c.organizationId | ||
} | ||
]); | ||
await r | ||
.knex("organization") | ||
.update( | ||
"features", | ||
'{"EXPERIMENTAL_TAGS": "1", "PROFANITY_CONTACT_TAG_ID": "1", "PROFANITY_TEXTER_TAG_ID": "2", "PROFANITY_TEXTER_SUSPEND_COUNT": "2"}' | ||
); | ||
await cacheableData.organization.clear(c.organizationId); | ||
const org = await cacheableData.organization.load(c.organizationId); | ||
|
||
// Confirm Available | ||
expect(available(org)).toBeTruthy(); | ||
|
||
// Confirm texter catch | ||
await sendMessage(c.testContacts[0].id, c.testTexterUser, { | ||
userId: c.testTexterUser.id, | ||
contactNumber: c.testContacts[0].cell, | ||
text: "Some fakeslur message", | ||
assignmentId: c.assignmentId | ||
}); | ||
const text1 = await r | ||
.knex("tag_campaign_contact") | ||
.select("tag_id", "campaign_contact_id") | ||
.where("campaign_contact_id", 1); | ||
expect(text1).toEqual([{ tag_id: 2, campaign_contact_id: 1 }]); | ||
|
||
let user = await cacheableData.user.userHasRole( | ||
c.testTexterUser, | ||
c.organizationId, | ||
"TEXTER" | ||
); | ||
expect(user).toBe(true); | ||
|
||
// Confirm texter no-match | ||
await sendMessage(c.testContacts[1].id, c.testTexterUser, { | ||
userId: c.testTexterUser.id, | ||
contactNumber: c.testContacts[1].cell, | ||
text: "brass shoe eddie homonym", | ||
assignmentId: c.assignmentId | ||
}); | ||
const text2 = await r | ||
.knex("tag_campaign_contact") | ||
.select("tag_id", "campaign_contact_id") | ||
.where("campaign_contact_id", 2); | ||
expect(text2).toEqual([]); | ||
|
||
user = await cacheableData.user.userHasRole( | ||
c.testTexterUser, | ||
c.organizationId, | ||
"TEXTER" | ||
); | ||
expect(user).toBe(true); | ||
|
||
// Confirm texter no-match | ||
await sendMessage(c.testContacts[1].id, c.testTexterUser, { | ||
userId: c.testTexterUser.id, | ||
contactNumber: c.testContacts[1].cell, | ||
text: "fakeslur is one too many slurs", | ||
assignmentId: c.assignmentId | ||
}); | ||
user = await cacheableData.user.userHasRole( | ||
c.testTexterUser, | ||
c.organizationId, | ||
"TEXTER" | ||
); | ||
expect(user).toBe(false); | ||
}); | ||
}); |
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
Oops, something went wrong.