// Stand-in for https://etrade.gov.et in the e2e stack. ETradeService's base // URL is hardcoded (apps/edr-freight-api/src/modules/companies/services/etrade.service.ts), // not env-configurable, so this is reached by aliasing this container AS // "etrade.gov.et" on the compose network (see docker-compose.e2e.yaml) rather // than by pointing an env var here. HTTPS because the real service is HTTPS // — the cert itself only needs to exist, never be trusted, since // ETradeService's httpsAgent sets rejectUnauthorized:false. The compose // service's command generates a throwaway self-signed cert into // TLS_CERT_PATH/TLS_KEY_PATH before starting this — nothing shaped like a // key/cert is committed here. // // Every TIN resolves to the same canned company — these specs don't care // about per-TIN business logic, only that the lookup succeeds so the rest // of the company-info form (name, address, manager) auto-fills instead of // staying gated behind a "No matching business record" alert. const https = require("node:https"); const fs = require("node:fs"); const PORT = process.env.PORT || 443; const options = { key: fs.readFileSync(process.env.TLS_KEY_PATH || "/tmp/etrade-mock/key.pem"), cert: fs.readFileSync( process.env.TLS_CERT_PATH || "/tmp/etrade-mock/cert.pem", ), }; function companyInfo(tin) { return { Tin: tin, LegalCondtion: "Private Limited Company", RegNo: "REG-E2E-0001", RegDate: "2020-01-01", // Embeds the (per-run-unique) TIN rather than a static name — specs // that look a company up by name (e.g. onboarding.cy.ts) need this to // stay unique across repeated e2e runs against the same warm DB, same // as it would be if the customer had typed a real company name. BusinessName: `E2E Mock Trading PLC ${tin}`, BusinessNameAmh: "ኢቱኢ ሞክ ትሬዲንግ", PaidUpCapital: 100000, AssociateShortInfos: [], Businesses: [ { MainGuid: "e2e-guid-0001", OwnerTIN: tin, DateRegistered: "2020-01-01", TradeNameAmh: "ኢቱኢ", TradesName: "E2E Mock Trading", LicenceNumber: "LIC-E2E-0001", RenewalDate: "2026-01-01", RenewedFrom: "2025-01-01", RenewedTo: "2027-01-01", BusinessLicensingGroupMain: null, SubGroups: null, }, ], }; } function businessInfo(tin) { return { MainGuid: "e2e-guid-0001", OwnerTIN: tin, DateRegistered: "2020-01-01", TradeName: "E2E Mock Trading", LicenceNumber: "LIC-E2E-0001", Status: 1, StatusDescription: "Active", Capital: 100000, AssociateShortInfos: [ { Position: "Manager", ManagerName: "አበበ በቀለ", ManagerNameEng: "Abebe Bekele", Photo: null, MobilePhone: "+251911223344", RegularPhone: null, }, ], AddressInfo: { Region: "ADDIS ABABA", Zone: "Zone 1", Woreda: "Woreda 1", Kebele: "Kebele 1", HouseNo: "123", MobilePhone: "+251911223344", RegularPhone: "", }, RenewedTo: "2027-01-01", RenewedToDateString: "2027-01-01", RenewalDate: "2026-01-01", RenewedFrom: "2025-01-01", CancellationDate: null, }; } const server = https.createServer(options, (req, res) => { const url = new URL(req.url, `https://${req.headers.host}`); const regMatch = url.pathname.match( /^\/api\/Registration\/GetRegistrationInfoByTin\/([^/]+)\/en$/, ); if (req.method === "GET" && regMatch) { res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(companyInfo(regMatch[1]))); return; } if ( req.method === "GET" && url.pathname === "/api/BusinessMain/GetBusinessByLicenseNo" ) { const tin = url.searchParams.get("Tin") || ""; res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(businessInfo(tin))); return; } res.writeHead(404).end(); }); server.listen(PORT, () => { console.log(`etrade-mock listening on ${PORT}`); });