Skip to content

Commit

Permalink
AUT-2760 add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VladGavrilet committed May 29, 2024
1 parent 132302a commit 48a4cfd
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 52 deletions.
48 changes: 48 additions & 0 deletions src/components/common/state-machine/tests/state-machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@ describe("state-machine", () => {

expect(nextState.value).to.equal(PATH_NAMES.PROVE_IDENTITY_WELCOME);
});

it(`should move from ${PATH_NAMES.AUTHORIZE} to ${PATH_NAMES.PROVE_IDENTITY}`, () => {
const nextState = getNextState(
PATH_NAMES.AUTHORIZE,
USER_JOURNEY_EVENTS.EXISTING_SESSION,
{
isIdentityRequired: true,
proveIdentityWelcomeEnabled: false,
}
);

expect(nextState.value).to.equal(PATH_NAMES.PROVE_IDENTITY);
});
it(`should stay on ${PATH_NAMES.AUTHORIZE}`, () => {
const nextState = getNextState(
PATH_NAMES.AUTHORIZE,
USER_JOURNEY_EVENTS.EXISTING_SESSION,
{ isIdentityRequired: false, proveIdentityWelcomeEnabled: false }
);
expect(nextState.value).to.equal(PATH_NAMES.AUTHORIZE);
});
it(`should move from ${PATH_NAMES.AUTHORIZE} to ${PATH_NAMES.ENTER_EMAIL_SIGN_IN}`, () => {
const nextState = getNextState(
PATH_NAMES.AUTHORIZE,
USER_JOURNEY_EVENTS.EXISTING_SESSION,
{
isIdentityRequired: true,
proveIdentityWelcomeEnabled: false,
isAuthenticated: true,
isReauthenticationRequired: true,
}
);
expect(nextState.value).to.equal(PATH_NAMES.ENTER_EMAIL_SIGN_IN);
});
it(`should move from ${PATH_NAMES.AUTHORIZE} to ${PATH_NAMES.PROVE_IDENTITY}`, () => {
const nextState = getNextState(
PATH_NAMES.AUTHORIZE,
USER_JOURNEY_EVENTS.EXISTING_SESSION,
{
isIdentityRequired: true,
isAuthenticated: true,
isReauthenticationRequired: false,
proveIdentityWelcomeEnabled: false,
}
);
expect(nextState.value).to.equal(PATH_NAMES.PROVE_IDENTITY);
});
});
});

Expand Down Expand Up @@ -89,6 +136,7 @@ describe("state-machine", () => {
expect(nextState.value).to.equal(PATH_NAMES.AUTH_CODE);
});
});

describe("getNextState - login journey (non 2fa)", () => {
it("should move from initial state to sign or create when user event is landing", () => {
const nextState = getNextState(PATH_NAMES.ROOT, USER_JOURNEY_EVENTS.ROOT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,76 +12,81 @@ import {
} from "../prove-identity-welcome-controller";
import { createMockRequest } from "../../../../test/helpers/mock-request-helper";
import { proveIdentityWelcomeEnabled } from "../../../config";
if (proveIdentityWelcomeEnabled()) {
describe("prove your identity welcome controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

const STATE = "ndhd7d7d";

beforeEach(() => {
req = createMockRequest(PATH_NAMES.PROVE_IDENTITY_WELCOME);
req.session.client = {
redirectUri: "http://someservice.com/auth",
state: STATE,
};
res = mockResponse();
});

afterEach(() => {
sinon.restore();
});
describe("prove your identity welcome controller", () => {
let req: RequestOutput;
let res: ResponseOutput;

describe("proveIdentityWelcomeGet", () => {
it("should render prove your identity welcome page", async () => {
proveIdentityWelcomeGet(req as Request, res as Response);
const STATE = "ndhd7d7d";

beforeEach(() => {
req = createMockRequest(PATH_NAMES.PROVE_IDENTITY_WELCOME);
req.session.client = {
redirectUri: "http://someservice.com/auth",
state: STATE,
};
res = mockResponse();
});

afterEach(() => {
sinon.restore();
});

describe("proveIdentityWelcomeGet", () => {
it("should render prove your identity welcome page or redirect to sign-in-or-create", async () => {
proveIdentityWelcomeGet(req as Request, res as Response);
if (proveIdentityWelcomeEnabled()) {
expect(res.render).to.have.been.calledWith(
"prove-identity-welcome/index.njk"
);
});

it("should render prove identity welcome page for user that already has an active session", async () => {
req.session.user.isAuthenticated = true;
proveIdentityWelcomeGet(req as Request, res as Response);
} else {
expect(res.redirect).to.have.been.calledWith(
PATH_NAMES.SIGN_IN_OR_CREATE
);
}
});

it("should render prove identity welcome page for user that already has an active session", async () => {
req.session.user.isAuthenticated = true;
proveIdentityWelcomeGet(req as Request, res as Response);
if (proveIdentityWelcomeEnabled()) {
expect(res.render).to.have.been.calledWith(
"prove-identity-welcome/index-existing-session.njk"
);
});
}
});
});

describe("proveIdentityWelcomePost", () => {
it("should redirect to sign in or create when user not authenticated", async () => {
await proveIdentityWelcomePost(req as Request, res as Response);
describe("proveIdentityWelcomePost", () => {
it("should redirect to sign in or create when user not authenticated", async () => {
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(
PATH_NAMES.SIGN_IN_OR_CREATE
);
});
expect(res.redirect).to.have.been.calledWith(
PATH_NAMES.SIGN_IN_OR_CREATE
);
});

it("should redirect to prove your identity when user is authenticated", async () => {
req.session.user.isAuthenticated = true;
await proveIdentityWelcomePost(req as Request, res as Response);
it("should redirect to prove your identity when user is authenticated", async () => {
req.session.user.isAuthenticated = true;
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.PROVE_IDENTITY);
});
expect(res.redirect).to.have.been.calledWith(PATH_NAMES.PROVE_IDENTITY);
});

it("should redirect to uplift journey when user is required to step up auth", async () => {
req.session.user.isAuthenticated = true;
req.session.user.isUpliftRequired = true;
await proveIdentityWelcomePost(req as Request, res as Response);
it("should redirect to uplift journey when user is required to step up auth", async () => {
req.session.user.isAuthenticated = true;
req.session.user.isUpliftRequired = true;
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.UPLIFT_JOURNEY);
});
expect(res.redirect).to.have.been.calledWith(PATH_NAMES.UPLIFT_JOURNEY);
});

it("should redirect to enter password when user is required to login (prompt=LOGIN)", async () => {
req.session.user.isAuthenticated = true;
req.session.client.prompt = OIDC_PROMPT.LOGIN;
await proveIdentityWelcomePost(req as Request, res as Response);
it("should redirect to enter password when user is required to login (prompt=LOGIN)", async () => {
req.session.user.isAuthenticated = true;
req.session.client.prompt = OIDC_PROMPT.LOGIN;
await proveIdentityWelcomePost(req as Request, res as Response);

expect(res.redirect).to.have.been.calledWith(PATH_NAMES.ENTER_PASSWORD);
});
expect(res.redirect).to.have.been.calledWith(PATH_NAMES.ENTER_PASSWORD);
});
});
}
});

0 comments on commit 48a4cfd

Please sign in to comment.