Skip to content

Commit

Permalink
fix: [#188172536] add owningUser to v151 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
aadedejifearless committed Dec 18, 2024
1 parent 3ce7d6d commit 6e955a1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/src/db/DynamoUserDataClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion api/src/db/migrations/v150_remove_needs_nexus_dba_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type v150CommunityAffairsAddress = {
municipality: v150Municipality;
};

type v150BusinessUser = {
export type v150BusinessUser = {
name?: string;
email: string;
id: string;
Expand Down
7 changes: 5 additions & 2 deletions api/src/db/migrations/v151_extract_business_data.test.ts
Original file line number Diff line number Diff line change
@@ -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");
}
});
});
17 changes: 14 additions & 3 deletions api/src/db/migrations/v151_extract_business_data.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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;
};

Expand Down Expand Up @@ -80,6 +88,7 @@ export interface v151Business {
formationData: v151FormationData;
environmentData: v151EnvironmentData | undefined;
version: number;
userId: string;
}

export interface v151ProfileData extends v151IndustrySpecificData {
Expand Down Expand Up @@ -605,6 +614,7 @@ export const generatev151BusinessUser = (overrides: Partial<v151BusinessUser>):

export const generatev151Business = (overrides: Partial<v151Business>): v151Business => {
const profileData = generatev151ProfileData({});
const user = generatev151BusinessUser({});
return {
id: `some-id-${randomInt()}`,
dateCreatedISO: "",
Expand All @@ -623,6 +633,7 @@ export const generatev151Business = (overrides: Partial<v151Business>): v151Busi
licenseData: undefined,
taxFilingData: generatev151TaxFilingData({}),
environmentData: undefined,
userId: user.id,
...overrides,
};
};
Expand Down

0 comments on commit 6e955a1

Please sign in to comment.