From b0792b25d3225d00fab13ab7330bf412b2e00cbc Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Mon, 12 Jun 2023 15:37:59 +0200 Subject: [PATCH] MOBILE-4352 ws: Add current lang to service requests --- src/core/features/login/tests/credentials.test.ts | 4 +++- src/core/services/ws.ts | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/core/features/login/tests/credentials.test.ts b/src/core/features/login/tests/credentials.test.ts index 624fc3330..8adefc136 100644 --- a/src/core/features/login/tests/credentials.test.ts +++ b/src/core/features/login/tests/credentials.test.ts @@ -13,10 +13,11 @@ // limitations under the License. import { CoreSharedModule } from '@/core/shared.module'; -import { findElement, mockSingleton, renderPageComponent, requireElement } from '@/testing/utils'; +import { findElement, mock, mockSingleton, renderPageComponent, requireElement } from '@/testing/utils'; import { CoreLoginError } from '@classes/errors/loginerror'; import { CoreLoginComponentsModule } from '@features/login/components/components.module'; import { CoreLoginCredentialsPage } from '@features/login/pages/credentials/credentials'; +import { CoreLang } from '@services/lang'; import { CoreSites } from '@services/sites'; import { Http } from '@singletons'; import { of } from 'rxjs'; @@ -29,6 +30,7 @@ describe('Credentials page', () => { beforeEach(() => { // eslint-disable-next-line @typescript-eslint/no-explicit-any mockSingleton(Http, { get: () => of(null as any) }); + mockSingleton(CoreLang, mock({ getCurrentLanguage: async () => 'en' })); }); it('renders', async () => { diff --git a/src/core/services/ws.ts b/src/core/services/ws.ts index 5b2c7b3d5..230f5006e 100644 --- a/src/core/services/ws.ts +++ b/src/core/services/ws.ts @@ -42,6 +42,7 @@ import { CorePlatform } from '@services/platform'; import { CoreSiteError, CoreSiteErrorOptions } from '@classes/errors/siteerror'; import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config'; import { CoreSites } from '@services/sites'; +import { CoreLang } from './lang'; /** * This service allows performing WS calls and download/upload files. @@ -419,7 +420,11 @@ export class CoreWSProvider { * @param preSets Extra settings and information. Only some * @returns Promise resolved with the response data in success and rejected with CoreAjaxError. */ - protected performAjax(method: string, data: Record, preSets: CoreWSAjaxPreSets): Promise { + protected async performAjax ( + method: string, + data: Record, + preSets: CoreWSAjaxPreSets, + ): Promise { // eslint-disable-next-line @typescript-eslint/no-explicit-any let promise: Promise>; @@ -440,9 +445,11 @@ export class CoreWSProvider { args: this.convertValuesToString(data), }]; + const lang = await CoreLang.getCurrentLanguage(); + // The info= parameter has no function. It is just to help with debugging. // We call it info to match the parameter name use by Moodle's AMD ajax module. - let siteUrl = preSets.siteUrl + '/lib/ajax/' + script + '?info=' + method; + let siteUrl = preSets.siteUrl + '/lib/ajax/' + script + '?info=' + method + `&lang=${lang}`; if (preSets.noLogin && preSets.useGet) { // Send params using GET.