-
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.
- Loading branch information
Showing
31 changed files
with
1,596 additions
and
75 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,86 @@ | ||
import { ClockFake } from "../../src/__tests__/clockFake"; | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
const originalDate = new Date(); | ||
const roundedDate = new Date(originalDate.getTime()); | ||
roundedDate.setMilliseconds(0); | ||
|
||
const clock = new ClockFake(originalDate); | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.adminListGroupsForUser", | ||
withCognitoSdk( | ||
(Cognito) => { | ||
it("lists groups for a user", async () => { | ||
const client = Cognito(); | ||
|
||
const createGroupResponse = await client | ||
.createGroup({ | ||
GroupName: "group-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminCreateUser({ | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
TemporaryPassword: "def", | ||
UserAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
Username: "user-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminAddUserToGroup({ | ||
Username: "user-1", | ||
GroupName: "group-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
const result = await client | ||
.adminListGroupsForUser({ | ||
UserPoolId: "test", | ||
Username: "user-1", | ||
}) | ||
.promise(); | ||
|
||
expect(result.Groups).toEqual([createGroupResponse.Group]); | ||
}); | ||
|
||
it("lists groups for an unassigned user", async () => { | ||
const client = Cognito(); | ||
|
||
await client | ||
.createGroup({ | ||
GroupName: "group-2", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminCreateUser({ | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
TemporaryPassword: "def", | ||
UserAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
Username: "user-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
const result = await client | ||
.adminListGroupsForUser({ | ||
UserPoolId: "test", | ||
Username: "user-1", | ||
}) | ||
.promise(); | ||
|
||
expect(result.Groups).toHaveLength(0); | ||
}); | ||
}, | ||
{ | ||
clock, | ||
} | ||
) | ||
); |
73 changes: 73 additions & 0 deletions
73
integration-tests/aws-sdk/adminRemoveUserFromGroup.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,73 @@ | ||
import { ClockFake } from "../../src/__tests__/clockFake"; | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
const originalDate = new Date(); | ||
const roundedDate = new Date(originalDate.getTime()); | ||
roundedDate.setMilliseconds(0); | ||
|
||
const clock = new ClockFake(originalDate); | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.adminRemoveUserFromGroup", | ||
withCognitoSdk( | ||
(Cognito) => { | ||
it("lists groups for a user", async () => { | ||
const client = Cognito(); | ||
|
||
const createGroupResponse = await client | ||
.createGroup({ | ||
GroupName: "group-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminCreateUser({ | ||
DesiredDeliveryMediums: ["EMAIL"], | ||
TemporaryPassword: "def", | ||
UserAttributes: [{ Name: "email", Value: "[email protected]" }], | ||
Username: "user-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await client | ||
.adminAddUserToGroup({ | ||
Username: "user-1", | ||
GroupName: "group-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
const result = await client | ||
.adminListGroupsForUser({ | ||
UserPoolId: "test", | ||
Username: "user-1", | ||
}) | ||
.promise(); | ||
|
||
expect(result.Groups).toEqual([createGroupResponse.Group]); | ||
|
||
await client | ||
.adminRemoveUserFromGroup({ | ||
Username: "user-1", | ||
GroupName: "group-1", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
const resultAfterRemove = await client | ||
.adminListGroupsForUser({ | ||
UserPoolId: "test", | ||
Username: "user-1", | ||
}) | ||
.promise(); | ||
|
||
expect(resultAfterRemove.Groups).toHaveLength(0); | ||
}); | ||
}, | ||
{ | ||
clock, | ||
} | ||
) | ||
); |
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.deleteGroup", | ||
withCognitoSdk((Cognito) => { | ||
it("deletes a group", async () => { | ||
const client = Cognito(); | ||
|
||
await client | ||
.createGroup({ | ||
GroupName: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
const getGroupResponse = await client | ||
.getGroup({ | ||
GroupName: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
expect(getGroupResponse.Group).toBeDefined(); | ||
|
||
await client | ||
.deleteGroup({ | ||
GroupName: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
await expect( | ||
client | ||
.getGroup({ | ||
GroupName: "abc", | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ClockFake } from "../../src/__tests__/clockFake"; | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
const currentDate = new Date(); | ||
const roundedDate = new Date(currentDate.getTime()); | ||
roundedDate.setMilliseconds(0); | ||
|
||
const clock = new ClockFake(currentDate); | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.getGroup", | ||
withCognitoSdk( | ||
(Cognito) => { | ||
it("get a group", async () => { | ||
const client = Cognito(); | ||
|
||
await client | ||
.createGroup({ | ||
Description: "Description", | ||
GroupName: "abc", | ||
Precedence: 1, | ||
RoleArn: "arn", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
const getGroupResponse = await client | ||
.getGroup({ | ||
GroupName: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
expect(getGroupResponse.Group).toEqual({ | ||
CreationDate: roundedDate, | ||
Description: "Description", | ||
GroupName: "abc", | ||
LastModifiedDate: roundedDate, | ||
Precedence: 1, | ||
RoleArn: "arn", | ||
UserPoolId: "test", | ||
}); | ||
}); | ||
}, | ||
{ | ||
clock, | ||
} | ||
) | ||
); |
Oops, something went wrong.