-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lambda): save attributes from user migration lambda on user record
- Loading branch information
Showing
4 changed files
with
34 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,22 +44,26 @@ describe("UserMigration trigger", () => { | |
}); | ||
|
||
describe("when lambda invoke succeeds", () => { | ||
it("saves user", async () => { | ||
mockLambda.invoke.mockResolvedValue({}); | ||
it("saves user with attributes from response", async () => { | ||
mockLambda.invoke.mockResolvedValue({ | ||
userAttributes: { | ||
email: "[email protected]", | ||
}, | ||
}); | ||
|
||
const user = await userMigration({ | ||
userPoolId: "userPoolId", | ||
clientId: "clientId", | ||
username: "[email protected]", | ||
username: "[email protected]", // username may be an email when migration is from a login attempt | ||
password: "password", | ||
userAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
userAttributes: [], // there won't be any attributes yet because we don't know who the user is | ||
}); | ||
|
||
expect(mockLambda.invoke).toHaveBeenCalledWith("UserMigration", { | ||
clientId: "clientId", | ||
password: "password", | ||
triggerSource: "UserMigration_Authentication", | ||
userAttributes: { email: "[email protected]" }, | ||
userAttributes: {}, | ||
userPoolId: "userPoolId", | ||
username: "[email protected]", | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { CreateDataStore, DataStore } from "./dataStore"; | ||
import { | ||
attributesFromRecord, | ||
attributesInclude, | ||
attributesIncludeMatch, | ||
attributesToRecord, | ||
|
@@ -201,10 +202,21 @@ describe("User Pool", () => { | |
describe("attributesToRecord", () => { | ||
it("converts the attributes to a record", () => { | ||
expect(attributesToRecord(attributes)).toEqual({ | ||
email: "[email protected]", | ||
sub: "uuid", | ||
email: "[email protected]", | ||
}); | ||
}); | ||
}); | ||
|
||
describe("attributesFromRecord", () => { | ||
it("converts the attributes to a record", () => { | ||
expect( | ||
attributesFromRecord({ | ||
sub: "uuid", | ||
email: "[email protected]", | ||
}) | ||
).toEqual(attributes); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters