Skip to content

Consolidate duplicated generateMockToken helper into shared test/story utility #321

@sourcery-ai

Description

@sourcery-ai

Summary

The generateMockToken helper is currently duplicated across multiple story files (e.g., apollo-connection.stories.tsx and at least one other story). This duplication can lead to divergence in behavior over time and makes maintenance more difficult.

This issue proposes consolidating the generateMockToken logic into a single shared test/story utility and updating all story files to use that shared helper.

Current Behavior

  • Multiple Storybook stories define their own generateMockToken helper locally.
  • Implementations are very similar/identical but live in separate files.
  • Any future change in token generation would need to be updated in multiple places, with a risk of inconsistencies.

Proposed Solution

  1. Create a shared helper file for mock token generation, for example:

    • apps/ui-sharethrift/src/test-utils/mockToken.ts

    With the following implementation (as suggested by Sourcery):

    export const generateMockToken = () => {
      const randomPart = Math.random().toString(36).substring(2, 15);
      const timestamp = Date.now().toString(36);
      return `mock_${timestamp}_${randomPart}`;
    };
  2. Update stories to use the shared helper

    • In apollo-connection.stories.tsx and any other story files that currently define a local generateMockToken, remove the local function implementation.
    • Import the shared helper instead, adjusting the path to match the repo’s structure and alias conventions:
    import { generateMockToken } from './test-utils/mockToken';
    // or, depending on project structure
    // import { generateMockToken } from '../test-utils/mockToken';
    // or
    // import { generateMockToken } from '@test-utils/mockToken';
  3. Refactor usage

    • Replace all references to the local generateMockToken functions with the imported helper.
    • Ensure that stories still work as expected (run Storybook and/or tests involving these stories).

Acceptance Criteria

  • A shared generateMockToken helper exists in an agreed-upon test-utils or shared stories utilities location.
  • All stories that previously defined their own generateMockToken now import and use the shared helper.
  • Storybook runs successfully and all relevant stories still render/function correctly.
  • No remaining duplicate generateMockToken implementations in the codebase.

Notes

  • This is a refactoring/cleanup task and was explicitly called out as out of scope for the Snyk implementation work, so it should be handled separately from that feature.
  • Maintain consistency with existing project conventions for test/story utilities (directory structure, import aliases, etc.).

I created this issue for @nnoce14 from #316 (comment).

Tips and commands

Getting Help

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions