diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 43f114c..0b35b25 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -66,8 +66,8 @@ jobs: npx sst secrets set SLACK_SIGNING_SECRET "${{ secrets.SLACK_SIGNING_SECRET_TEST }}" --stage ${{ env.STAGE }} npx sst secrets set CORE_SLACK_CHANNEL_ID "${{ secrets.CORE_SLACK_CHANNEL_ID_TEST }}" --stage ${{ env.STAGE }} npx sst secrets set RANDOM_SLACK_CHANNEL_ID "${{ secrets.RANDOM_SLACK_CHANNEL_ID_TEST }}" --stage ${{ env.STAGE }} - npx sst secrets set KRISZTA_SLACK_USER_ID "${{ secrets.SLACK_USER_ID_TEST }}" --stage ${{ env.STAGE }} - npx sst secrets set MATE_SLACK_USER_ID "${{ secrets.SLACK_USER_ID_TEST }}" --stage ${{ env.STAGE }} + npx sst secrets set ADMIN_SLACK_USER_ID "${{ secrets.SLACK_USER_ID_TEST }}" --stage ${{ env.STAGE }} + npx sst secrets set DEPUTY_ADMIN_SLACK_USER_ID "${{ secrets.SLACK_USER_ID_TEST }}" --stage ${{ env.STAGE }} - name: Deploy stack run: pnpm run deploy --stage ${{ env.STAGE }} diff --git a/.github/workflows/production.yaml b/.github/workflows/production.yaml index 67f9b4d..114ad93 100644 --- a/.github/workflows/production.yaml +++ b/.github/workflows/production.yaml @@ -54,8 +54,8 @@ jobs: npx sst secrets set SLACK_SIGNING_SECRET "${{ secrets.SLACK_SIGNING_SECRET_PRODUCTION}}" --stage "${{ env.stage }}" npx sst secrets set CORE_SLACK_CHANNEL_ID "${{ secrets.CORE_SLACK_CHANNEL_ID_PRODUCTION}}" --stage "${{ env.stage }}" npx sst secrets set RANDOM_SLACK_CHANNEL_ID "${{ secrets.RANDOM_SLACK_CHANNEL_ID_PRODUCTION}}" --stage "${{ env.stage }}" - npx sst secrets set KRISZTA_SLACK_USER_ID "${{ secrets.KRISZTA_SLACK_USER_ID_PRODUCTION }}" --stage ${{ env.stage }} - npx sst secrets set MATE_SLACK_USER_ID "${{ secrets.MATE_SLACK_USER_ID_PRODUCTION }}" --stage ${{ env.stage }} + npx sst secrets set ADMIN_SLACK_USER_ID "${{ secrets.ADMIN_SLACK_USER_ID_PRODUCTION }}" --stage ${{ env.stage }} + npx sst secrets set DEPUTY_ADMIN_SLACK_USER_ID "${{ secrets.DEPUTY_ADMIN_SLACK_USER_ID_PRODUCTION }}" --stage ${{ env.stage }} - name: Deploy stack run: pnpm run deploy --stage "${{ env.stage }}" diff --git a/.github/workflows/staging.yaml b/.github/workflows/staging.yaml index 9d6fef0..0dc1735 100644 --- a/.github/workflows/staging.yaml +++ b/.github/workflows/staging.yaml @@ -55,8 +55,8 @@ jobs: npx sst secrets set SLACK_SIGNING_SECRET "${{ secrets.SLACK_SIGNING_SECRET_STAGING }}" --stage "${{ env.stage }}" npx sst secrets set CORE_SLACK_CHANNEL_ID "${{ secrets.CORE_SLACK_CHANNEL_ID_STAGING }}" --stage "${{ env.stage }}" npx sst secrets set RANDOM_SLACK_CHANNEL_ID "${{ secrets.RANDOM_SLACK_CHANNEL_ID_STAGING }}" --stage "${{ env.stage }}" - npx sst secrets set KRISZTA_SLACK_USER_ID "${{ secrets.KRISZTA_SLACK_USER_ID_STAGING }}" --stage ${{ env.stage }} - npx sst secrets set MATE_SLACK_USER_ID "${{ secrets.MATE_SLACK_USER_ID_STAGING }}" --stage ${{ env.stage }} + npx sst secrets set ADMIN_SLACK_USER_ID "${{ secrets.ADMIN_SLACK_USER_ID_STAGING }}" --stage ${{ env.stage }} + npx sst secrets set DEPUTY_ADMIN_SLACK_USER_ID "${{ secrets.DEPUTY_ADMIN_SLACK_USER_ID_STAGING }}" --stage ${{ env.stage }} - name: Deploy stack run: pnpm run deploy --stage "${{ env.stage }}" diff --git a/README.md b/README.md index 1269b5e..255f6b8 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,8 @@ npx sst secrets set SLACK_BOT_TOKEN npx sst secrets set SLACK_SIGNING_SECRET npx sst secrets set CORE_SLACK_CHANNEL_ID npx sst secrets set RANDOM_SLACK_CHANNEL_ID -npx sst secrets set KRISZTA_SLACK_USER_ID -npx sst secrets set MATE_SLACK_USER_ID +npx sst secrets set ADMIN_SLACK_USER_ID +npx sst secrets set DEPUTY_ADMIN_SLACK_USER_ID ``` 3. Install dependencies: `pnpm i` diff --git a/architecture/backend.drawio b/architecture/backend.drawio index f7dacfb..e14d359 100644 --- a/architecture/backend.drawio +++ b/architecture/backend.drawio @@ -1,11 +1,11 @@ - + - + @@ -86,17 +86,19 @@ - + - + - + - + + + @@ -169,6 +171,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -200,10 +247,10 @@ - + - + @@ -214,14 +261,14 @@ - + - - + + @@ -238,10 +285,10 @@ - + - + @@ -250,10 +297,10 @@ - + - + @@ -290,22 +337,38 @@ - + + + + + + + + + + + + + + + + + - - + + - + - + - + @@ -336,10 +399,10 @@ - + - + @@ -416,25 +479,25 @@ - - - - - - - - - + - + + + + + + + + + - + @@ -442,12 +505,14 @@ - + - + - - + + + + @@ -469,6 +534,11 @@ + + + + + @@ -479,13 +549,13 @@ - + - + - + @@ -498,7 +568,7 @@ - + @@ -524,6 +594,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/core/types/events/index.ts b/packages/core/types/events/index.ts index 1977e8e..4c13b89 100644 --- a/packages/core/types/events/index.ts +++ b/packages/core/types/events/index.ts @@ -43,11 +43,6 @@ const Events = z.object({ presentIdea: z.string(), responseUrl: z.string(), }), - saveSquadJoin: BaseEvent.extend({ - birthdayPerson: z.string(), - user: z.string(), - team: z.string(), - }), askPresentAndSquadJoinFromTeam: BaseEvent.extend({ birthdayPerson: z.string(), team: z.string(), @@ -56,6 +51,11 @@ const Events = z.object({ birthdayPerson: z.string(), user: z.string(), }), + saveSquadJoin: BaseEvent.extend({ + birthdayPerson: z.string(), + user: z.string(), + team: z.string(), + }), createBirthdaySquad: BaseEvent.extend({ birthdayPerson: z.string(), team: z.string(), diff --git a/packages/functions/events/createBirthdaySquad.ts b/packages/functions/events/createBirthdaySquad.ts index 4f29e10..b9260d9 100644 --- a/packages/functions/events/createBirthdaySquad.ts +++ b/packages/functions/events/createBirthdaySquad.ts @@ -15,13 +15,13 @@ import { publishEvent } from "@/utils/eventBridge/publishEvent"; export const handler = handleEvent( "createBirthdaySquad", async ({ team, birthdayPerson, eventId }) => { - const { KRISZTA_SLACK_USER_ID, MATE_SLACK_USER_ID } = Config; + const { ADMIN_SLACK_USER_ID, DEPUTY_ADMIN_SLACK_USER_ID } = Config; - // Include Kriszta in all squads except on her birthday, where Mate is added to the squad. + // Include admin in all squads except on the individual's birthday, where deputy admin is added to the squad. const adminPerson = - birthdayPerson !== KRISZTA_SLACK_USER_ID - ? KRISZTA_SLACK_USER_ID - : MATE_SLACK_USER_ID; + birthdayPerson !== ADMIN_SLACK_USER_ID + ? ADMIN_SLACK_USER_ID + : DEPUTY_ADMIN_SLACK_USER_ID; try { const appliedSquadMembers = await getSquadMembers(team, birthdayPerson); diff --git a/stacks/ConfigStack.ts b/stacks/ConfigStack.ts index c557c6a..70659ca 100644 --- a/stacks/ConfigStack.ts +++ b/stacks/ConfigStack.ts @@ -13,11 +13,11 @@ export function ConfigStack({ stack }: StackContext) { stack, "RANDOM_SLACK_CHANNEL_ID", ); - const KRISZTA_SLACK_USER_ID = new Config.Secret( + const ADMIN_SLACK_USER_ID = new Config.Secret(stack, "ADMIN_SLACK_USER_ID"); + const DEPUTY_ADMIN_SLACK_USER_ID = new Config.Secret( stack, - "KRISZTA_SLACK_USER_ID", + "DEPUTY_ADMIN_SLACK_USER_ID", ); - const MATE_SLACK_USER_ID = new Config.Secret(stack, "MATE_SLACK_USER_ID"); return [ SLACK_LOG_LEVEL, @@ -25,7 +25,7 @@ export function ConfigStack({ stack }: StackContext) { SLACK_SIGNING_SECRET, CORE_SLACK_CHANNEL_ID, RANDOM_SLACK_CHANNEL_ID, - KRISZTA_SLACK_USER_ID, - MATE_SLACK_USER_ID, + ADMIN_SLACK_USER_ID, + DEPUTY_ADMIN_SLACK_USER_ID, ]; } diff --git a/tests/unit/createBirthdaySquad.test.ts b/tests/unit/createBirthdaySquad.test.ts index 95d5c2b..8264fa5 100644 --- a/tests/unit/createBirthdaySquad.test.ts +++ b/tests/unit/createBirthdaySquad.test.ts @@ -37,8 +37,8 @@ const constants = vi.hoisted(() => ({ teamId: "T001", otherUserIds: ["U002", "U003", "U004", "U005", "U006"], conversationId: "CH001", - krisztaUserId: "KU001", - mateUserId: "MU001", + adminUserId: "AU001", + deputyAdminUserId: "DAU001", })); const event = vi.hoisted( @@ -56,8 +56,8 @@ vi.mock("@/services/slack/openConversation", async () => ({ vi.mock("sst/node/config", () => ({ Config: { - KRISZTA_SLACK_USER_ID: constants.krisztaUserId, - MATE_SLACK_USER_ID: constants.mateUserId, + ADMIN_SLACK_USER_ID: constants.adminUserId, + DEPUTY_ADMIN_SLACK_USER_ID: constants.deputyAdminUserId, }, })); @@ -78,7 +78,7 @@ describe("Final squad size is less then 2", () => { expect(getRandomSquadMembersSpy).toHaveBeenCalledWith({ teamId: constants.teamId, - usersToExclude: [constants.birthdayPerson, constants.krisztaUserId], + usersToExclude: [constants.birthdayPerson, constants.adminUserId], limit: BIRTHDAY_SQUAD_SIZE, }); @@ -95,7 +95,7 @@ describe("Final squad size is less then 2", () => { expect(getRandomSquadMembersSpy).toHaveBeenCalledWith({ teamId: constants.teamId, - usersToExclude: [constants.birthdayPerson, constants.krisztaUserId], + usersToExclude: [constants.birthdayPerson, constants.adminUserId], limit: BIRTHDAY_SQUAD_SIZE, }); @@ -115,7 +115,7 @@ describe("2 or less squad members applied", () => { expect(getRandomSquadMembersSpy).toHaveBeenCalledWith({ teamId: constants.teamId, - usersToExclude: [constants.birthdayPerson, constants.krisztaUserId], + usersToExclude: [constants.birthdayPerson, constants.adminUserId], limit: BIRTHDAY_SQUAD_SIZE, }); }); @@ -202,7 +202,7 @@ describe("Add admin to the squad", () => { await testDb.delete(squadJoins); }); - it("Should add Kriszta to conversation", async () => { + it("Should add admin to conversation", async () => { await testDb.insert(users).values({ id: constants.birthdayPerson, teamId: constants.teamId, @@ -227,16 +227,13 @@ describe("Add admin to the squad", () => { await sendMockSqsMessage("createBirthdaySquad", event, handler); expect(openConversation).toBeCalledWith( - expect.arrayContaining([ - ...insertedSquadMembers, - constants.krisztaUserId, - ]), + expect.arrayContaining([...insertedSquadMembers, constants.adminUserId]), ); }); - it("Should add Mate to conversation if it's Krista's birthday", async () => { + it("Should add deputy admin to conversation if it's admins birthday", async () => { await testDb.insert(users).values({ - id: constants.krisztaUserId, + id: constants.adminUserId, teamId: constants.teamId, birthday: dayjs.utc().toDate(), }); @@ -250,7 +247,7 @@ describe("Add admin to the squad", () => { ); insertedSquadMembers = await seedSquadJoins( - constants.krisztaUserId, + constants.adminUserId, constants.teamId, constants.otherUserIds, 3, @@ -258,12 +255,15 @@ describe("Add admin to the squad", () => { await sendMockSqsMessage( "createBirthdaySquad", - { ...event, birthdayPerson: constants.krisztaUserId }, + { ...event, birthdayPerson: constants.adminUserId }, handler, ); expect(openConversation).toBeCalledWith( - expect.arrayContaining([...insertedSquadMembers, constants.mateUserId]), + expect.arrayContaining([ + ...insertedSquadMembers, + constants.deputyAdminUserId, + ]), ); }); });