-
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): adminConfirmSignUp full support
- Loading branch information
Showing
16 changed files
with
287 additions
and
59 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,43 @@ | ||
import { withCognitoSdk } from "./setup"; | ||
|
||
describe( | ||
"CognitoIdentityServiceProvider.adminConfirmSignUp", | ||
withCognitoSdk((Cognito) => { | ||
it("creates a user with only the required parameters", async () => { | ||
const client = Cognito(); | ||
|
||
await client | ||
.adminCreateUser({ | ||
UserAttributes: [{ Name: "phone_number", Value: "0400000000" }], | ||
Username: "abc", | ||
UserPoolId: "test", | ||
}) | ||
.promise(); | ||
|
||
let user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
expect(user.UserStatus).toEqual("FORCE_CHANGE_PASSWORD"); | ||
|
||
await client | ||
.adminConfirmSignUp({ | ||
UserPoolId: "test", | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
user = await client | ||
.adminGetUser({ | ||
UserPoolId: "test", | ||
Username: "abc", | ||
}) | ||
.promise(); | ||
|
||
expect(user.UserStatus).toEqual("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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,7 @@ describe( | |
aud: upc.UserPoolClient?.ClientId, | ||
auth_time: expect.any(Number), | ||
email: "[email protected]", | ||
email_verified: true, | ||
email_verified: false, | ||
event_id: expect.stringMatching(UUID), | ||
exp: expect.any(Number), | ||
iat: expect.any(Number), | ||
|
@@ -245,7 +245,7 @@ describe( | |
aud: upc.UserPoolClient?.ClientId, | ||
auth_time: expect.any(Number), | ||
email: "[email protected]", | ||
email_verified: true, | ||
email_verified: false, | ||
event_id: expect.stringMatching(UUID), | ||
exp: expect.any(Number), | ||
iat: expect.any(Number), | ||
|
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
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,121 @@ | ||
import { ClockFake } from "../__tests__/clockFake"; | ||
import { newMockCognitoService } from "../__tests__/mockCognitoService"; | ||
import { newMockTriggers } from "../__tests__/mockTriggers"; | ||
import { newMockUserPoolService } from "../__tests__/mockUserPoolService"; | ||
import { TestContext } from "../__tests__/testContext"; | ||
import * as TDB from "../__tests__/testDataBuilder"; | ||
import { NotAuthorizedError } from "../errors"; | ||
import { Triggers, UserPoolService } from "../services"; | ||
import { attribute, attributesAppend } from "../services/userPoolService"; | ||
import { | ||
AdminConfirmSignUp, | ||
AdminConfirmSignUpTarget, | ||
} from "./adminConfirmSignUp"; | ||
|
||
const currentDate = new Date(); | ||
|
||
const clock = new ClockFake(currentDate); | ||
|
||
describe("AdminConfirmSignUp target", () => { | ||
let adminConfirmSignUp: AdminConfirmSignUpTarget; | ||
let mockUserPoolService: jest.Mocked<UserPoolService>; | ||
let mockTriggers: jest.Mocked<Triggers>; | ||
|
||
beforeEach(() => { | ||
mockUserPoolService = newMockUserPoolService(); | ||
mockTriggers = newMockTriggers(); | ||
adminConfirmSignUp = AdminConfirmSignUp({ | ||
clock, | ||
cognito: newMockCognitoService(mockUserPoolService), | ||
triggers: mockTriggers, | ||
}); | ||
}); | ||
|
||
it("throws if the user doesn't exist", async () => { | ||
mockUserPoolService.getUserByUsername.mockResolvedValue(null); | ||
|
||
await expect( | ||
adminConfirmSignUp(TestContext, { | ||
ClientMetadata: { | ||
client: "metadata", | ||
}, | ||
Username: "invalid user", | ||
UserPoolId: "test", | ||
}) | ||
).rejects.toEqual(new NotAuthorizedError()); | ||
}); | ||
|
||
it("updates the user's status", async () => { | ||
const user = TDB.user(); | ||
|
||
mockUserPoolService.getUserByUsername.mockResolvedValue(user); | ||
|
||
await adminConfirmSignUp(TestContext, { | ||
ClientMetadata: { | ||
client: "metadata", | ||
}, | ||
Username: user.Username, | ||
UserPoolId: "test", | ||
}); | ||
|
||
expect(mockUserPoolService.saveUser).toHaveBeenCalledWith(TestContext, { | ||
...user, | ||
UserLastModifiedDate: currentDate, | ||
UserStatus: "CONFIRMED", | ||
}); | ||
}); | ||
|
||
describe("when PostConfirmation trigger is enabled", () => { | ||
it("invokes the trigger", async () => { | ||
mockTriggers.enabled.mockImplementation( | ||
(trigger) => trigger === "PostConfirmation" | ||
); | ||
|
||
const user = TDB.user(); | ||
|
||
mockUserPoolService.getUserByUsername.mockResolvedValue(user); | ||
|
||
await adminConfirmSignUp(TestContext, { | ||
ClientMetadata: { | ||
client: "metadata", | ||
}, | ||
Username: user.Username, | ||
UserPoolId: "test", | ||
}); | ||
|
||
expect(mockTriggers.postConfirmation).toHaveBeenCalledWith(TestContext, { | ||
clientId: null, | ||
clientMetadata: { | ||
client: "metadata", | ||
}, | ||
source: "PostConfirmation_ConfirmSignUp", | ||
userAttributes: attributesAppend( | ||
user.Attributes, | ||
attribute("cognito:user_status", "CONFIRMED") | ||
), | ||
userPoolId: "test", | ||
username: user.Username, | ||
}); | ||
}); | ||
}); | ||
|
||
describe("when PostConfirmation trigger is not enabled", () => { | ||
it("invokes the trigger", async () => { | ||
mockTriggers.enabled.mockReturnValue(false); | ||
|
||
const user = TDB.user(); | ||
|
||
mockUserPoolService.getUserByUsername.mockResolvedValue(user); | ||
|
||
await adminConfirmSignUp(TestContext, { | ||
ClientMetadata: { | ||
client: "metadata", | ||
}, | ||
Username: user.Username, | ||
UserPoolId: "test", | ||
}); | ||
|
||
expect(mockTriggers.postConfirmation).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.