-
Notifications
You must be signed in to change notification settings - Fork 0
Description
As a developer, I want a single source of truth for accessing githubDiscordMap.json data so that we can avoid duplicate parsing logic and simplify test mocking.
🧠 Context
Today there are multiple places in the codebase that directly import and parse data/githubDiscordMap.json:
src/infrastructure/discord/interactions/assigneeSelectInteraction.tssrc/infrastructure/discord/commands/myIssues.tssrc/infrastructure/discord/authz.tssrc/infrastructure/discord/webhookMessages.tssrc/infrastructure/discord/tasks/urgentItemsDirectMessage.tstest/infrastructure/discord/interactions/assigneeSelectInteraction.test.tstest/infrastructure/discord/tasks/urgentItemsDirecMessage.test.ts
Each of these files creates duplicate code to traverse and lookup data on githubDiscordMap.json. This also introduces friction when testing, as each file must remock the same interface manually.
We should abstract access to this data into a central service to improve maintainability and eliminate redundancy.
🛠️ Implementation Plan
-
Create a new service file
In
src/items/services/, create a new file:
UserService.ts -
Define the
Userinterfaceexport interface User { githubUsername: string; githubId: string; discordId: string; }
-
Implement
UserServicewith the following methodsEach method should return a
Promise<Result<User, Error>>.findUserByDiscordID(discordId: string): Promise<Result<User, Error>> findUserByGithubUsername(githubUsername: string): Promise<Result<User, Error>>
- These methods should perform lookups using the existing
githubDiscordMapdata. - Use
.find()onObject.values(githubDiscordMap)and wrap the result inok()orerr()from your Result utility.
- These methods should perform lookups using the existing
-
Replace direct imports
- Refactor all existing files that directly use
githubDiscordMap.jsonto instead useUserService.
- Refactor all existing files that directly use
-
Write unit tests
- Create a new test file in
test/items/services/UserService.test.ts - Mock example
githubDiscordMapdata to test lookup methods - Update any tests that previously mocked
githubDiscordMap.jsonto instead mockUserService
- Create a new test file in
✅ Acceptance Criteria
-
UserService.tsexists insrc/items/services/with methods:findUserByDiscordID(discordId: string): Promise<Result<User, Error>>findUserByGithubUsername(githubUsername: string): Promise<Result<User, Error>>
-
A shared
Userinterface is exported from the service -
All imports of
data/githubDiscordMap.jsonin application code are replaced with calls toUserService -
A test file exists at
test/items/services/UserService.test.tswith coverage for all public methods -
All corresponding unit tests mock
UserServiceinstead of mockinggithubDiscordMap.jsondirectly -
Code duplication for
githubDiscordMaplookups has been removed across all files listed in the context section
Metadata
Metadata
Assignees
Labels
Type
Projects
Status