Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#13104] Accounts request form: auto-unify country names #13117

Merged
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
Loading