/** * Giving the investment-licence route back. * * A company that ticked the box by mistake, or that has since been registered * with the trade registry, switches from Settings → Company. It is a * re-application rather than a settings edit, and this spec is about proving * that literally: the typed registration is cleared (nothing on file was ever * checked against a licence), the company returns to pending, onboarding * reopens on the company step — and only after a real eTrade lookup does the * backoffice stop flagging it. * * Each test is one leg of a single journey, in order, retries off. The * portal ↔ backoffice hops re-evaluate the spec bundle, so every leg resolves * the company from the database rather than from module state. */ import { approveFirstProfile, companyByEmail, completeInvestorOnboarding, etradeTin, expectProfileActive, fillAria, latestJourney, openCustomer, signupIdentity, wizardClick, SIGNUP_PASSWORD, } from "./onboarding-utils"; const stamp = Date.now(); const who = signupIdentity("switchback", stamp); describe("onboarding — switching back to eTrade registration", { retries: 0 }, () => { it("onboards on an investment licence", () => { completeInvestorOnboarding(who, stamp, { companyName: `E2E Switchback Trading ${stamp}`, }); companyByEmail(who.email).then((company) => { expect((company.attributes ?? {})["investorLicence"]).to.eq(true); expect(company.region, "typed address").to.eq("Addis Ababa"); }); }); it("is approved by the backoffice", () => { cy.loginBackoffice("chief@edr.local"); latestJourney("switchback").then((company) => { openCustomer(company.name); cy.contains("Manual entry · investment licence").should("be.visible"); approveFirstProfile(); expectProfileActive(company.name); }); }); it("switches back from settings, which clears the typed registration", () => { latestJourney("switchback").then((company) => { cy.loginPortal(company.email, SIGNUP_PASSWORD); }); cy.visitPortal("/settings"); cy.contains("Registration source", { timeout: 20000 }).should("be.visible"); cy.contains("button", "Switch to eTrade registration").click(); // The confirmation has to state the cost outright — this is the screen // that decides whether the customer knows they are re-applying. cy.contains("Switch to eTrade registration?").should("be.visible"); cy.contains("The registration details you typed are cleared").should( "be.visible", ); cy.contains("Your company goes back to pending").should("be.visible"); cy.contains("button", "Switch and re-apply").click(); cy.contains("Registration source", { timeout: 20000 }).should("not.exist"); latestJourney("switchback").then((company) => { expect((company.attributes ?? {})["investorLicence"]).to.be.undefined; expect(company.status).to.eq("pending"); expect(company.onboarding_completed).to.eq(false); // The wizard treats a populated registration as a lookup that already // passed, so leaving any of it behind would walk the customer straight // past the eTrade step this switch exists to reach. expect(company.region, "typed address cleared").to.be.null; expect(company.licence_number).to.be.null; expect(company.etrade_phone).to.be.null; expect(company.onboarding_step, "resume target").to.eq("company"); }); }); it("re-runs onboarding through eTrade and resubmits", () => { latestJourney("switchback").then((company) => { cy.loginPortal(company.email, SIGNUP_PASSWORD); }); cy.visitPortal("/portal"); // Reopened on the company step — not on the furthest step reached before. cy.contains("Confirm your VAT number", { timeout: 30000 }).should( "be.visible", ); // The typed registration section is gone: this is an ordinary company now. cy.contains("Nothing on file at eTrade for this TIN").should("not.exist"); fillAria('[aria-label^="TIN Number"]', etradeTin(stamp)); cy.contains("Verified with eTrade", { timeout: 20000 }).should("be.visible"); cy.wait(500); wizardClick("Continue"); // Owner, representation and contact are already satisfied server-side — // the switch keeps everything except the registration — so each step only // needs advancing. cy.contains("Company Owner", { timeout: 20000 }).should("be.visible"); wizardClick("Continue"); cy.contains("The owner acts for the company", { timeout: 20000 }).should( "be.visible", ); wizardClick("Continue"); cy.contains("Contact Person", { timeout: 20000 }).should("be.visible"); wizardClick("Continue"); // Documents and the licence were uploaded before the switch and survive // it, so the step is already satisfied. cy.contains("Upload Importer Business license file(s)", { timeout: 20000, }).should("be.visible"); wizardClick("Submit for review"); cy.contains("You're all set", { timeout: 30000 }).should("be.visible"); latestJourney("switchback").then((company) => { expect(company.onboarding_completed).to.eq(true); expect((company.attributes ?? {})["investorLicence"]).to.be.undefined; // eTrade answered this time, and its licence is on file. expect(company.licence_number).to.eq("LIC-E2E-0001"); }); }); it("the backoffice no longer flags it", () => { cy.loginBackoffice("chief@edr.local"); latestJourney("switchback").then((company) => { openCustomer(company.name); cy.contains("eTrade trade licence").should("be.visible"); cy.contains("Manual entry").should("not.exist"); cy.contains("Registration entered by hand").should("not.exist"); }); }); it("offers nothing to switch to a customer who came through eTrade", () => { // The seeded demo customer onboarded the ordinary way, so the card must // not be on its settings page at all. cy.loginPortal(); cy.visitPortal("/settings"); cy.contains("Operational Services", { timeout: 20000 }).should("be.visible"); cy.contains("Registration source").should("not.exist"); }); }); export {};