Skip to content

Commit

Permalink
Merge b72e0d9 into e7eae79
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Nov 27, 2023
2 parents e7eae79 + b72e0d9 commit 21b7248
Show file tree
Hide file tree
Showing 10 changed files with 695 additions and 565 deletions.
2 changes: 1 addition & 1 deletion src/rumors-db
50 changes: 2 additions & 48 deletions src/webhook/__tests__/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Webhook router singleUserHandler() should handle follow event 1`] = `
Array [
Object {
"_id": "_id",
"allowNewReplyUpdate": true,
"createdAt": 1989-06-04T00:00:00.000Z,
"userId": "U4af4980629",
},
]
`;

exports[`Webhook router singleUserHandler() should handle follow event with RUMORS_LINE_BOT_URL not set 1`] = `
Array [
Object {
"_id": "_id",
"allowNewReplyUpdate": true,
"createdAt": 1989-06-04T00:00:00.000Z,
"userId": "U4af4980629",
},
]
`;

exports[`Webhook router singleUserHandler() should handle follow then unfollow then follow event 1`] = `
Array [
Object {
Expand Down Expand Up @@ -55,30 +33,6 @@ Array [
]
`;

exports[`Webhook router singleUserHandler() should reply default messages 1`] = `
Array [
Array [
"/message/reply",
Object {
"messages": Array [
Object {
"text": "I cannot understand messages other than text.",
"type": "text",
},
],
"replyToken": "nHuyWiB7yP5Zw52FIkcQobQuGDXCTA",
},
],
]
`;
exports[`Webhook router singleUserHandler() should ignore sticker messages 1`] = `Array []`;

exports[`Webhook router singleUserHandler() should reply default messages 2`] = `
Array [
Array [
"U4af4980630",
Object {
"data": Object {},
},
],
]
`;
exports[`Webhook router singleUserHandler() should ignore sticker messages 2`] = `Array []`;
113 changes: 1 addition & 112 deletions src/webhook/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,117 +49,6 @@ describe('Webhook router', () => {
await expiredGroupEventQueue.close();
});

it('singleUserHandler() should handle follow event', async () => {
const userId = 'U4af4980629';
const app = new Koa();
app.use(webhookRouter.routes(), webhookRouter.allowedMethods());

const eventObject = {
events: [
{
replyToken: 'nHuyWiB7yP5Zw52FIkcQobQuGDXCTA',
type: 'follow',
mode: 'active',
timestamp: 1462629479859,
source: {
type: 'user',
userId,
},
},
],
};

const server = app.listen();

await request(server).post('/').send(eventObject).expect(200);

/**
* The HTTP response isn't guaranteed the event handling to be complete
*/
await sleep(500);

expect(
(await UserSettings.find({ userId })).map((e) => ({ ...e, _id: '_id' }))
).toMatchSnapshot();

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) => {
if (error) return reject(error);
resolve();
});
});
});

it('singleUserHandler() should handle follow event with RUMORS_LINE_BOT_URL not set', async () => {
delete process.env.RUMORS_LINE_BOT_URL;
const userId = 'U4af4980629';
const app = new Koa();
app.use(webhookRouter.routes(), webhookRouter.allowedMethods());

const eventObject = {
events: [
{
replyToken: 'nHuyWiB7yP5Zw52FIkcQobQuGDXCTA',
type: 'follow',
mode: 'active',
timestamp: 1462629479859,
source: {
type: 'user',
userId,
},
},
],
};

const server = app.listen();

await request(server).post('/').send(eventObject).expect(200);

/**
* The HTTP response isn't guaranteed the event handling to be complete
*/
await sleep(500);

expect(
(await UserSettings.find({ userId })).map((e) => ({ ...e, _id: '_id' }))
).toMatchSnapshot();

expect(createGreetingMessage).not.toHaveBeenCalled();
expect(createTutorialMessage).not.toHaveBeenCalled();
expect(ga.sendMock).not.toHaveBeenCalled();
expect(lineClient.post).not.toHaveBeenCalled();

return new Promise((resolve, reject) => {
server.close((error) => {
if (error) return reject(error);
resolve();
});
});
});

it('singleUserHandler() should handle follow then unfollow then follow event', async () => {
const userId = 'U4af4980630';
const app = new Koa();
Expand Down Expand Up @@ -208,7 +97,7 @@ describe('Webhook router', () => {
});
});

it('singleUserHandler() should reply default messages', async () => {
it('singleUserHandler() should ignore sticker messages', async () => {
const userId = 'U4af4980630';
const app = new Koa();
app.use(webhookRouter.routes(), webhookRouter.allowedMethods());
Expand Down
72 changes: 0 additions & 72 deletions src/webhook/handleInput.ts

This file was deleted.

0 comments on commit 21b7248

Please sign in to comment.