Skip to content
Open
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
12 changes: 12 additions & 0 deletions src/services/triggers/userMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ describe("UserMigration trigger", () => {
Name: "email",
Value: "[email protected]",
});
expect(user.Attributes).toContainEqual({
Name: "sub",
Value: expect.stringMatching(UUID),
});
expect(user.UserStatus).toEqual("CONFIRMED");
});

Expand Down Expand Up @@ -119,6 +123,10 @@ describe("UserMigration trigger", () => {
expect(mockLambda.invoke).toBeCalled();
expect(user).not.toBeNull();
expect(user.Username).toEqual("thisuser");
expect(user.Attributes).toContainEqual({
Name: "sub",
Value: "thisuser",
});
});

it("sets user to RESET_REQUIRED if finalUserStatus is RESET_REQUIRED in response", async () => {
Expand All @@ -138,6 +146,10 @@ describe("UserMigration trigger", () => {

expect(user).not.toBeNull();
expect(user.UserStatus).toEqual("RESET_REQUIRED");
expect(user.Attributes).toContainEqual({
Name: "sub",
Value: expect.stringMatching(UUID),
});
});
});
});
7 changes: 5 additions & 2 deletions src/services/triggers/userMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ export const UserMigration =
}

const now = clock.get();
const userId = result.userAttributes?.username || uuid.v4();
const attributes = result.userAttributes || {};

const user: User = {
Attributes: attributesFromRecord(result.userAttributes ?? {}),
Attributes: attributesFromRecord({ ...attributes, sub: userId }),
Enabled: true,
Password: password,
UserCreateDate: now,
UserLastModifiedDate: now,
Username: result.userAttributes?.username || uuid.v4(),
Username: userId,
UserStatus: result.finalUserStatus ?? "CONFIRMED",
RefreshTokens: [],
};
Expand Down