Skip to content

Commit

Permalink
[#13104] Accounts request form: auto-unify country names (#13117)
Browse files Browse the repository at this point in the history
* 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 <francisco.savala@mercadolibre.com>
Co-authored-by: Wei Qing <48304907+weiquu@users.noreply.github.com>
Co-authored-by: Ching Ming Yuan <cmingyuan123@gmail.com>
Co-authored-by: domoberzin <74132255+domoberzin@users.noreply.github.com>
  • Loading branch information
5 people committed Jul 11, 2024
1 parent 13a1891 commit 3f5f68d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3f5f68d

Please sign in to comment.