-
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): support for DeleteUserPoolClient
- Loading branch information
Showing
8 changed files
with
183 additions
and
1 deletion.
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,45 @@ | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.deleteUserPoolClient", | ||
withCognitoSdk((Cognito) => { | ||
it("deletes a group", async () => { | ||
const client = Cognito(); | ||
|
||
// create the user pool client | ||
const upc = await client | ||
.createUserPoolClient({ | ||
UserPoolId: "test", | ||
ClientName: "test", | ||
}) | ||
.promise(); | ||
|
||
const describeResponse = await client | ||
.describeUserPoolClient({ | ||
ClientId: upc.UserPoolClient?.ClientId!, | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
expect(describeResponse.UserPoolClient).toBeDefined(); | ||
|
||
await client | ||
.deleteUserPoolClient({ | ||
ClientId: upc.UserPoolClient?.ClientId!, | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await expect( | ||
client | ||
.describeUserPoolClient({ | ||
ClientId: upc.UserPoolClient?.ClientId!, | ||
UserPoolId: "test", | ||
}) | ||
.promise() | ||
).rejects.toMatchObject({ | ||
code: "ResourceNotFoundException", | ||
}); | ||
}); | ||
}) | ||
); |
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,70 @@ | ||
import { newMockCognitoService } from "../__tests__/mockCognitoService"; | ||
import { newMockUserPoolService } from "../__tests__/mockUserPoolService"; | ||
import { TestContext } from "../__tests__/testContext"; | ||
import * as TDB from "../__tests__/testDataBuilder"; | ||
import { ResourceNotFoundError } from "../errors"; | ||
import { CognitoService, UserPoolService } from "../services"; | ||
import { | ||
DeleteUserPoolClient, | ||
DeleteUserPoolClientTarget, | ||
} from "./deleteUserPoolClient"; | ||
|
||
describe("DeleteUserPoolClient target", () => { | ||
let deleteUserPoolClient: DeleteUserPoolClientTarget; | ||
let mockUserPoolService: jest.Mocked<UserPoolService>; | ||
let mockCognitoService: jest.Mocked<CognitoService>; | ||
|
||
beforeEach(() => { | ||
mockUserPoolService = newMockUserPoolService(); | ||
mockCognitoService = newMockCognitoService(mockUserPoolService); | ||
|
||
deleteUserPoolClient = DeleteUserPoolClient({ | ||
cognito: mockCognitoService, | ||
}); | ||
}); | ||
|
||
it("deletes a user pool client", async () => { | ||
const existingAppClient = TDB.appClient({ | ||
UserPoolId: "test", | ||
}); | ||
|
||
mockCognitoService.getAppClient.mockResolvedValue(existingAppClient); | ||
|
||
await deleteUserPoolClient(TestContext, { | ||
ClientId: existingAppClient.ClientId, | ||
UserPoolId: "test", | ||
}); | ||
|
||
expect(mockUserPoolService.deleteAppClient).toHaveBeenCalledWith( | ||
TestContext, | ||
existingAppClient | ||
); | ||
}); | ||
|
||
it("throws if the user pool client doesn't exist", async () => { | ||
mockCognitoService.getAppClient.mockResolvedValue(null); | ||
|
||
await expect( | ||
deleteUserPoolClient(TestContext, { | ||
ClientId: "clientId", | ||
UserPoolId: "test", | ||
}) | ||
).rejects.toEqual(new ResourceNotFoundError()); | ||
}); | ||
|
||
it("throws if the user pool client UserPoolId doesn't match the request", async () => { | ||
const existingAppClient = TDB.appClient({ | ||
ClientId: "clientId", | ||
UserPoolId: "pool-one", | ||
}); | ||
|
||
mockCognitoService.getAppClient.mockResolvedValue(existingAppClient); | ||
|
||
await expect( | ||
deleteUserPoolClient(TestContext, { | ||
ClientId: "clientId", | ||
UserPoolId: "pool-two", | ||
}) | ||
).rejects.toEqual(new ResourceNotFoundError()); | ||
}); | ||
}); |
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,27 @@ | ||
import { DeleteUserPoolClientRequest } from "aws-sdk/clients/cognitoidentityserviceprovider"; | ||
import { ResourceNotFoundError } from "../errors"; | ||
import { Services } from "../services"; | ||
import { Target } from "./Target"; | ||
|
||
export type DeleteUserPoolClientTarget = Target< | ||
DeleteUserPoolClientRequest, | ||
{} | ||
>; | ||
|
||
type DeleteUserPoolClientServices = Pick<Services, "cognito">; | ||
|
||
export const DeleteUserPoolClient = | ||
({ cognito }: DeleteUserPoolClientServices): DeleteUserPoolClientTarget => | ||
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); | ||
const appClient = await cognito.getAppClient(ctx, req.ClientId); | ||
if (!appClient || appClient.UserPoolId !== req.UserPoolId) { | ||
throw new ResourceNotFoundError(); | ||
} | ||
|
||
await userPool.deleteAppClient(ctx, appClient); | ||
|
||
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