Skip to content

Commit

Permalink
[choosingReply] unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Jun 24, 2022
1 parent 67d79bb commit 7b524dc
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 38 deletions.
160 changes: 126 additions & 34 deletions src/webhook/handlers/__tests__/__snapshots__/choosingReply.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,26 @@ https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz",
"contents": Array [
Object {
"action": Object {
"label": "Yes",
"label": "👍 Yes",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback/yes&token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVYWRkYzc0ZGY4YTNhMTc2YjkwMWQ5ZDY0OGIwZmM0ZmUiLCJleHAiOjE1Nzc5MjMyMDB9.rVpljRKoxb65cvss9Rtuup-N9vF0y2n46pQ9SXNRufw",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=AWDZYXxAyCdS-nWhumlz&replyId=AWDZeeV0yCdS-nWhuml8&vote=UPVOTE",
},
"color": "#ffb600",
"color": "#00B172",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"label": "No",
"label": "😕 No",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback/no&token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVYWRkYzc0ZGY4YTNhMTc2YjkwMWQ5ZDY0OGIwZmM0ZmUiLCJleHAiOjE1Nzc5MjMyMDB9.rVpljRKoxb65cvss9Rtuup-N9vF0y2n46pQ9SXNRufw",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=AWDZYXxAyCdS-nWhumlz&replyId=AWDZeeV0yCdS-nWhuml8&vote=DOWNVOTE",
},
"color": "#ffb600",
"color": "#FB5959",
"style": "primary",
"type": "button",
},
],
"layout": "horizontal",
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
Expand All @@ -74,41 +74,41 @@ https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz",
"body": Object {
"contents": Array [
Object {
"text": "You can turn on notifications if you want Cofacts to notify you when someone replies to this message.",
"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": "Go to settings",
"label": "Share to friends",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=setting&utm_source=rumors-line-bot&utm_medium=reply-request",
"uri": "https://line.me/R/msg/text/?Someone%20says%20the%20message%20%E2%80%9C(0)(1)(/)(0)(%E2%8B%AF%E2%8B%AF%E2%80%9D%20invalid%20request.%0A%0APlease%20refer%20to%20https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz%20for%20more%20information,%20replies%20and%20references.",
},
"color": "#00B172",
"color": "#ffb600",
"style": "primary",
"type": "button",
},
],
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
"header": Object {
"contents": Array [
Object {
"text": "🔔 Receive updates",
"type": "text",
"wrap": true,
"action": Object {
"label": "Provide better reply",
"type": "uri",
"uri": "https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz",
},
"color": "#ffb600",
"style": "link",
"type": "button",
},
],
"layout": "vertical",
"paddingBottom": "none",
"spacing": "sm",
"type": "box",
},
"type": "bubble",
Expand All @@ -126,6 +126,9 @@ Object {
"data": Object {
"searchedText": "貼圖",
"selectedArticleId": "AWDZYXxAyCdS-nWhumlz",
"selectedArticleText": "(0)(1)(/)(0)(9)(line)免費貼
「[全螢幕貼圖]生活市集x生活小黑熊」
https://line.me/S/sticker/",
"selectedReplyId": "AWDZeeV0yCdS-nWhuml8",
},
"event": Object {
Expand Down Expand Up @@ -182,26 +185,69 @@ https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz",
"contents": Array [
Object {
"action": Object {
"label": "Yes",
"label": "👍 Yes",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback/yes&token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVYWRkYzc0ZGY4YTNhMTc2YjkwMWQ5ZDY0OGIwZmM0ZmUiLCJleHAiOjE1Nzc5MjMyMDB9.rVpljRKoxb65cvss9Rtuup-N9vF0y2n46pQ9SXNRufw",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=AWDZYXxAyCdS-nWhumlz&replyId=AWDZeeV0yCdS-nWhuml8&vote=UPVOTE",
},
"color": "#ffb600",
"color": "#00B172",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"label": "😕 No",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=AWDZYXxAyCdS-nWhumlz&replyId=AWDZeeV0yCdS-nWhuml8&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": "No",
"label": "Share to friends",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback/no&token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVYWRkYzc0ZGY4YTNhMTc2YjkwMWQ5ZDY0OGIwZmM0ZmUiLCJleHAiOjE1Nzc5MjMyMDB9.rVpljRKoxb65cvss9Rtuup-N9vF0y2n46pQ9SXNRufw",
"uri": "https://line.me/R/msg/text/?Someone%20says%20the%20message%20%E2%80%9C(0)(1)(/)(0)(%E2%8B%AF%E2%8B%AF%E2%80%9D%20invalid%20request.%0A%0APlease%20refer%20to%20https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz%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/AWDZYXxAyCdS-nWhumlz",
},
"color": "#ffb600",
"style": "link",
"type": "button",
},
],
"layout": "horizontal",
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
Expand All @@ -222,6 +268,9 @@ Object {
"data": Object {
"searchedText": "貼圖",
"selectedArticleId": "AWDZYXxAyCdS-nWhumlz",
"selectedArticleText": "(0)(1)(/)(0)(9)(line)免費貼
「[全螢幕貼圖]生活市集x生活小黑熊」
https://line.me/S/sticker/",
"selectedReplyId": "AWDZeeV0yCdS-nWhuml8",
},
"event": Object {
Expand Down Expand Up @@ -280,26 +329,69 @@ https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz",
"contents": Array [
Object {
"action": Object {
"label": "Yes",
"label": "👍 Yes",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback/yes&token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVYWRkYzc0ZGY4YTNhMTc2YjkwMWQ5ZDY0OGIwZmM0ZmUiLCJleHAiOjE1Nzc5MjMyMDB9.rVpljRKoxb65cvss9Rtuup-N9vF0y2n46pQ9SXNRufw",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=AWDZYXxAyCdS-nWhumlz&replyId=AWDZeeV0yCdS-nWhuml8&vote=UPVOTE",
},
"color": "#ffb600",
"color": "#00B172",
"style": "primary",
"type": "button",
},
Object {
"action": Object {
"label": "No",
"label": "😕 No",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW?p=feedback&articleId=AWDZYXxAyCdS-nWhumlz&replyId=AWDZeeV0yCdS-nWhuml8&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://liff.line.me/1563196602-X6mLdDkW?p=feedback/no&token=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVYWRkYzc0ZGY4YTNhMTc2YjkwMWQ5ZDY0OGIwZmM0ZmUiLCJleHAiOjE1Nzc5MjMyMDB9.rVpljRKoxb65cvss9Rtuup-N9vF0y2n46pQ9SXNRufw",
"uri": "https://line.me/R/msg/text/?Someone%20says%20the%20message%20%E2%80%9C(0)(1)(/)(0)(%E2%8B%AF%E2%8B%AF%E2%80%9D%20invalid%20request.%0A%0APlease%20refer%20to%20https://dev.cofacts.tw/article/AWDZYXxAyCdS-nWhumlz%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/AWDZYXxAyCdS-nWhumlz",
},
"color": "#ffb600",
"style": "link",
"type": "button",
},
],
"layout": "horizontal",
"layout": "vertical",
"spacing": "sm",
"type": "box",
},
Expand Down
4 changes: 2 additions & 2 deletions src/webhook/handlers/__tests__/choosingReply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ afterAll(async () => {
await (await Client.getInstance()).close();
});

// Note: all commented to make unit test pass on other PRs.

describe('should select reply by replyId', () => {
const params = {
data: {
searchedText: '貼圖',
selectedArticleId: 'AWDZYXxAyCdS-nWhumlz',
selectedArticleText:
'(0)(1)(/)(0)(9)(line)免費貼圖\n「[全螢幕貼圖]生活市集x生活小黑熊」\n https://line.me/S/sticker/',
},
event: {
type: 'postback',
Expand Down
3 changes: 1 addition & 2 deletions src/webhook/handlers/choosingReply.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export default async function choosingReply(params) {
}
GetArticle(id: $articleId) {
replyCount
text
}
}
`({ id: selectedReplyId, articleId: data.selectedArticleId });
Expand Down Expand Up @@ -172,7 +171,7 @@ export default async function choosingReply(params) {

createShareBubble(
data.selectedArticleId,
GetArticle.text,
data.selectedArticleText,
GetReply.type
),
].filter(m => m),
Expand Down

0 comments on commit 7b524dc

Please sign in to comment.