Skip to content

Commit

Permalink
Update tutorial ga test
Browse files Browse the repository at this point in the history
  • Loading branch information
nonumpa committed Oct 31, 2020
1 parent b7cacec commit e78fd9b
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 11 deletions.
22 changes: 22 additions & 0 deletions src/webhook/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ jest.mock('src/webhook/checkSignatureAndParse');
jest.mock('src/webhook/lineClient');
jest.mock('src/lib/redisClient');
jest.mock('src/webhook/handlers/tutorial');
jest.mock('src/lib/ga');

import Koa from 'koa';
import request from 'supertest';
Expand All @@ -16,6 +17,7 @@ import {
createGreetingMessage,
createTutorialMessage,
} from 'src/webhook/handlers/tutorial';
import ga from 'src/lib/ga';

const sleep = async ms => new Promise(resolve => setTimeout(resolve, ms));

Expand Down Expand Up @@ -78,6 +80,26 @@ describe('Webhook router', () => {

expect(createGreetingMessage).toHaveBeenCalledTimes(1);
expect(createTutorialMessage).toHaveBeenCalledTimes(1);
expect(ga.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"U4af4980629",
"TUTORIAL",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "ON_BOARDING",
},
],
]
`);
expect(ga.sendMock).toHaveBeenCalledTimes(1);

return new Promise((resolve, reject) => {
server.close(error => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ Object {
"action": Object {
"label": "Setup permission",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW/liff/index.html?p=setting",
"uri": "https://liff.line.me/1563196602-X6mLdDkW/liff/index.html?p=setting&utm_source=rumors-line-bot&utm_medium=tutorial",
},
"color": "#ffb600",
"style": "primary",
Expand Down Expand Up @@ -411,7 +411,7 @@ Object {
"action": Object {
"label": "Setup permission",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW/liff/index.html?p=setting",
"uri": "https://liff.line.me/1563196602-X6mLdDkW/liff/index.html?p=setting&utm_source=rumors-line-bot&utm_medium=tutorial",
},
"color": "#ffb600",
"style": "primary",
Expand Down Expand Up @@ -511,7 +511,7 @@ You can still use Cofacts without granting me this permission. When we ask for f
"action": Object {
"label": "Setup permission",
"type": "uri",
"uri": "https://liff.line.me/1563196602-X6mLdDkW/liff/index.html?p=setting",
"uri": "https://liff.line.me/1563196602-X6mLdDkW/liff/index.html?p=setting&utm_source=rumors-line-bot&utm_medium=tutorial",
},
"color": "#ffb600",
"style": "primary",
Expand Down Expand Up @@ -552,7 +552,7 @@ You can still use Cofacts without granting me this permission. When we ask for f
}
`;

exports[`should handle RICH_MENU_TRIGGER 1`] = `
exports[`should handle RICH_MENU 1`] = `
Object {
"data": Object {
"sessionId": 1497994017447,
Expand Down
84 changes: 77 additions & 7 deletions src/webhook/handlers/__tests__/tutorial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ it('should handle RICH_MENU', async () => {
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"RICH_MENU_TRIGGER",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "RICH_MENU",
},
],
]
`);
Expand All @@ -60,7 +70,17 @@ it('should handle SIMULATE_FORWARDING_MESSAGE', async () => {
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"SIMULATE_FORWARDING_MESSAGE",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "SIMULATE_FORWARDING_MESSAGE",
},
],
]
`);
Expand All @@ -77,7 +97,17 @@ it('should handle PROVIDE_PERMISSION_SETUP', async () => {
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"PROVIDE_PERMISSION_SETUP",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "PROVIDE_PERMISSION_SETUP",
},
],
]
`);
Expand All @@ -95,7 +125,17 @@ it('should handle EXPLAN_CHATBOT_FLOW_AND_PROVIDE_PERMISSION_SETUP', async () =>
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"EXPLAN_CHATBOT_FLOW_AND_PROVIDE_PERMISSION_SETUP",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "EXPLAN_CHATBOT_FLOW_AND_PROVIDE_PERMISSION_SETUP",
},
],
]
`);
Expand All @@ -113,7 +153,17 @@ it('should handle PROVIDE_PERMISSION_SETUP_WITH_EXPLANATION', async () => {
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"PROVIDE_PERMISSION_SETUP_WITH_EXPLANATION",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "PROVIDE_PERMISSION_SETUP_WITH_EXPLANATION",
},
],
]
`);
Expand All @@ -130,7 +180,17 @@ it('should handle SETUP_DONE', async () => {
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"SETUP_DONE",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "SETUP_DONE",
},
],
]
`);
Expand All @@ -147,7 +207,17 @@ it('should handle SETUP_LATER', async () => {
Array [
"Uaddc74df8a3a176b901d9d648b0fc4fe",
"TUTORIAL",
"SETUP_LATER",
],
]
`);
expect(ga.eventMock.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
Object {
"ea": "Step",
"ec": "Tutorial",
"el": "SETUP_LATER",
},
],
]
`);
Expand Down

0 comments on commit e78fd9b

Please sign in to comment.