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.ts
src/infrastructure/discord/commands/myIssues.ts
src/infrastructure/discord/authz.ts
src/infrastructure/discord/webhookMessages.ts
src/infrastructure/discord/tasks/urgentItemsDirectMessage.ts
test/infrastructure/discord/interactions/assigneeSelectInteraction.test.ts
test/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 User interface
export interface User {
githubUsername: string;
githubId: string;
discordId: string;
}
-
Implement UserService with the following methods
Each 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
githubDiscordMap data.
- Use
.find() on Object.values(githubDiscordMap) and wrap the result in ok() or err() from your Result utility.
-
Replace direct imports
- Refactor all existing files that directly use
githubDiscordMap.json to instead use UserService.
-
Write unit tests
- Create a new test file in
test/items/services/UserService.test.ts
- Mock example
githubDiscordMap data to test lookup methods
- Update any tests that previously mocked
githubDiscordMap.json to instead mock UserService
✅ Acceptance Criteria
As a developer, I want a single source of truth for accessing
githubDiscordMap.jsondata 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.tsEach 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.tsDefine the
UserinterfaceImplement
UserServicewith the following methodsEach method should return a
Promise<Result<User, Error>>.githubDiscordMapdata..find()onObject.values(githubDiscordMap)and wrap the result inok()orerr()from your Result utility.Replace direct imports
githubDiscordMap.jsonto instead useUserService.Write unit tests
test/items/services/UserService.test.tsgithubDiscordMapdata to test lookup methodsgithubDiscordMap.jsonto instead mockUserService✅ 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 serviceAll imports of
data/githubDiscordMap.jsonin application code are replaced with calls toUserServiceA test file exists at
test/items/services/UserService.test.tswith coverage for all public methodsAll corresponding unit tests mock
UserServiceinstead of mockinggithubDiscordMap.jsondirectlyCode duplication for
githubDiscordMaplookups has been removed across all files listed in the context section