Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [M3-8739] - Fix MSW 2.0 initial mock store and support ticket seeder bugs #11090

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix: Ensure that every empty store key is represented in mock state.

Note: I didn't compare the number of keys in the empty store and mock state, because mock state seems to always get an id key added that is not part of the empty store. (See screenshots in testing section to see it.) I am not quite sure the purpose of the id but am sure they're useful for something and maybe @abailly-akamai can clarify.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjac0bs it is how IndexedDB works - it's meant to behave like a DB to it has auto ID increment. We're not really using indexedDB the way it's supposed to, I just used this storage solution as a blob store

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
Loading