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: 'US',
};
const unitedStatesCreateRequest: AccountCreateRequest = {
...typicalCreateRequest,
instructorInstitution: `${unitedStatesModel.institution}, USA`,
};
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 @@ -116,10 +116,20 @@ export class InstructorRequestFormComponent {
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the only possibilities?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some countries to the list with the change in the issue, and also included the possibility to correct any capitalization typos in the listed countries.

};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there is a better place to put this. I am not completely sure where though; perhaps another reviewer has a better idea. However, maybe at the very least, it should be outside the function, like maybe it should be a class constant.

Copy link
Contributor Author

@franciscoSavala franciscoSavala Jun 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of creating another class so that the map can only be accessed with a method and cannot be modified, but I'm not sure if it's the correct apporach.


// Combine country and institution
const country = this.country.value!.trim();
const mappedCountry = countryMapping[country] || country;
const institution = this.institution.value!.trim();
const combinedInstitution = `${institution}, ${country}`;
const combinedInstitution = `${institution}, ${mappedCountry}`;

const requestData: AccountCreateRequest = {
instructorEmail: email,
Expand Down
Loading