Skip to content

Refactor duplicate githubDiscordMap access usage #30

@MathyouMB

Description

@MathyouMB

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

  1. Create a new service file

    In src/items/services/, create a new file:
    UserService.ts

  2. Define the User interface

    export interface User {
      githubUsername: string;
      githubId: string;
      discordId: string;
    }
  3. 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.
  4. Replace direct imports

    • Refactor all existing files that directly use githubDiscordMap.json to instead use UserService.
  5. 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

  • UserService.ts exists in src/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 to UserService

  • 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 mocking githubDiscordMap.json directly

  • Code duplication for githubDiscordMap lookups has been removed across all files listed in the context section

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Projects

Status

Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions