-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): updateUserPool and describeUserPool support
- Loading branch information
Showing
9 changed files
with
208 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.updateUserPool", | ||
withCognitoSdk((Cognito) => { | ||
it("updates a user pool", async () => { | ||
const client = Cognito(); | ||
|
||
// create the user pool client | ||
const up = await client | ||
.createUserPool({ | ||
PoolName: "pool", | ||
MfaConfiguration: "OFF", | ||
}) | ||
.promise(); | ||
|
||
const describeResponse = await client | ||
.describeUserPool({ | ||
UserPoolId: up.UserPool?.Id!, | ||
}) | ||
.promise(); | ||
|
||
expect(describeResponse.UserPool).toMatchObject({ | ||
Name: "pool", | ||
MfaConfiguration: "OFF", | ||
}); | ||
|
||
await client | ||
.updateUserPool({ | ||
UserPoolId: up.UserPool?.Id!, | ||
MfaConfiguration: "OPTIONAL", | ||
}) | ||
.promise(); | ||
|
||
const describeResponseAfterUpdate = await client | ||
.describeUserPool({ | ||
UserPoolId: up.UserPool?.Id!, | ||
}) | ||
.promise(); | ||
|
||
expect(describeResponseAfterUpdate.UserPool).toMatchObject({ | ||
Name: "pool", | ||
MfaConfiguration: "OPTIONAL", | ||
}); | ||
}); | ||
}) | ||
); |
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,35 @@ | ||
import { newMockCognitoService } from "../__tests__/mockCognitoService"; | ||
import { newMockUserPoolService } from "../__tests__/mockUserPoolService"; | ||
import { TestContext } from "../__tests__/testContext"; | ||
import { CognitoService } from "../services"; | ||
import { DescribeUserPool, DescribeUserPoolTarget } from "./describeUserPool"; | ||
import * as TDB from "../__tests__/testDataBuilder"; | ||
|
||
describe("DescribeUserPool target", () => { | ||
let describeUserPool: DescribeUserPoolTarget; | ||
let mockCognitoService: jest.Mocked<CognitoService>; | ||
|
||
beforeEach(() => { | ||
mockCognitoService = newMockCognitoService(newMockUserPoolService()); | ||
describeUserPool = DescribeUserPool({ | ||
cognito: mockCognitoService, | ||
}); | ||
}); | ||
|
||
it("returns an existing user pool", async () => { | ||
const existingUserPool = TDB.userPool(); | ||
mockCognitoService.getUserPool.mockResolvedValue( | ||
newMockUserPoolService(existingUserPool) | ||
); | ||
|
||
const result = await describeUserPool(TestContext, { | ||
UserPoolId: existingUserPool.Id, | ||
}); | ||
|
||
expect(result).toEqual({ | ||
UserPool: existingUserPool, | ||
}); | ||
}); | ||
|
||
it.todo("throws resource not found for an invalid user pool"); | ||
}); |
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,26 @@ | ||
import { | ||
DescribeUserPoolRequest, | ||
DescribeUserPoolResponse, | ||
} from "aws-sdk/clients/cognitoidentityserviceprovider"; | ||
import { ResourceNotFoundError } from "../errors"; | ||
import { Services } from "../services"; | ||
import { userPoolToResponseObject } from "./responses"; | ||
import { Target } from "./Target"; | ||
|
||
export type DescribeUserPoolTarget = Target< | ||
DescribeUserPoolRequest, | ||
DescribeUserPoolResponse | ||
>; | ||
|
||
export const DescribeUserPool = | ||
({ cognito }: Pick<Services, "cognito">): DescribeUserPoolTarget => | ||
async (ctx, req) => { | ||
const userPool = await cognito.getUserPool(ctx, req.UserPoolId); | ||
if (!userPool) { | ||
throw new ResourceNotFoundError(); | ||
} | ||
|
||
return { | ||
UserPool: userPoolToResponseObject(userPool.config), | ||
}; | ||
}; |
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,43 @@ | ||
import { newMockCognitoService } from "../__tests__/mockCognitoService"; | ||
import { newMockUserPoolService } from "../__tests__/mockUserPoolService"; | ||
import { TestContext } from "../__tests__/testContext"; | ||
import * as TDB from "../__tests__/testDataBuilder"; | ||
import { CognitoService, UserPoolService } from "../services"; | ||
import { UpdateUserPool, UpdateUserPoolTarget } from "./updateUserPool"; | ||
|
||
describe("UpdateUserPool target", () => { | ||
let updateUserPool: UpdateUserPoolTarget; | ||
let mockCognitoService: jest.Mocked<CognitoService>; | ||
let mockUserPoolService: jest.Mocked<UserPoolService>; | ||
|
||
beforeEach(() => { | ||
mockUserPoolService = newMockUserPoolService(); | ||
mockCognitoService = newMockCognitoService(mockUserPoolService); | ||
|
||
updateUserPool = UpdateUserPool({ | ||
cognito: mockCognitoService, | ||
}); | ||
}); | ||
|
||
it("updates a user pool", async () => { | ||
const existingUserPool = TDB.userPool({ | ||
Name: "name", | ||
}); | ||
|
||
const userPoolService = newMockUserPoolService(existingUserPool); | ||
|
||
mockCognitoService.getUserPool.mockResolvedValue(userPoolService); | ||
|
||
await updateUserPool(TestContext, { | ||
UserPoolId: existingUserPool.Id, | ||
MfaConfiguration: "OPTIONAL", | ||
}); | ||
|
||
expect(userPoolService.update).toHaveBeenCalledWith(TestContext, { | ||
...existingUserPool, | ||
MfaConfiguration: "OPTIONAL", | ||
}); | ||
}); | ||
|
||
it.todo("throws if the user pool client doesn't exist"); | ||
}); |
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,44 @@ | ||
import { | ||
UpdateUserPoolRequest, | ||
UpdateUserPoolResponse, | ||
} from "aws-sdk/clients/cognitoidentityserviceprovider"; | ||
import { Services } from "../services"; | ||
import { UserPool } from "../services/userPoolService"; | ||
import { Target } from "./Target"; | ||
|
||
export type UpdateUserPoolTarget = Target< | ||
UpdateUserPoolRequest, | ||
UpdateUserPoolResponse | ||
>; | ||
|
||
type UpdateUserPoolServices = Pick<Services, "cognito">; | ||
|
||
export const UpdateUserPool = | ||
({ cognito }: UpdateUserPoolServices): UpdateUserPoolTarget => | ||
async (ctx, req) => { | ||
const userPool = await cognito.getUserPool(ctx, req.UserPoolId); | ||
|
||
const updatedUserPool: UserPool = { | ||
...userPool.config, | ||
AccountRecoverySetting: req.AccountRecoverySetting, | ||
AdminCreateUserConfig: req.AdminCreateUserConfig, | ||
AutoVerifiedAttributes: req.AutoVerifiedAttributes, | ||
DeviceConfiguration: req.DeviceConfiguration, | ||
EmailConfiguration: req.EmailConfiguration, | ||
EmailVerificationMessage: req.EmailVerificationMessage, | ||
EmailVerificationSubject: req.EmailVerificationSubject, | ||
LambdaConfig: req.LambdaConfig, | ||
MfaConfiguration: req.MfaConfiguration, | ||
Policies: req.Policies, | ||
SmsAuthenticationMessage: req.SmsAuthenticationMessage, | ||
SmsConfiguration: req.SmsConfiguration, | ||
SmsVerificationMessage: req.SmsVerificationMessage, | ||
UserPoolAddOns: req.UserPoolAddOns, | ||
UserPoolTags: req.UserPoolTags, | ||
VerificationMessageTemplate: req.VerificationMessageTemplate, | ||
}; | ||
|
||
await userPool.update(ctx, updatedUserPool); | ||
|
||
return {}; | ||
}; |