diff --git a/src/webhook/handlers/__tests__/__snapshots__/processImage.test.js.snap b/src/webhook/handlers/__tests__/__snapshots__/processImage.test.js.snap index 8738f202..2930361c 100644 --- a/src/webhook/handlers/__tests__/__snapshots__/processImage.test.js.snap +++ b/src/webhook/handlers/__tests__/__snapshots__/processImage.test.js.snap @@ -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 { diff --git a/src/webhook/handlers/__tests__/processImage.test.js b/src/webhook/handlers/__tests__/processImage.test.js index 3fd5d258..f4e1231a 100644 --- a/src/webhook/handlers/__tests__/processImage.test.js +++ b/src/webhook/handlers/__tests__/processImage.test.js @@ -27,6 +27,7 @@ it('one identical article found', async () => { const event = { type: 'message', timestamp: 1497994016356, + messageId: '6270464463537', message: { type: 'image', id: '6270464463537', @@ -75,6 +76,7 @@ it('one article found (not identical)', async () => { const event = { type: 'message', timestamp: 1497994016356, + messageId: '6270464463537', message: { type: 'image', id: '6270464463537', @@ -123,6 +125,7 @@ it('twelve articles found', async () => { const event = { type: 'message', timestamp: 1497994016356, + messageId: '6530038889933', message: { type: 'image', id: '6530038889933', @@ -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); +});