Skip to content

Commit

Permalink
fix(fe:FSADT1-1292): validate individual (#922)
Browse files Browse the repository at this point in the history
Co-authored-by: Paulo Gomes da Cruz Junior <[email protected]>
  • Loading branch information
fterra-encora and paulushcgcj authored Apr 12, 2024
1 parent dac0e2c commit e51876a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const checkForIndividualValid = (lastName: string) => {
validation.business = false;
toggleErrorMessages(null, true, null);
generalErrorBus.emit(watchValue.response?.data ?? "");
}else{
} else if (watchValue.response?.status === 404) {
validation.individual = true;
}
});
Expand Down
95 changes: 89 additions & 6 deletions frontend/tests/pages/bceid/BusinessInformationWizardStep.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const global = {
},
};

let individualStatusCode: number;

describe('<BusinessInformationWizardStep />', () => {

beforeEach(() => {
individualStatusCode = 200;

cy.intercept("/api/clients/name/*", {
fixture: "business.json",
}).as("searchCompany");
Expand Down Expand Up @@ -67,14 +71,18 @@ describe('<BusinessInformationWizardStep />', () => {
},
}).as("getClientType");

cy.intercept("GET", "/api/clients/individual/mockUserId?lastName=Doe", {
statusCode: 200,
delay: 10,
cy.intercept("GET", "/api/clients/individual/mockUserId?lastName=Doe", (req) => {
req.reply({
statusCode: individualStatusCode,
delay: 10,
});
}).as("checkIndividualUser");

cy.intercept("GET", "/api/clients/individual/mockUserId?lastName=Else", {
statusCode: 200,
delay: 10,
cy.intercept("GET", "/api/clients/individual/mockUserId?lastName=Else", (req) => {
req.reply({
statusCode: individualStatusCode,
delay: 10,
});
}).as("checkIndividualElse");
});

Expand Down Expand Up @@ -227,6 +235,81 @@ describe('<BusinessInformationWizardStep />', () => {
cy.get("cds-inline-notification").should("not.exist");
});

describe("individual validation", () => {
let callsSetIndividualValidInd = [];
const individualValidWrapper = {
individualValidInd: false,
};
const functionWrapper = {
setIndividualValidInd: (value: boolean) => {
individualValidWrapper.individualValidInd = value;
callsSetIndividualValidInd.push(value);
},
};
const { setIndividualValidInd } = functionWrapper;
beforeEach(() => {
individualValidWrapper.individualValidInd = false;
callsSetIndividualValidInd = [];

cy.mount(BusinessInformationWizardStep, {
props: {
data: {
businessInformation: {
businessType: "",
legalType: "",
clientType: "",
registrationNumber: "",
businessName: "",
goodStandingInd: "",
birthdate: "",
address: "",
},
location: {
contacts: [
{
email: "[email protected]",
firstName: "John",
},
],
},
} as unknown as FormDataDto,
districtsList: districts,
active: false,
individualValidInd: individualValidWrapper.individualValidInd,
setIndividualValidInd,
},
global,
});
});
interface Scenario {
statusCode: number;
valid: boolean;
};
const scenarios: Scenario[] = [
{ statusCode: 200, valid: true },
{ statusCode: 404, valid: true },
{ statusCode: 409, valid: false },
{ statusCode: 400, valid: false },
{ statusCode: 403, valid: false },
{ statusCode: 500, valid: false },
{ statusCode: 503, valid: false },
];
scenarios.forEach((scenario) => {
describe(`when response is ${scenario.statusCode}`, () => {
beforeEach(() => {
individualStatusCode = scenario.statusCode;
});
it(`should set valid to: ${scenario.valid}`, () => {
cy.get("#businessTyperbU").click();
cy.wait("@checkIndividualUser");
cy.wrap(individualValidWrapper).should(({ individualValidInd }) => {
expect(individualValidInd).to.equal(scenario.valid);
});
})
});
});
});

describe("when a Registered individual business gets selected", () => {
let callsSetIndividualValidInd = [];
const functionWrapper = {
Expand Down

0 comments on commit e51876a

Please sign in to comment.