MOBILE-4352 ws: Add current lang to service requests
parent
d7a18dd36c
commit
b0792b25d3
|
@ -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 () => {
|
||||
|
|
|
@ -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<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
|
||||
let promise: Promise<HttpResponse<any>>;
|
||||
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue