-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): listUserPools full support
- Loading branch information
Showing
9 changed files
with
202 additions
and
5 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,44 @@ | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.listUserPools", | ||
withCognitoSdk((Cognito) => { | ||
it("lists user pools", async () => { | ||
const client = Cognito(); | ||
|
||
// TODO: refactor this when we support createUserPool | ||
// right now we're relying on pools being created on-demand when a user is created | ||
await client | ||
.adminCreateUser({ | ||
Username: "abc", | ||
UserPoolId: "test-1", | ||
TemporaryPassword: "TemporaryPassword", // TODO: shouldn't need to supply this | ||
}) | ||
.promise(); | ||
await client | ||
.adminCreateUser({ | ||
Username: "abc", | ||
UserPoolId: "test-2", | ||
TemporaryPassword: "TemporaryPassword", // TODO: shouldn't need to supply this | ||
}) | ||
.promise(); | ||
await client | ||
.adminCreateUser({ | ||
Username: "abc", | ||
UserPoolId: "test-3", | ||
TemporaryPassword: "TemporaryPassword", // TODO: shouldn't need to supply this | ||
}) | ||
.promise(); | ||
|
||
const result = await client | ||
.listUserPools({ | ||
MaxResults: 10, | ||
}) | ||
.promise(); | ||
|
||
expect(result).toEqual({ | ||
UserPools: [{ Id: "test-1" }, { Id: "test-2" }, { Id: "test-3" }], | ||
}); | ||
}); | ||
}) | ||
); |
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 * as TDB from "../__tests__/testDataBuilder"; | ||
import { CognitoService } from "../services"; | ||
import { ListUserPools, ListUserPoolsTarget } from "./listUserPools"; | ||
|
||
describe("ListUserPools target", () => { | ||
let listUserPools: ListUserPoolsTarget; | ||
let mockCognitoService: jest.Mocked<CognitoService>; | ||
|
||
beforeEach(() => { | ||
mockCognitoService = newMockCognitoService(newMockUserPoolService()); | ||
listUserPools = ListUserPools({ | ||
cognito: mockCognitoService, | ||
}); | ||
}); | ||
|
||
it("lists user pools", async () => { | ||
const userPool1 = TDB.userPool(); | ||
const userPool2 = TDB.userPool(); | ||
|
||
mockCognitoService.listUserPools.mockResolvedValue([userPool1, userPool2]); | ||
|
||
const output = await listUserPools({ | ||
MaxResults: 10, | ||
}); | ||
|
||
expect(output).toBeDefined(); | ||
expect(output.UserPools).toEqual([ | ||
{ | ||
Id: userPool1.Id, | ||
}, | ||
{ | ||
Id: userPool2.Id, | ||
}, | ||
]); | ||
}); | ||
}); |
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 { | ||
ListUserPoolsRequest, | ||
ListUserPoolsResponse, | ||
} from "aws-sdk/clients/cognitoidentityserviceprovider"; | ||
import { Services } from "../services"; | ||
|
||
export type ListUserPoolsTarget = ( | ||
req: ListUserPoolsRequest | ||
) => Promise<ListUserPoolsResponse>; | ||
|
||
type ListGroupServices = Pick<Services, "cognito">; | ||
|
||
export const ListUserPools = ({ | ||
cognito, | ||
}: ListGroupServices): ListUserPoolsTarget => async () => { | ||
// TODO: NextToken support | ||
// TODO: MaxResults support | ||
|
||
const userPools = await cognito.listUserPools(); | ||
|
||
return { | ||
UserPools: userPools.map((x) => ({ | ||
Id: x.Id, | ||
// TODO: support more attributes on UserPool | ||
})), | ||
}; | ||
}; |
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