Skip to content

Conversation

cquirosj
Copy link
Contributor

@cquirosj cquirosj commented Apr 16, 2025

This change introduces a targeted approach to improve the testability of MessageStore:

  • Created a new ConfigurationStore as a Pinia store to replace the usage of useConfiguration composable in MessageStore
  • Created a new EditRetryStore as a Pinia store to replace useEditAndRetry composable usage in MessageStore
  • Removed automatic initialization in the store definition to avoid network calls during tests and take advantage of Pinia testing infrastructure that stubs actions by default and allows tests to patch the stores state instead for each scenario
  • The Message store explicitly calls loadConfig() of the new stores during initialization, which in turn is stubbed by Pinia when used in tests
  • This allows component tests to run without unwanted network calls, for when patching the store state is the technique the developer writing component tests prefers to use for setting up scenarios preconditions
  • The original useConfiguration composable remains untouched for other components

This focused refactoring prevents network calls from being made during tests while minimizing changes to the codebase. It only affects MessageStore.ts without requiring a broader refactoring across all components that use configuration data. In the future, the rest of the application can take advantage of the new Configuration Pinia store.

image

This changeintroduces a **targeted** approach to improve the testability of MessageStore:

- Created a new ConfigurationStore as a Pinia store to replace usage of useConfiguration composable in MessageStore
- Created a new EditRetryStore as a Pinia store to replace useEditAndRetry composable usage in MessageStore
- Removed automatic initialization in the store definition to avoid network calls during tests and take advantage of Pinia testing infraestructure that stubs actions by default and allow tests to patch the stores state instead for each scenario
- The Message store explicitly calls loadConfig() of the new stores during initialization, which in turn is properly stubbed by Pinia when used in tests
- This allows component tests to run without unwanted network calls when patch the store state is preffered by the developer writing the component test
- The original useConfiguration composable remains untouched for other components

This focused refactoring prevents network calls from being made during tests while
minimizing changes to the codebase, as it only affects MessageStore.ts without
requiring a broader refactoring across all components that use configuration data.
@cquirosj cquirosj marked this pull request as ready for review April 16, 2025 02:52
@cquirosj cquirosj merged commit e39e51c into master Apr 16, 2025
5 checks passed
@cquirosj cquirosj deleted the message-store-testability branch April 16, 2025 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants