Skip to content
This repository was archived by the owner on Oct 16, 2019. It is now read-only.

Commit 72bed78

Browse files
author
Ahmed Sameh Mahmoud Ahmed Shehata
committed
fix(lang): #140 - Added lang field
1 parent 2355717 commit 72bed78

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/api/__tests__/config_service_tests.js

+20
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ test('Should return current locale, language and country code according to Sales
4444

4545
});
4646

47+
test('Should override language', async t => {
48+
fetchMock.get('https://atlas-config-api.dc.zalan.do/api/config/CLIENT_ID-staging.json', configJson);
49+
50+
const sdk = await AtlasSDK.configure({
51+
client_id: 'CLIENT_ID',
52+
sales_channel: 'SALES_CHANNEL',
53+
is_sandbox: true,
54+
lang: 'en'
55+
}).catch(error => {
56+
t.fail(error);
57+
});
58+
59+
t.is(sdk.getLocale(), 'de_DE');
60+
t.is(sdk.getLanguage(), 'en');
61+
t.is(sdk.getCountryCode(), 'DE');
62+
t.is(sdk.getConfig().clientId, 'CLIENT_ID');
63+
t.is(sdk.getConfig().salesChannel, 'SALES_CHANNEL');
64+
65+
});
66+
4767
test.afterEach.always(() => {
4868
fetchMock.restore();
4969
});

src/api/atlas_sdk_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class AtlasSDKClient {
110110
getLanguage() {
111111
const startPosition = 0;
112112

113-
return this.getLocale().substring(startPosition, this.getLocale().indexOf('_'));
113+
return this.config.lang ? this.config.lang : this.getLocale().substring(startPosition, this.getLocale().indexOf('_'));
114114
}
115115

116116
/**

src/models/__tests__/config_service_models_tests.js

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ test('Config should be initialized from JSON object', t => {
2929
client_id: 'CLIENT_ID',
3030
sales_channel: 'SALES_CHANNEL',
3131
is_sandbox: true,
32+
lang: 'en',
3233
'atlas-catalog-api': {
3334
url: 'https://catalog_api.com/api'
3435
},
@@ -60,6 +61,7 @@ test('Config should be initialized from JSON object', t => {
6061
t.is(config.catalogApi.url, 'https://catalog_api.com/api');
6162
t.is(config.atlasCheckoutGateway.url, 'https://atlas-checkout-gateway.com');
6263
t.is(config.salesChannels[0].locale, 'de_DE');
64+
t.is(config.lang, 'en');
6365
t.is(config.salesChannels[0].channel, '11111111-1111-1111-1111-111111111111');
6466
t.is(config.salesChannels[0].tocURL, 'https://m.zalando.de/agb/');
6567
});

src/models/config_models.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Config = createModel({
4848
atlasCheckoutApi: { key: 'atlas-checkout-api', type: 'object', optional: true },
4949
salesChannels: { key: 'sales-channels', type: 'object', model: SalesChannel },
5050
clientId: { key: 'client_id', type: 'string' },
51+
lang: { key: 'lang', type: 'string', optional: true },
5152
salesChannel: { key: 'sales_channel', type: 'string' },
5253
recommendations: { key: 'recommendations', type: 'object', model: Recommendations },
5354
isSandbox: { key: 'is_sandbox', type: 'boolean' }

0 commit comments

Comments
 (0)