Skip to content

Commit

Permalink
Update test, add messageId to test input and fix rebase conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
nonumpa committed Aug 20, 2022
1 parent 15befe2 commit c55b1a8
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/webhook/handlers/__tests__/__snapshots__/processImage.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,109 @@ Please choose the version that looks the most similar👇",

exports[`one identical article found 1`] = `"__HANDLE_POSTBACK_RESULT__"`;

exports[`should handle image not found 1`] = `
Object {
"context": Object {
"data": Object {
"messageId": "6530038889933",
"searchedText": "",
"sessionId": 1577836800000,
},
},
"replies": Array [
Object {
"altText": "I am sorry you cannot find the information you are looking for.
Do you want someone to fact-check this message?",
"contents": Object {
"body": Object {
"contents": Array [
Object {
"text": "I am sorry you cannot find the information you are looking for.
Do you want someone to fact-check this message?",
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"type": "box",
},
"type": "bubble",
},
"type": "flex",
},
Object {
"altText": "Be the first to report the message",
"contents": Object {
"body": Object {
"contents": Array [
Object {
"contents": Array [
Object {
"text": "Currently we don’t have this message in our database. If you think it is most likely a rumor, ",
"type": "span",
},
Object {
"color": "#ffb600",
"text": "press “🆕 Report to database” to make this message public on Cofacts database ",
"type": "span",
"weight": "bold",
},
Object {
"text": "and have volunteers fact-check it. This way you can help the people who receive the same message in the future.",
"type": "span",
},
],
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"paddingAll": "lg",
"spacing": "md",
"type": "box",
},
"footer": Object {
"contents": Array [
Object {
"action": Object {
"data": "{\\"input\\":\\"__POSTBACK_YES__\\",\\"sessionId\\":1577836800000,\\"state\\":\\"ASKING_ARTICLE_SUBMISSION_CONSENT\\"}",
"displayText": "🆕 Report to database",
"label": "🆕 Report to database",
"type": "postback",
},
"color": "#ffb600",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"data": "{\\"input\\":\\"__POSTBACK_NO__\\",\\"sessionId\\":1577836800000,\\"state\\":\\"ASKING_ARTICLE_SUBMISSION_CONSENT\\"}",
"displayText": "Don’t report",
"label": "Don’t report",
"type": "postback",
},
"color": "#333333",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"styles": Object {
"body": Object {
"separator": true,
},
},
"type": "bubble",
},
"type": "flex",
},
],
}
`;

exports[`twelve articles found 1`] = `
Object {
"context": Object {
Expand Down
43 changes: 43 additions & 0 deletions src/webhook/handlers/__tests__/processImage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ it('one identical article found', async () => {
const event = {
type: 'message',
timestamp: 1497994016356,
messageId: '6270464463537',
message: {
type: 'image',
id: '6270464463537',
Expand Down Expand Up @@ -75,6 +76,7 @@ it('one article found (not identical)', async () => {
const event = {
type: 'message',
timestamp: 1497994016356,
messageId: '6270464463537',
message: {
type: 'image',
id: '6270464463537',
Expand Down Expand Up @@ -123,6 +125,7 @@ it('twelve articles found', async () => {
const event = {
type: 'message',
timestamp: 1497994016356,
messageId: '6530038889933',
message: {
type: 'image',
id: '6530038889933',
Expand All @@ -141,3 +144,43 @@ it('twelve articles found', async () => {
expect(carousel.contents.length).toBeLessThanOrEqual(10); // Flex message carousel 10 bubble limit
expect(JSON.stringify(carousel).length).toBeLessThan(50 * 1000); // Flex message carousel 50K limit
});

it('should handle image not found', async () => {
gql.__push(apiResult.notFound);
const data = {
sessionId: 1497994017447,
};
const event = {
type: 'message',
timestamp: 1497994016356,
messageId: '6530038889933',
message: {
type: 'image',
id: '6530038889933',
},
};
const userId = 'Uc76d8ae9ccd1ada4f06c4e1515d46466';
MockDate.set('2020-01-01');
expect(await processImage(data, event, userId)).toMatchSnapshot();
MockDate.reset();
expect(gql.__finished()).toBe(true);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "MessageType",
"ec": "UserInput",
"el": "image",
},
],
Array [
Object {
"ea": "ArticleSearch",
"ec": "UserInput",
"el": "ArticleNotFound",
},
],
]
`);
expect(ga.sendMock).toHaveBeenCalledTimes(1);
});

0 comments on commit c55b1a8

Please sign in to comment.