From 1d622f4c3756a96a5995cd3a757da35f4d7db6a6 Mon Sep 17 00:00:00 2001 From: Mariah Jacobs <114685994+mjac0bs@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:07:27 -0700 Subject: [PATCH] fix: [M3-8739] - Fix MSW 2.0 initial mock store and support ticket seeder 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 --- .../.changeset/pr-11090-tech-stories-1728605016946.md | 5 +++++ packages/manager/src/mocks/mockState.ts | 9 ++++++++- packages/manager/src/mocks/presets/crud/seeds/utils.ts | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 packages/manager/.changeset/pr-11090-tech-stories-1728605016946.md diff --git a/packages/manager/.changeset/pr-11090-tech-stories-1728605016946.md b/packages/manager/.changeset/pr-11090-tech-stories-1728605016946.md new file mode 100644 index 00000000000..313b634e115 --- /dev/null +++ b/packages/manager/.changeset/pr-11090-tech-stories-1728605016946.md @@ -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)) diff --git a/packages/manager/src/mocks/mockState.ts b/packages/manager/src/mocks/mockState.ts index 3cbf770964f..d4aa0d3a905 100644 --- a/packages/manager/src/mocks/mockState.ts +++ b/packages/manager/src/mocks/mockState.ts @@ -44,7 +44,14 @@ export const createInitialMockStore = async (): Promise => { 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; diff --git a/packages/manager/src/mocks/presets/crud/seeds/utils.ts b/packages/manager/src/mocks/presets/crud/seeds/utils.ts index 348c6dd6c23..5b77c2d2781 100644 --- a/packages/manager/src/mocks/presets/crud/seeds/utils.ts +++ b/packages/manager/src/mocks/presets/crud/seeds/utils.ts @@ -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. * @@ -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; }