// Verifies signUp/confirmSignUp/resendConfirmationCode build correct Cognito IDP requests. // Mocks cognitoFetch to assert request construction, not Cognito behavior. jest.mock("../cognito/cognito-fetch"); import { cognitoFetch } from "../cognito/cognito-fetch"; import { signUp, confirmSignUp, resendConfirmationCode } from "../"; const mockedFetch = cognitoFetch as jest.MockedFunction; const region = "us-west-2"; const clientId = "test-client-id"; const username = "jan@xcspec.com"; beforeEach(() => { mockedFetch.mockReset(); mockedFetch.mockResolvedValue({} as any); }); describe("signUp", () => { it("builds a SignUp request with password and user attributes", async () => { await signUp({ region, clientId, username, password: "S3cret!pass", userAttributes: [ { Name: "email", Value: username }, { Name: "custom:orgId", Value: "org-123" }, ], }); expect(mockedFetch).toHaveBeenCalledTimes(1); const call = mockedFetch.mock.calls[0][0]; expect(call.region).toBe(region); expect(call.operation).toBe("SignUp"); expect(call.args).toEqual({ ClientId: clientId, Username: username, Password: "S3cret!pass", UserAttributes: [ { Name: "email", Value: username }, { Name: "custom:orgId", Value: "org-123" }, ], }); }); it("omits UserAttributes and includes ClientMetadata when given", async () => { await signUp({ region, clientId, username, password: "S3cret!pass", clientMetadata: { source: "rn-app" }, }); const call = mockedFetch.mock.calls[0][0]; expect(call.args).toEqual({ ClientId: clientId, Username: username, Password: "S3cret!pass", ClientMetadata: { source: "rn-app" }, }); }); }); describe("confirmSignUp", () => { it("builds a ConfirmSignUp request with the confirmation code", async () => { await confirmSignUp({ region, clientId, username, confirmationCode: "123456", }); const call = mockedFetch.mock.calls[0][0]; expect(call.operation).toBe("ConfirmSignUp"); expect(call.args).toEqual({ ClientId: clientId, Username: username, ConfirmationCode: "123456", }); }); }); describe("resendConfirmationCode", () => { it("builds a ResendConfirmationCode request", async () => { await resendConfirmationCode({ region, clientId, username }); const call = mockedFetch.mock.calls[0][0]; expect(call.operation).toBe("ResendConfirmationCode"); expect(call.args).toEqual({ ClientId: clientId, Username: username, }); }); });