Skip to content

Commit

Permalink
Diagram and admin refactor (#29)
Browse files Browse the repository at this point in the history
* chore: use generic admin and deputy admin instead of specifiying names

* chore: update diagram

* chore: change wordings + constant values
  • Loading branch information
BaDo2001 authored Nov 29, 2023
1 parent c20bed4 commit f4e40a6
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ npx sst secrets set SLACK_BOT_TOKEN <your-bot-token>
npx sst secrets set SLACK_SIGNING_SECRET <your-signing-secret>
npx sst secrets set CORE_SLACK_CHANNEL_ID <your-test-channel>
npx sst secrets set RANDOM_SLACK_CHANNEL_ID <your-test-channel>
npx sst secrets set KRISZTA_SLACK_USER_ID <your-test-user>
npx sst secrets set MATE_SLACK_USER_ID <your-test-user>
npx sst secrets set ADMIN_SLACK_USER_ID <your-test-user>
npx sst secrets set DEPUTY_ADMIN_SLACK_USER_ID <your-test-user>
```

3. Install dependencies: `pnpm i`
Expand Down
353 changes: 311 additions & 42 deletions architecture/backend.drawio

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/core/types/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
10 changes: 5 additions & 5 deletions packages/functions/events/createBirthdaySquad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions stacks/ConfigStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ 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,
SLACK_BOT_TOKEN,
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,
];
}
34 changes: 17 additions & 17 deletions tests/unit/createBirthdaySquad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
},
}));

Expand All @@ -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,
});

Expand All @@ -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,
});

Expand All @@ -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,
});
});
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
});
Expand All @@ -250,20 +247,23 @@ describe("Add admin to the squad", () => {
);

insertedSquadMembers = await seedSquadJoins(
constants.krisztaUserId,
constants.adminUserId,
constants.teamId,
constants.otherUserIds,
3,
);

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,
]),
);
});
});

0 comments on commit f4e40a6

Please sign in to comment.