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(api): support for DeleteUserPool
- Loading branch information
Showing
9 changed files
with
137 additions
and
7 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,41 @@ | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.deleteUserPool", | ||
withCognitoSdk((Cognito) => { | ||
it("deletes a group", async () => { | ||
const client = Cognito(); | ||
|
||
// create the user pool | ||
const up = await client | ||
.createUserPool({ | ||
PoolName: "newPool", | ||
}) | ||
.promise(); | ||
|
||
const listResponse = await client | ||
.listUserPools({ | ||
MaxResults: 1, | ||
}) | ||
.promise(); | ||
|
||
expect(listResponse.UserPools).toEqual([ | ||
expect.objectContaining({ | ||
Id: up.UserPool?.Id, | ||
}), | ||
]); | ||
|
||
await client | ||
.deleteUserPool({ | ||
UserPoolId: up.UserPool?.Id!, | ||
}) | ||
.promise(); | ||
|
||
const listResponseAfter = await client | ||
.listUserPools({ MaxResults: 1 }) | ||
.promise(); | ||
|
||
expect(listResponseAfter.UserPools).toHaveLength(0); | ||
}); | ||
}) | ||
); |
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
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,38 @@ | ||
import { newMockCognitoService } from "../__tests__/mockCognitoService"; | ||
import { newMockUserPoolService } from "../__tests__/mockUserPoolService"; | ||
import { TestContext } from "../__tests__/testContext"; | ||
import * as TDB from "../__tests__/testDataBuilder"; | ||
import { CognitoService } from "../services"; | ||
import { DeleteUserPool, DeleteUserPoolTarget } from "./deleteUserPool"; | ||
|
||
describe("DeleteUserPool target", () => { | ||
let deleteUserPool: DeleteUserPoolTarget; | ||
let mockCognitoService: jest.Mocked<CognitoService>; | ||
|
||
beforeEach(() => { | ||
mockCognitoService = newMockCognitoService(newMockUserPoolService()); | ||
|
||
deleteUserPool = DeleteUserPool({ | ||
cognito: mockCognitoService, | ||
}); | ||
}); | ||
|
||
it("deletes a user pool client", async () => { | ||
const userPool = TDB.userPool(); | ||
|
||
mockCognitoService.getUserPool.mockResolvedValue( | ||
newMockUserPoolService(userPool) | ||
); | ||
|
||
await deleteUserPool(TestContext, { | ||
UserPoolId: "test", | ||
}); | ||
|
||
expect(mockCognitoService.deleteUserPool).toHaveBeenCalledWith( | ||
TestContext, | ||
userPool | ||
); | ||
}); | ||
|
||
it.todo("throws if the user pool 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,22 @@ | ||
import { DeleteUserPoolRequest } from "aws-sdk/clients/cognitoidentityserviceprovider"; | ||
import { ResourceNotFoundError } from "../errors"; | ||
import { Services } from "../services"; | ||
import { Target } from "./Target"; | ||
|
||
export type DeleteUserPoolTarget = Target<DeleteUserPoolRequest, {}>; | ||
|
||
type DeleteUserPoolServices = Pick<Services, "cognito">; | ||
|
||
export const DeleteUserPool = | ||
({ cognito }: DeleteUserPoolServices): DeleteUserPoolTarget => | ||
async (ctx, req) => { | ||
// TODO: from the docs "Calling this action requires developer credentials.", can we enforce this? | ||
const userPool = await cognito.getUserPool(ctx, req.UserPoolId); | ||
if (!userPool) { | ||
throw new ResourceNotFoundError(); | ||
} | ||
|
||
await cognito.deleteUserPool(ctx, userPool.config); | ||
|
||
return {}; | ||
}; |
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