[AC-2520] State migration/removal of Unassigned Items Banner state definition (#10080)

* chore: create migration to remove banner dismissed data, refs AC-2520

* chore: remove unassigned items banner state definition, refs AC-2520

* fix: key like definition name updated to match original scope, refs AC-2520
This commit is contained in:
Vincent Salucci 2024-07-12 12:20:16 -05:00 committed by GitHub
parent 7588e06d2b
commit 81a3dce774
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 73 additions and 4 deletions

View File

@ -95,10 +95,6 @@ export const NEW_WEB_LAYOUT_BANNER_DISK = new StateDefinition("newWebLayoutBanne
web: "disk-local",
});
export const UNASSIGNED_ITEMS_BANNER_DISK = new StateDefinition("unassignedItemsBanner", "disk", {
web: "disk-local",
});
// Platform
export const APPLICATION_ID_DISK = new StateDefinition("applicationId", "disk", {

View File

@ -0,0 +1,50 @@
import { runMigrator } from "../migration-helper.spec";
import { IRREVERSIBLE } from "../migrator";
import { RemoveUnassignedItemsBannerDismissed } from "./67-remove-unassigned-items-banner-dismissed";
describe("RemoveUnassignedItemsBannerDismissed", () => {
const sut = new RemoveUnassignedItemsBannerDismissed(66, 67);
describe("migrate", () => {
it("deletes unassignedItemsBanner from all users", async () => {
const output = await runMigrator(sut, {
global_account_accounts: {
user1: {
email: "user1@email.com",
name: "User 1",
emailVerified: true,
},
user2: {
email: "user2@email.com",
name: "User 2",
emailVerified: true,
},
},
user_user1_unassignedItemsBanner_showBanner: true,
user_user2_unassignedItemsBanner_showBanner: false,
});
expect(output).toEqual({
global_account_accounts: {
user1: {
email: "user1@email.com",
name: "User 1",
emailVerified: true,
},
user2: {
email: "user2@email.com",
name: "User 2",
emailVerified: true,
},
},
});
});
});
describe("rollback", () => {
it("is irreversible", async () => {
await expect(runMigrator(sut, {}, "rollback")).rejects.toThrow(IRREVERSIBLE);
});
});
});

View File

@ -0,0 +1,23 @@
import { KeyDefinitionLike, MigrationHelper } from "../migration-helper";
import { IRREVERSIBLE, Migrator } from "../migrator";
export const SHOW_BANNER: KeyDefinitionLike = {
key: "showBanner",
stateDefinition: { name: "unassignedItemsBanner" },
};
export class RemoveUnassignedItemsBannerDismissed extends Migrator<66, 67> {
async migrate(helper: MigrationHelper): Promise<void> {
await Promise.all(
(await helper.getAccounts()).map(async ({ userId }) => {
if (helper.getFromUser(userId, SHOW_BANNER) != null) {
await helper.removeFromUser(userId, SHOW_BANNER);
}
}),
);
}
async rollback(helper: MigrationHelper): Promise<void> {
throw IRREVERSIBLE;
}
}