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.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
interfaceexport interface User { githubUsername: string; githubId: string; discordId: string; }
-
Implement
UserService
with 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
githubDiscordMap
data. - 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.json
to 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
githubDiscordMap
data to test lookup methods - Update any tests that previously mocked
githubDiscordMap.json
to instead mockUserService
- Create a new test file in
✅ Acceptance Criteria
-
UserService.ts
exists insrc/items/services/
with methods:findUserByDiscordID(discordId: string): Promise<Result<User, Error>>
findUserByGithubUsername(githubUsername: string): Promise<Result<User, Error>>
-
A shared
User
interface is exported from the service -
All imports of
data/githubDiscordMap.json
in application code are replaced with calls toUserService
-
A test file exists at
test/items/services/UserService.test.ts
with coverage for all public methods -
All corresponding unit tests mock
UserService
instead of mockinggithubDiscordMap.json
directly -
Code duplication for
githubDiscordMap
lookups has been removed across all files listed in the context section
Metadata
Metadata
Assignees
Labels
Type
Projects
Status