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): adminDeleteUser full support
- Loading branch information
Showing
14 changed files
with
311 additions
and
149 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,70 @@ | ||
import { ClockFake } from "../../src/__tests__/clockFake"; | ||
import { UUID } from "../../src/__tests__/patterns"; | ||
import { UserNotFoundError } from "../../src/errors"; | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
const currentDate = new Date(); | ||
const roundedDate = new Date(currentDate.getTime()); | ||
roundedDate.setMilliseconds(0); | ||
|
||
const clock = new ClockFake(currentDate); | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.adminDeleteUser", | ||
withCognitoSdk( | ||
(Cognito) => { | ||
it("deletes a user", async () => { | ||
const client = Cognito(); | ||
|
||
// create the user | ||
const createUserResult = await client | ||
.adminCreateUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
|
||
// TODO: shouldn't need to supply this | ||
TemporaryPassword: "TemporaryPassword", | ||
}) | ||
.promise(); | ||
|
||
// verify they exist | ||
const beforeUserResult = await client | ||
.adminGetUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
expect(beforeUserResult).toEqual({ | ||
Enabled: true, | ||
UserAttributes: createUserResult.User?.Attributes, | ||
UserCreateDate: createUserResult.User?.UserCreateDate, | ||
UserLastModifiedDate: createUserResult.User?.UserLastModifiedDate, | ||
Username: createUserResult.User?.Username, | ||
UserStatus: createUserResult.User?.UserStatus, | ||
}); | ||
|
||
// delete the user | ||
await client | ||
.adminDeleteUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
// verify they don't exist anymore | ||
await expect( | ||
client | ||
.adminGetUser({ | ||
Username: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise() | ||
).rejects.toEqual(new UserNotFoundError("User does not exist")); | ||
}); | ||
}, | ||
{ | ||
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,8 @@ | ||
import { DataStore } from "../services/dataStore"; | ||
|
||
export const newMockDataStore = (): jest.Mocked<DataStore> => ({ | ||
delete: jest.fn(), | ||
get: jest.fn(), | ||
getRoot: jest.fn(), | ||
set: jest.fn(), | ||
}); |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { User } from "../services/userPoolClient"; | ||
|
||
export const user = (): User => ({ | ||
Attributes: [], | ||
Enabled: true, | ||
Password: "Password123!", | ||
UserCreateDate: new Date().getTime(), | ||
UserLastModifiedDate: new Date().getTime(), | ||
Username: "Username", | ||
UserStatus: "CONFIRMED", | ||
export const user = (partial?: Partial<User>): User => ({ | ||
Attributes: partial?.Attributes ?? [], | ||
Enabled: partial?.Enabled ?? true, | ||
Password: partial?.Password ?? "Password123!", | ||
UserCreateDate: partial?.UserCreateDate ?? new Date().getTime(), | ||
UserLastModifiedDate: partial?.UserLastModifiedDate ?? new Date().getTime(), | ||
Username: partial?.Username ?? "Username", | ||
UserStatus: partial?.UserStatus ?? "CONFIRMED", | ||
}); |
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
Oops, something went wrong.