-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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
generateMockTokenhelper 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.tsxand any other story files that currently define a localgenerateMockToken, 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';
- In
-
Refactor usage
- Replace all references to the local
generateMockTokenfunctions with the imported helper. - Ensure that stories still work as expected (run Storybook and/or tests involving these stories).
- Replace all references to the local
Acceptance Criteria
- A shared
generateMockTokenhelper exists in an agreed-upontest-utilsor shared stories utilities location. - All stories that previously defined their own
generateMockTokennow import and use the shared helper. - Storybook runs successfully and all relevant stories still render/function correctly.
- No remaining duplicate
generateMockTokenimplementations 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
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
In Progress