Skip to content

Commit

Permalink
fix: [M3-8739] - Fix MSW 2.0 initial mock store and support ticket se…
Browse files Browse the repository at this point in the history
…eder bugs (#11090)

* Fix the bug in initial mock store creation

* Fix bug where support ticket seeds aren't removed on uncheck

* Added changeset: Fix MSW 2.0 initial mock store and support ticket seeder bugs

* Fix conditional logic

* Update removeSeeds comment to clarify use
  • Loading branch information
mjac0bs authored Oct 17, 2024
1 parent cf8823a commit 1d622f4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Fix MSW 2.0 initial mock store and support ticket seeder bugs ([#11090](https://github.com/linode/manager/pull/11090))
9 changes: 8 additions & 1 deletion packages/manager/src/mocks/mockState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ export const createInitialMockStore = async (): Promise<MockState> => {
const mockState = await mswDB.getStore('mockState');

if (mockState) {
return mockState;
const mockStateKeys = Object.keys(mockState);
const emptyStoreKeys = Object.keys(emptyStore);

// Return the existing mockState if it includes all keys from the empty store;
// else, discard the existing mockState because we've introduced new values.
if (emptyStoreKeys.every((key) => mockStateKeys.includes(key))) {
return mockState;
}
}

return emptyStore;
Expand Down
4 changes: 4 additions & 0 deletions packages/manager/src/mocks/presets/crud/seeds/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { MockSeeder, MockState } from 'src/mocks/types';

/**
* Removes the seeds from the database.
* This function is called upon unchecking an individual seeder in the MSW.
*
* @param seederId - The ID of the seeder to remove.
*
Expand All @@ -22,6 +23,9 @@ export const removeSeeds = async (seederId: MockSeeder['id']) => {
case 'volumes:crud':
await mswDB.deleteAll('volumes', mockState, 'seedState');
break;
case 'support-tickets:crud':
await mswDB.deleteAll('supportTickets', mockState, 'seedState');
break;
default:
break;
}
Expand Down

0 comments on commit 1d622f4

Please sign in to comment.