Skip to content

Commit

Permalink
fix: send empty json on slack callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Balint Dolla committed Oct 25, 2023
1 parent 6605006 commit d8ff79b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VITE_SLACK_BOT_TOKEN=
VITE_SLACK_SIGNING_SECRET=
# Your slack user id
VITE_SLACK_USER_ID=
# The slack bots user id (can be found by running npx ts-node --esm tests/scripts/getBotUserId.ts after setting the slack bot token and signing secret)
# The slack bots user id
VITE_SLACK_BOT_USER_ID=
# The slack channel id used for testing
VITE_CORE_SLACK_CHANNEL_ID=
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/events/askBirthday.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ export const handler = handleEvent("askBirthday", async ({ user }) => {
],
});
} catch (error) {
console.log("Error processing askBirthday event: ", error);
console.error("Error processing askBirthday event: ", error);
}
});
2 changes: 2 additions & 0 deletions packages/functions/lambdas/slack-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export const handler: APIGatewayProxyHandlerV2 = async (request) => {

return {
statusCode: 200,
body: JSON.stringify({}),
};
} catch (error) {
console.error(`Error handling slack callback: ${error as string}`);
return {
statusCode: 500,
body: JSON.stringify({}),
};
}
};
14 changes: 7 additions & 7 deletions tests/integration/slackEvents.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from "@slack/bolt";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";

import { deleteDmMessages } from "@/testUtils/deleteDmMessages";
import { sendMockSlackEvent } from "@/testUtils/sendMockSlackEvent";
Expand All @@ -15,13 +15,13 @@ const app = new App({
});

describe("Slack events", () => {
beforeAll(async () => {
beforeEach(async () => {
await deleteDmMessages(app);
});
}, 10_000);

afterEach(async () => {
afterAll(async () => {
await deleteDmMessages(app);
});
}, 10_000);

it("Should return challenge on slack event endpoint", async () => {
const res = await sendMockSlackEvent({
Expand Down Expand Up @@ -50,7 +50,7 @@ describe("Slack events", () => {
expect(chat.messages![0].text).toEqual(
"Please share your birthday with us! :birthday:",
);
}, 20_000);
}, 10_000);

it("Should send DM to all users when bot joins the channel", async () => {
await sendMockSlackEvent({
Expand All @@ -68,5 +68,5 @@ describe("Slack events", () => {
expect(chat.messages![0].text).toEqual(
"Please share your birthday with us! :birthday:",
);
}, 20_000);
}, 10_000);
});
17 changes: 0 additions & 17 deletions tests/scripts/getBotUserId.ts

This file was deleted.

20 changes: 11 additions & 9 deletions tests/utils/deleteDmMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ export const deleteDmMessages = async (app: App) => {
limit: 1,
});

for (const message of chat.messages ?? []) {
if (!message.ts) {
continue;
}
await Promise.all(
chat.messages?.map(async (message) => {
if (!message.ts) {
return;
}

await app.client.chat.delete({
channel: import.meta.env.VITE_SLACK_DM_ID,
ts: message.ts,
});
}
await app.client.chat.delete({
channel: import.meta.env.VITE_SLACK_DM_ID,
ts: message.ts,
});
}) ?? [],
);
};
2 changes: 1 addition & 1 deletion tests/utils/waitForDm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const waitForDm = async (app: App) =>
return chat;
},
{
timeout: 20_000,
timeout: 10_000,
interval: 1_000,
},
);

0 comments on commit d8ff79b

Please sign in to comment.