-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): adminUpdateUserAttributes full support
Fixes this API call not actually doing anything. Now will update the attributes, trying to respect Cognito's validation behaviour. Sends messages including calling the CustomMessage trigger.
- Loading branch information
Showing
15 changed files
with
590 additions
and
340 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
57 changes: 57 additions & 0 deletions
57
integration-tests/aws-sdk/adminUpdateUserAttributes.test.ts
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { UUID } from "../../src/__tests__/patterns"; | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.adminUpdateUserAttributes", | ||
withCognitoSdk((Cognito) => { | ||
it("updates a user's attributes", async () => { | ||
const client = Cognito(); | ||
|
||
await client | ||
.adminCreateUser({ | ||
UserAttributes: [ | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0400000000" }, | ||
], | ||
Username: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
let user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
expect(user.UserAttributes).toEqual([ | ||
{ Name: "sub", Value: expect.stringMatching(UUID) }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0400000000" }, | ||
]); | ||
|
||
await client | ||
.adminUpdateUserAttributes({ | ||
UserPoolId: "test", | ||
Username: "abc", | ||
UserAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
}) | ||
.promise(); | ||
|
||
user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
expect(user.UserAttributes).toEqual([ | ||
{ Name: "sub", Value: expect.stringMatching(UUID) }, | ||
{ Name: "email", Value: "[email protected]" }, | ||
{ Name: "phone_number", Value: "0400000000" }, | ||
{ Name: "email_verified", Value: "false" }, | ||
]); | ||
}); | ||
}) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { VerifiedAttributesListType } from "aws-sdk/clients/cognitoidentityserviceprovider"; | ||
import { attributeValue, User } from "../userPoolService"; | ||
import { DeliveryDetails } from "./messageDelivery"; | ||
|
||
export const selectAppropriateDeliveryMethod = ( | ||
desiredDeliveryMediums: VerifiedAttributesListType, | ||
user: User | ||
): DeliveryDetails | null => { | ||
if (desiredDeliveryMediums.includes("phone_number")) { | ||
const phoneNumber = attributeValue("phone_number", user.Attributes); | ||
if (phoneNumber) { | ||
return { | ||
AttributeName: "phone_number", | ||
DeliveryMedium: "SMS", | ||
Destination: phoneNumber, | ||
}; | ||
} | ||
} | ||
|
||
if (desiredDeliveryMediums.includes("email")) { | ||
const email = attributeValue("email", user.Attributes); | ||
if (email) { | ||
return { | ||
AttributeName: "email", | ||
DeliveryMedium: "EMAIL", | ||
Destination: email, | ||
}; | ||
} | ||
} | ||
|
||
return null; | ||
}; |
Oops, something went wrong.