Skip to content

Commit

Permalink
Merge pull request #324 from cofacts/issue/232-reply-expire
Browse files Browse the repository at this point in the history
Fix issue choosing reply button expire
  • Loading branch information
MrOrz authored Sep 21, 2022
2 parents 9267b1f + 71b69a7 commit 5dbdb74
Show file tree
Hide file tree
Showing 13 changed files with 672 additions and 93 deletions.
8 changes: 8 additions & 0 deletions scripts/setup-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ const path = require('path');
require('dotenv').config({
path: path.resolve(process.cwd(), '.env.sample'),
});

// Must import Client after dotenv, so that MONGODB_URI in mongoClient file can get correct value
const { default: Client } = require('../src/database/mongoClient');

afterAll(async () => {
// Close MongoDB connection after each test
await (await Client.getInstance()).close();
});
41 changes: 41 additions & 0 deletions src/webhook/handlers/__fixtures__/choosingArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,47 @@ export const noReplies = {
},
};

export const shortArticle = {
data: {
GetArticle: {
text: 'YouTube · 寻找健康人生',
replyCount: 0,
articleReplies: [],
},
},
};

export const oneImageArticle = {
data: {
GetArticle: {
text: '',
replyCount: 2,
articleReplies: [
{
reply: {
id: 'AVygFA0RyCdS-nWhuaXY',
type: 'RUMOR',
text:
'查證這則謠言的過程中,約翰走鹿也發現其實網路早就有許多解答,就讓約翰走鹿來借花獻佛一下囉。多家媒體都有針對這則「吃生魚片會有海獸胃腺蟲附著胃壁」的謠言請教醫師,受訪的醫師們皆表示,這則謠言太誇大,海獸胃腺蟲沒那麼神通廣大。\n醫師們表示,台灣的衛生條件很進步,吃生魚片被寄生蟲寄生的案例很少,大部份都是生魚片不乾淨,感染沙門氏菌、大腸桿菌的案例,此外,寄生蟲也不是什麼難治之症,服用一些抗寄生蟲藥就可以殺死胃裡的這些蟲子,除非這些蟲子跑到身體其他部位那才比較難處理,但那也是要大量地吃生魚片(一週兩次以上),中獎機率才會比較高。',
},
positiveFeedbackCount: 14,
negativeFeedbackCount: 2,
},
{
reply: {
id: 'AVy6LkWIyCdS-nWhuaqu',
type: 'RUMOR',
text:
'過去台灣只有一個海獸胃腺蟲鑽入胃壁的病例,而且僅有一隻蟲。而經查詢,台北馬偕醫院也沒有名為林清風的醫師。',
},
positiveFeedbackCount: 24,
negativeFeedbackCount: 0,
},
],
},
},
};

export const createOrUpdateReplyRequest = {
data: { CreateOrUpdateReplyRequest: { replyRequestCount: 1 } },
};
15 changes: 15 additions & 0 deletions src/webhook/handlers/__fixtures__/choosingReply.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ export const oneReply = {
},
};

export const oneReply2 = {
data: {
GetReply: {
type: 'RUMOR',
text:
'The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply ',
reference: '',
createdAt: '2018-01-09T05:52:12.658Z',
},
GetArticle: {
replyCount: 1,
},
},
};

export const multipleReplies = {
data: {
GetReply: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,141 @@ Array [
]
`;

exports[`should select article and choose the only one reply for user 1`] = `
Object {
"data": Object {
"searchedText": "Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply",
"selectedArticleId": "article-id",
"selectedArticleText": "Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply Just One Reply ",
"selectedReplyId": "AV--O3nfyCdS-nWhujMD",
},
"event": Object {
"input": "AV--O3nfyCdS-nWhujMD",
"type": "server_choose",
},
"issuedAt": undefined,
"replies": Array [
Object {
"text": "💡 Someone on the internet replies to the message:",
"type": "text",
},
Object {
"text": "The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply The Only Reply ",
"type": "text",
},
Object {
"text": "􀂅 ⚠️️ This reply has no references and it may be biased ⚠️️ 􀂅",
"type": "text",
},
Object {
"text": "⬆️ Therefore, the author think the message contains misinformation.
💁 This content is provided by Cofact message reporting chatbot and crowd-sourced fact-checking community under CC BY-SA 4.0 license. Please refer to their references and make judgements on your own.
⁉️ If you have different thoughts, you may have your say here:
https://dev.cofacts.tw/article/article-id",
"type": "text",
},
Object {
"altText": "Is the reply helpful?",
"contents": Object {
"contents": Array [
Object {
"body": Object {
"contents": Array [
Object {
"text": "Is the reply helpful?",
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"paddingAll": "xl",
"type": "box",
},
"footer": Object {
"contents": Array [
Object {
"action": Object {
"label": "👍 Yes",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=article-id&replyId=AV--O3nfyCdS-nWhujMD&vote=UPVOTE",
},
"color": "#00B172",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"label": "😕 No",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=article-id&replyId=AV--O3nfyCdS-nWhujMD&vote=DOWNVOTE",
},
"color": "#FB5959",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"type": "bubble",
},
Object {
"body": Object {
"contents": Array [
Object {
"text": "Don't forget to forward the messages above to others and share with them!",
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"paddingAll": "lg",
"spacing": "md",
"type": "box",
},
"footer": Object {
"contents": Array [
Object {
"action": Object {
"label": "Share to friends",
"type": "uri",
"uri": "https://line.me/R/msg/text/?Someone%20says%20the%20message%20%E2%80%9CJust%20One%20Repl%E2%8B%AF%E2%8B%AF%E2%80%9D%20contains%20misinformation.%0A%0APlease%20refer%20to%20https://dev.cofacts.tw/article/article-id%20for%20more%20information,%20replies%20and%20references.",
},
"color": "#ffb600",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"label": "Provide better reply",
"type": "uri",
"uri": "https://dev.cofacts.tw/article/article-id",
},
"color": "#ffb600",
"style": "link",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"type": "bubble",
},
],
"type": "carousel",
},
"type": "flex",
},
],
"userId": "Uc76d8ae9ccd1ada4f06c4e1515d46466",
}
`;

exports[`should select article and have OPINIONATED and NOT_ARTICLE replies 1`] = `
Object {
"data": Object {
Expand Down
159 changes: 159 additions & 0 deletions src/webhook/handlers/__tests__/__snapshots__/initState.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,165 @@ Object {
}
`;

exports[`only one article found with high similarity and choose for user 1`] = `
Object {
"data": Object {
"searchedText": "YouTube · 寻找健康人生",
"selectedArticleId": "AVvY-yizyCdS-nWhuYWx",
"selectedArticleText": "YouTube · 寻找健康人生",
"sessionId": 1497994017447,
},
"event": Object {
"input": "AVvY-yizyCdS-nWhuYWx",
"type": "server_choose",
},
"replies": Array [
Object {
"altText": "This message has already published on Cofacts, and will soon be fact-checked by volunteers.
Dont trust the message just yet!",
"contents": Object {
"body": Object {
"contents": Array [
Object {
"text": "This message has already published on Cofacts, and will soon be fact-checked by volunteers.
Dont trust the message just yet!",
"type": "text",
"wrap": true,
},
Object {
"action": Object {
"label": "View reported message",
"type": "uri",
"uri": "https://dev.cofacts.tw/article/AVvY-yizyCdS-nWhuYWx",
},
"margin": "md",
"type": "button",
},
],
"layout": "vertical",
"type": "box",
},
"type": "bubble",
},
"type": "flex",
},
Object {
"altText": "In the meantime, you can:",
"contents": Object {
"body": Object {
"contents": Array [
Object {
"text": "In the meantime, you can:",
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"type": "box",
},
"type": "bubble",
},
"type": "flex",
},
Object {
"altText": "Provide more detail",
"contents": Object {
"contents": Array [
Object {
"body": Object {
"contents": Array [
Object {
"text": "It would help fact checkers a lot if you provide more detail :)",
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"type": "box",
},
"footer": Object {
"contents": Array [
Object {
"action": Object {
"label": "Provide detail",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=comment&articleId=AVvY-yizyCdS-nWhuYWx",
},
"color": "#00B172",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"header": Object {
"contents": Array [
Object {
"color": "#00B172",
"size": "lg",
"text": "Provide more detail",
"type": "text",
},
],
"layout": "vertical",
"paddingBottom": "none",
"type": "box",
},
"type": "bubble",
},
Object {
"body": Object {
"contents": Array [
Object {
"text": "We all get by with a little help from our friends 🌟 Share your question to friends, someone might be able to help!",
"type": "text",
"wrap": true,
},
],
"layout": "vertical",
"type": "box",
},
"footer": Object {
"contents": Array [
Object {
"action": Object {
"label": "Share on LINE",
"type": "uri",
"uri": "line://msg/text/?Please%20help%20me%20verify%20if%20this%20is%20true%3A%20https%3A%2F%2Fdev.cofacts.tw%2Farticle%2FAVvY-yizyCdS-nWhuYWx",
},
"color": "#ffb600",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"label": "Share on Facebook",
"type": "uri",
"uri": "https://www.facebook.com/dialog/share?openExternalBrowser=1&app_id=719656818195367&display=popup&hashtag=%23ReportedToCofacts&href=https%3A%2F%2Fdev.cofacts.tw%2Farticle%2FAVvY-yizyCdS-nWhuYWx",
},
"color": "#ffb600",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"type": "bubble",
},
],
"type": "carousel",
},
"type": "flex",
},
],
"userId": "Uc76d8ae9ccd1ada4f06c4e1515d46466",
}
`;

exports[`should handle message matches only hyperlinks 1`] = `
Object {
"data": Object {
Expand Down
Loading

0 comments on commit 5dbdb74

Please sign in to comment.