From 3f5f68dc971ebabc2eb0f5d8541a24b36d716807 Mon Sep 17 00:00:00 2001 From: Francisco Savala <99670885+franciscoSavala@users.noreply.github.com> Date: Wed, 10 Jul 2024 21:53:36 -0300 Subject: [PATCH] [#13104] Accounts request form: auto-unify country names (#13117) * Added unified countries for InstructorRequestForm * Added tests for InstructorRequestForm for unified countries * Fixed lint errors for InstructorRequestForm * Added countries and moved countrymapping * Tests Fixed --------- Co-authored-by: Francisco Savala Co-authored-by: Wei Qing <48304907+weiquu@users.noreply.github.com> Co-authored-by: Ching Ming Yuan Co-authored-by: domoberzin <74132255+domoberzin@users.noreply.github.com> --- .../instructor-request-form.component.spec.ts | 20 +++++++++++++++++++ .../instructor-request-form.component.ts | 17 ++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts index a0c9bbac2f2..ff055296c3c 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts @@ -114,4 +114,24 @@ describe('InstructorRequestFormComponent', () => { expect(accountService.createAccountRequest).toHaveBeenCalledTimes(1); expect(accountService.createAccountRequest).toHaveBeenCalledWith(expect.objectContaining(typicalCreateRequest)); }); + + it('should auto-unify country when applicable', () => { + jest.spyOn(accountService, 'createAccountRequest').mockReturnValue( + new Observable((subscriber) => { subscriber.next(); })); + const unitedStatesModel: InstructorRequestFormModel = { + ...typicalModel, + country: 'españa', + }; + const unitedStatesCreateRequest: AccountCreateRequest = { + ...typicalCreateRequest, + instructorInstitution: `${unitedStatesModel.institution}, Spain`, + }; + fillFormWith(unitedStatesModel); + component.onSubmit(); + + expect(accountService.createAccountRequest).toHaveBeenCalledTimes(1); + expect(accountService.createAccountRequest).toHaveBeenCalledWith( + expect.objectContaining(unitedStatesCreateRequest)); + }); + }); diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts index 7caa14e3bd9..a5fd36e8e38 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts @@ -115,11 +115,24 @@ export class InstructorRequestFormComponent { const name = this.name.value!.trim(); const email = this.email.value!.trim(); const comments = this.comments.value!.trim(); - + // Country Mapping + const countryMapping: { [key: string]: string } = { + 'united states': 'USA', + us: 'USA', + america: 'USA', + uk: 'United Kingdom', + deutschland: 'Germany', + 'united arab emirates': 'UAE', + españa: 'Spain', + méxico: 'Mexico', + belgië: 'Belgium', + holland: 'Netherlands', + }; // Combine country and institution const country = this.country.value!.trim(); + const mappedCountry = countryMapping[country.toLowerCase()] || country; const institution = this.institution.value!.trim(); - const combinedInstitution = `${institution}, ${country}`; + const combinedInstitution = `${institution}, ${mappedCountry}`; const requestData: AccountCreateRequest = { instructorEmail: email,