Skip to content

Commit

Permalink
Merge bacb41b into 8e1928e
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Apr 4, 2023
2 parents 8e1928e + bacb41b commit 786459a
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Array [
]
`;

exports[`should submit article if user agrees to submit 1`] = `
exports[`should submit article if user agrees to submit: has AI reply 1`] = `
Object {
"data": Object {
"foundArticleIds": Array [],
Expand Down Expand Up @@ -325,6 +325,162 @@ Object {
}
`;

exports[`should submit article if user agrees to submit: has no AI reply 1`] = `
Object {
"data": Object {
"foundArticleIds": Array [],
"searchedText": "Some text forwarded by the user",
"sessionId": 1577923200000,
},
"event": Object {
"input": "__POSTBACK_YES__",
"type": "postback",
},
"replies": Array [
Object {
"altText": "The message has now been recorded at Cofacts for volunteers to fact-check. Thank you for submitting!",
"contents": Object {
"body": Object {
"contents": Array [
Object {
"text": "The message has now been recorded at Cofacts for volunteers to fact-check. Thank you for submitting!",
"type": "text",
"wrap": true,
},
Object {
"action": Object {
"label": "View reported message",
"type": "uri",
"uri": "https://dev.cofacts.tw/article/new-article-id-2",
},
"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": "Your submission is now recorded at https://dev.cofacts.tw/article/new-article-id-2",
"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=new-article-id-2",
},
"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%2Fnew-article-id-2",
},
"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%2Fnew-article-id-2",
},
"color": "#ffb600",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"type": "bubble",
},
],
"type": "carousel",
},
"type": "flex",
},
],
"userId": "userId",
}
`;

exports[`should submit image article if user agrees to submit 1`] = `
Object {
"data": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,7 @@ Object {
}
`;

exports[`should select article with no replies 1`] = `
exports[`should select article with no replies: has AI reply 1`] = `
Object {
"data": Object {
"searchedText": "老司機車裡總備一塊香皂,知道內情的新手默默也準備了一塊",
Expand Down Expand Up @@ -1924,3 +1924,164 @@ Don’t trust the message just yet!",
"userId": "Uc76d8ae9ccd1ada4f06c4e1515d46466",
}
`;

exports[`should select article with no replies: has no AI reply 1`] = `
Object {
"data": Object {
"searchedText": "老司機車裡總備一塊香皂,知道內情的新手默默也準備了一塊",
"selectedArticleId": "article-id",
"selectedArticleText": "老司機車裡總備一塊香皂,知道內情的新手默默也準備了一塊",
},
"event": Object {
"input": "article-id",
"postback": Object {
"data": "{\\"input\\":\\"article-id\\",\\"sessionId\\":1497994017447,\\"state\\":\\"CHOOSING_ARTICLE\\"}",
},
"timestamp": 1519019734813,
"type": "postback",
},
"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": "此訊息已經被收錄至 Cofacts 有待好心人來查證。",
"type": "text",
"wrap": true,
},
Object {
"action": Object {
"label": "View reported message",
"type": "uri",
"uri": "https://dev.cofacts.tw/article/article-id",
},
"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=article-id",
},
"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%2Farticle-id",
},
"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%2Farticle-id",
},
"color": "#ffb600",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"type": "bubble",
},
],
"type": "carousel",
},
"type": "flex",
},
],
"userId": "Uc76d8ae9ccd1ada4f06c4e1515d46466",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ it('should submit article if user agrees to submit', async () => {

MockDate.set('2020-01-02');
gql.__push({ data: { CreateArticle: { id: 'new-article-id' } } });
// The case when have AI replies
gql.__push({ data: { CreateAIReply: { text: 'Hello from ChatGPT' } } });
const result = await askingArticleSubmissionConsent(params);
MockDate.reset();
expect(gql.__finished()).toBe(true);

expect(result).toMatchSnapshot();
expect(result).toMatchSnapshot('has AI reply');
expect(result.data.sessionId).not.toEqual(inputSession);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Expand All @@ -112,6 +113,17 @@ it('should submit article if user agrees to submit', async () => {
]
`);
expect(ga.sendMock).toHaveBeenCalledTimes(1);

// The case when no AI reply is provided (such as in the case of insufficient data)
//
MockDate.set('2020-01-02');
gql.__push({ data: { CreateArticle: { id: 'new-article-id-2' } } });
gql.__push({ data: { CreateAIReply: null } });
expect(await askingArticleSubmissionConsent(params)).toMatchSnapshot(
'has no AI reply'
);
MockDate.reset();
expect(gql.__finished()).toBe(true);
});

it('should submit image article if user agrees to submit', async () => {
Expand Down

0 comments on commit 786459a

Please sign in to comment.