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
-
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}`;
};
-
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';
-
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
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
Summary
The
generateMockTokenhelper is currently duplicated across multiple story files (e.g.,apollo-connection.stories.tsxand 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
generateMockTokenlogic into a single shared test/story utility and updating all story files to use that shared helper.Current Behavior
generateMockTokenhelper locally.Proposed Solution
Create a shared helper file for mock token generation, for example:
apps/ui-sharethrift/src/test-utils/mockToken.tsWith the following implementation (as suggested by Sourcery):
Update stories to use the shared helper
apollo-connection.stories.tsxand any other story files that currently define a localgenerateMockToken, remove the local function implementation.Refactor usage
generateMockTokenfunctions with the imported helper.Acceptance Criteria
generateMockTokenhelper exists in an agreed-upontest-utilsor shared stories utilities location.generateMockTokennow import and use the shared helper.generateMockTokenimplementations in the codebase.Notes
I created this issue for @nnoce14 from #316 (comment).
Tips and commands
Getting Help