From 6e955a1290ee3afd3b7e34af4526b4b33e3e1b2f Mon Sep 17 00:00:00 2001 From: Ade Adedeji Date: Wed, 18 Dec 2024 15:00:02 -0500 Subject: [PATCH] fix: [#188172536] add owningUser to v151 migration --- api/src/db/DynamoUserDataClient.test.ts | 2 +- .../v150_remove_needs_nexus_dba_name.ts | 2 +- .../v151_extract_business_data.test.ts | 7 +++++-- .../db/migrations/v151_extract_business_data.ts | 17 ++++++++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/api/src/db/DynamoUserDataClient.test.ts b/api/src/db/DynamoUserDataClient.test.ts index a767f45daa..36564e78ae 100644 --- a/api/src/db/DynamoUserDataClient.test.ts +++ b/api/src/db/DynamoUserDataClient.test.ts @@ -33,7 +33,7 @@ describe("DynamoUserDataClient", () => { it("should throw an error when attempting to retrieve a non-existent user by ID", async () => { const randomUserId = `user-id-${randomInt()}`; - await expect(dynamoUserDataClient.get(randomUserId)).rejects.toEqual(new Error("Not Found")); + await expect(dynamoUserDataClient.get(randomUserId)).rejects.toEqual(new Error("Not found")); }); it("gets inserted items", async () => { diff --git a/api/src/db/migrations/v150_remove_needs_nexus_dba_name.ts b/api/src/db/migrations/v150_remove_needs_nexus_dba_name.ts index cc94390e44..4cdf4bba51 100644 --- a/api/src/db/migrations/v150_remove_needs_nexus_dba_name.ts +++ b/api/src/db/migrations/v150_remove_needs_nexus_dba_name.ts @@ -117,7 +117,7 @@ export type v150CommunityAffairsAddress = { municipality: v150Municipality; }; -type v150BusinessUser = { +export type v150BusinessUser = { name?: string; email: string; id: string; diff --git a/api/src/db/migrations/v151_extract_business_data.test.ts b/api/src/db/migrations/v151_extract_business_data.test.ts index b010f81bdb..6bcaa931dd 100644 --- a/api/src/db/migrations/v151_extract_business_data.test.ts +++ b/api/src/db/migrations/v151_extract_business_data.test.ts @@ -1,14 +1,17 @@ import { generatev150UserData } from "@db/migrations/v150_remove_needs_nexus_dba_name"; import { migrate_v150_to_v151 } from "@db/migrations/v151_extract_business_data"; -describe("v151 migration adds version field to businesses object", () => { - it("should upgrade v150 user by adding version field to businesses object", () => { +describe("v151 migration adds version field and userId to businesses object", () => { + it("should upgrade v150 user by adding version field and userId field to businesses object", () => { const v150UserData = generatev150UserData({}); const migratedUserData = migrate_v150_to_v151(v150UserData); expect(migratedUserData.version).toBe(151); for (const business of Object.values(migratedUserData.businesses)) { expect(business.version).toBe(151); + + expect(business.userId).toBeDefined(); + expect(typeof business.userId).toBe("string"); } }); }); diff --git a/api/src/db/migrations/v151_extract_business_data.ts b/api/src/db/migrations/v151_extract_business_data.ts index 6c425815b8..55c1101984 100644 --- a/api/src/db/migrations/v151_extract_business_data.ts +++ b/api/src/db/migrations/v151_extract_business_data.ts @@ -1,4 +1,8 @@ -import { v150Business, v150UserData } from "@db/migrations/v150_remove_needs_nexus_dba_name"; +import { + v150Business, + v150BusinessUser, + v150UserData, +} from "@db/migrations/v150_remove_needs_nexus_dba_name"; import { randomInt } from "@shared/intHelpers"; export const migrate_v150_to_v151 = (v150Data: v150UserData): v151UserData => { @@ -7,17 +11,21 @@ export const migrate_v150_to_v151 = (v150Data: v150UserData): v151UserData => { businesses: Object.fromEntries( Object.entries(v150Data.businesses).map(([id, business]) => [ id, - migrate_v150Business_to_v151Business(business), + migrate_v150Business_to_v151Business(business, v150Data.user), ]) ), version: 151, } as v151UserData; }; -export const migrate_v150Business_to_v151Business = (business: v150Business): v151Business => { +export const migrate_v150Business_to_v151Business = ( + business: v150Business, + user: v150BusinessUser +): v151Business => { return { ...business, version: 151, + userId: user.id, } as v151Business; }; @@ -80,6 +88,7 @@ export interface v151Business { formationData: v151FormationData; environmentData: v151EnvironmentData | undefined; version: number; + userId: string; } export interface v151ProfileData extends v151IndustrySpecificData { @@ -605,6 +614,7 @@ export const generatev151BusinessUser = (overrides: Partial): export const generatev151Business = (overrides: Partial): v151Business => { const profileData = generatev151ProfileData({}); + const user = generatev151BusinessUser({}); return { id: `some-id-${randomInt()}`, dateCreatedISO: "", @@ -623,6 +633,7 @@ export const generatev151Business = (overrides: Partial): v151Busi licenseData: undefined, taxFilingData: generatev151TaxFilingData({}), environmentData: undefined, + userId: user.id, ...overrides, }; };