forked from jagregory/cognito-local
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include user attributes in user migration lambda call
- Loading branch information
Showing
6 changed files
with
154 additions
and
57 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
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 |
---|---|---|
|
@@ -37,6 +37,7 @@ describe("UserMigration trigger", () => { | |
clientId: "clientId", | ||
username: "username", | ||
password: "password", | ||
userAttributes: [], | ||
}) | ||
).rejects.toBeInstanceOf(NotAuthorizedError); | ||
}); | ||
|
@@ -51,6 +52,16 @@ describe("UserMigration trigger", () => { | |
clientId: "clientId", | ||
username: "[email protected]", | ||
password: "password", | ||
userAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
}); | ||
|
||
expect(mockLambda.invoke).toHaveBeenCalledWith("UserMigration", { | ||
clientId: "clientId", | ||
password: "password", | ||
triggerSource: "UserMigration_Authentication", | ||
userAttributes: { email: "[email protected]" }, | ||
userPoolId: "userPoolId", | ||
username: "[email protected]", | ||
}); | ||
|
||
expect(user).not.toBeNull(); | ||
|
@@ -73,6 +84,7 @@ describe("UserMigration trigger", () => { | |
clientId: "clientId", | ||
username: "[email protected]", | ||
password: "password", | ||
userAttributes: [], | ||
}); | ||
|
||
expect(user).not.toBeNull(); | ||
|
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,12 @@ | ||
import { CreateDataStore, DataStore } from "./dataStore"; | ||
import { createUserPool, UserPool } from "./userPool"; | ||
import { | ||
attributesInclude, | ||
attributesIncludeMatch, | ||
attributesToRecord, | ||
createUserPool, | ||
UserAttribute, | ||
UserPool, | ||
} from "./userPool"; | ||
|
||
describe("User Pool", () => { | ||
let mockDataStore: jest.Mocked<DataStore>; | ||
|
@@ -154,4 +161,50 @@ describe("User Pool", () => { | |
} | ||
); | ||
}); | ||
|
||
describe("attributes", () => { | ||
const attributes: readonly UserAttribute[] = [ | ||
{ Name: "sub", Value: "uuid" }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
]; | ||
|
||
describe("attributesIncludeMatch", () => { | ||
it("returns true if attribute exists in collection with matching name and value", () => { | ||
expect( | ||
attributesIncludeMatch("email", "[email protected]", attributes) | ||
).toBe(true); | ||
}); | ||
|
||
it("returns false if attribute exists in collection with matching name but not matching value", () => { | ||
expect(attributesIncludeMatch("email", "invalid", attributes)).toBe( | ||
false | ||
); | ||
}); | ||
|
||
it("returns false if attribute does not exist in collection", () => { | ||
expect(attributesIncludeMatch("invalid", "invalid", attributes)).toBe( | ||
false | ||
); | ||
}); | ||
}); | ||
|
||
describe("attributesInclude", () => { | ||
it("returns true if attribute exists in collection with matching name", () => { | ||
expect(attributesInclude("email", attributes)).toBe(true); | ||
}); | ||
|
||
it("returns false if attribute does not exist in collection", () => { | ||
expect(attributesInclude("invalid", attributes)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("attributesToRecord", () => { | ||
it("converts the attributes to a record", () => { | ||
expect(attributesToRecord(attributes)).toEqual({ | ||
email: "[email protected]", | ||
sub: "uuid", | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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