Merge pull request #3710 from alfonso-salces/MOBILE-4352
MOBILE-4352 ws: Add current lang to service requestsmain
commit
24c1b38da5
|
@ -13,10 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreSharedModule } from '@/core/shared.module';
|
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 { CoreLoginError } from '@classes/errors/loginerror';
|
||||||
import { CoreLoginComponentsModule } from '@features/login/components/components.module';
|
import { CoreLoginComponentsModule } from '@features/login/components/components.module';
|
||||||
import { CoreLoginCredentialsPage } from '@features/login/pages/credentials/credentials';
|
import { CoreLoginCredentialsPage } from '@features/login/pages/credentials/credentials';
|
||||||
|
import { CoreLang } from '@services/lang';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { Http } from '@singletons';
|
import { Http } from '@singletons';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
|
@ -29,6 +30,7 @@ describe('Credentials page', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
mockSingleton(Http, { get: () => of(null as any) });
|
mockSingleton(Http, { get: () => of(null as any) });
|
||||||
|
mockSingleton(CoreLang, mock({ getCurrentLanguage: async () => 'en' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders', async () => {
|
it('renders', async () => {
|
||||||
|
|
|
@ -42,6 +42,7 @@ import { CorePlatform } from '@services/platform';
|
||||||
import { CoreSiteError, CoreSiteErrorOptions } from '@classes/errors/siteerror';
|
import { CoreSiteError, CoreSiteErrorOptions } from '@classes/errors/siteerror';
|
||||||
import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config';
|
import { CoreUserGuestSupportConfig } from '@features/user/classes/support/guest-support-config';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
|
import { CoreLang } from './lang';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service allows performing WS calls and download/upload files.
|
* 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
|
* @param preSets Extra settings and information. Only some
|
||||||
* @returns Promise resolved with the response data in success and rejected with CoreAjaxError.
|
* @returns Promise resolved with the response data in success and rejected with CoreAjaxError.
|
||||||
*/
|
*/
|
||||||
protected performAjax<T = unknown>(method: string, data: Record<string, unknown>, preSets: CoreWSAjaxPreSets): Promise<T> {
|
protected async performAjax<T = unknown> (
|
||||||
|
method: string,
|
||||||
|
data: Record<string, unknown>,
|
||||||
|
preSets: CoreWSAjaxPreSets,
|
||||||
|
): Promise<T> {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
let promise: Promise<HttpResponse<any>>;
|
let promise: Promise<HttpResponse<any>>;
|
||||||
|
|
||||||
|
@ -440,9 +445,11 @@ export class CoreWSProvider {
|
||||||
args: this.convertValuesToString(data),
|
args: this.convertValuesToString(data),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
const lang = await CoreLang.getCurrentLanguage();
|
||||||
|
|
||||||
// The info= parameter has no function. It is just to help with debugging.
|
// 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.
|
// 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) {
|
if (preSets.noLogin && preSets.useGet) {
|
||||||
// Send params using GET.
|
// Send params using GET.
|
||||||
|
|
Loading…
Reference in New Issue