Skip to content

Commit 95af9c7

Browse files
committed
Revert "fix: STRF-13605 Support local to be channel-specific" (#1327)
1 parent 7c1e81a commit 95af9c7

File tree

5 files changed

+49
-160
lines changed

5 files changed

+49
-160
lines changed

lib/stencil-start.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,35 @@ class StencilStart {
5858
const initialStencilConfig = await this._stencilConfigManager.read();
5959
// Use initial (before updates) port for BrowserSync
6060
const browserSyncPort = cliOptions.port || initialStencilConfig.port;
61-
const channelInfo = await this.getChannelInfo(initialStencilConfig, cliOptions);
61+
const channelUrl = await this.getChannelUrl(initialStencilConfig, cliOptions);
6262
const storeInfoFromAPI = await this._themeApiClient.checkCliVersion({
63-
storeUrl: channelInfo.url,
63+
storeUrl: channelUrl,
6464
});
6565
const updatedStencilConfig = this.updateStencilConfig(
6666
initialStencilConfig,
6767
storeInfoFromAPI,
6868
browserSyncPort,
6969
);
70-
7170
this._storeSettingsLocale = await this.getStoreSettingsLocale(
7271
cliOptions,
7372
updatedStencilConfig,
74-
channelInfo.channel_id,
7573
);
7674
await this.startLocalServer(cliOptions, updatedStencilConfig);
7775
this._logger.log(this.getStartUpInfo(updatedStencilConfig));
7876
await this.startBrowserSync(cliOptions, browserSyncPort);
7977
}
8078

81-
async getStoreSettingsLocale(cliOptions, stencilConfig, channelId) {
79+
async getStoreSettingsLocale(cliOptions, stencilConfig) {
8280
const { accessToken } = stencilConfig;
8381
const apiHost = cliOptions.apiHost || stencilConfig.apiHost;
8482
return this._storeSettingsApiClient.getStoreSettingsLocale({
8583
storeHash: this.storeHash,
8684
accessToken,
8785
apiHost,
88-
channelId,
8986
});
9087
}
9188

92-
async getChannelInfo(stencilConfig, cliOptions) {
89+
async getChannelUrl(stencilConfig, cliOptions) {
9390
const { accessToken } = stencilConfig;
9491
const apiHost = cliOptions.apiHost || stencilConfig.apiHost;
9592
this.storeHash = await this._themeApiClient.getStoreHash({
@@ -109,7 +106,7 @@ class StencilStart {
109106
const foundChannel = channels.find(
110107
(channel) => channel.channel_id === parseInt(channelId, 10),
111108
);
112-
return foundChannel || null;
109+
return foundChannel ? foundChannel.url : null;
113110
}
114111

115112
/**

lib/stencil-start.spec.js

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,22 @@ describe('StencilStart unit tests', () => {
137137
const storeHash = 'storeHash_value';
138138
const channelId = 5;
139139
const storeUrl = 'https://www.example.com';
140-
it('should obtain channel info object from the api when no channelUrl is provided', async () => {
140+
it('should obtain channel id from the api', async () => {
141141
const channels = [{ channel_id: channelId, url: storeUrl }];
142142
const themeApiClientStub = {
143143
checkCliVersion: jest.fn(),
144144
getStoreHash: jest.fn().mockResolvedValue(storeHash),
145145
getStoreChannels: jest.fn().mockResolvedValue(channels),
146146
};
147-
const stencilPushUtilsStub = {
148-
promptUserToSelectChannel: jest.fn().mockResolvedValue(channelId),
149-
};
150147
const { instance } = createStencilStartInstance({
151148
themeApiClient: themeApiClientStub,
152-
stencilPushUtils: stencilPushUtilsStub,
149+
stencilPushUtils: stencilPushUtilsModule,
153150
});
154-
const stencilConfig = { accessToken, normalStoreUrl: 'https://example.com', apiHost };
155-
const cliOptions = { apiHost };
156-
const result = await instance.getChannelInfo(stencilConfig, cliOptions);
157-
expect(result).toEqual(channels[0]);
151+
const result = await instance.getChannelUrl({ accessToken }, { apiHost });
152+
expect(result).toEqual(storeUrl);
158153
});
159154

160-
it('should return the channelUrl string from cliOptions if provided', async () => {
155+
it('should obtain channel url from the CLI', async () => {
161156
const channelUrl = 'https://shop.bigcommerce.com';
162157
const channels = [{ channel_id: channelId, url: storeUrl }];
163158
const themeApiClientStub = {
@@ -169,9 +164,7 @@ describe('StencilStart unit tests', () => {
169164
themeApiClient: themeApiClientStub,
170165
stencilPushUtils: stencilPushUtilsModule,
171166
});
172-
const stencilConfig = { accessToken, normalStoreUrl: 'https://example.com', apiHost };
173-
const cliOptions = { apiHost, channelUrl };
174-
const result = await instance.getChannelInfo(stencilConfig, cliOptions);
167+
const result = await instance.getChannelUrl({ accessToken }, { apiHost, channelUrl });
175168
expect(result).toEqual(channelUrl);
176169
});
177170
});
@@ -180,23 +173,9 @@ describe('StencilStart unit tests', () => {
180173
it('should read port from the config file', async () => {
181174
const port = 1234;
182175
const browserSyncStub = getBrowserSyncStub();
183-
const themeApiClientStub = {
184-
checkCliVersion: jest
185-
.fn()
186-
.mockResolvedValue({ baseUrl: 'example.com', sslUrl: 'https://example.com' }),
187-
getStoreHash: jest.fn().mockResolvedValue('storeHash_value'),
188-
getStoreChannels: jest
189-
.fn()
190-
.mockResolvedValue([{ channel_id: 5, url: 'https://www.example.com' }]),
191-
};
192-
const stencilPushUtilsStub = {
193-
promptUserToSelectChannel: jest.fn().mockResolvedValue(5),
194-
};
195176
const { instance } = createStencilStartInstance({
196177
browserSync: browserSyncStub,
197178
stencilConfigManager: getStencilConfigManagerStub({ port }),
198-
themeApiClient: themeApiClientStub,
199-
stencilPushUtils: stencilPushUtilsStub,
200179
});
201180
instance.startLocalServer = jest.fn();
202181
instance.getStartUpInfo = jest.fn().mockReturnValue('Start up info');
@@ -212,23 +191,9 @@ describe('StencilStart unit tests', () => {
212191
it('should read port from the cli', async () => {
213192
const port = 1234;
214193
const browserSyncStub = getBrowserSyncStub();
215-
const themeApiClientStub = {
216-
checkCliVersion: jest
217-
.fn()
218-
.mockResolvedValue({ baseUrl: 'example.com', sslUrl: 'https://example.com' }),
219-
getStoreHash: jest.fn().mockResolvedValue('storeHash_value'),
220-
getStoreChannels: jest
221-
.fn()
222-
.mockResolvedValue([{ channel_id: 5, url: 'https://www.example.com' }]),
223-
};
224-
const stencilPushUtilsStub = {
225-
promptUserToSelectChannel: jest.fn().mockResolvedValue(5),
226-
};
227194
const { instance } = createStencilStartInstance({
228195
browserSync: browserSyncStub,
229196
stencilConfigManager: getStencilConfigManagerStub({ port: 5678 }),
230-
themeApiClient: themeApiClientStub,
231-
stencilPushUtils: stencilPushUtilsStub,
232197
});
233198
instance.startLocalServer = jest.fn();
234199
instance.getStartUpInfo = jest.fn().mockReturnValue('Start up info');

lib/store-settings-api-client.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,29 @@ import 'colors';
22
import NetworkUtils from './utils/NetworkUtils.js';
33

44
const networkUtils = new NetworkUtils();
5-
6-
async function getStoreSettingsLocaleWithChannel({ apiHost, storeHash, accessToken, channelId }) {
7-
let url = `${apiHost}/stores/${storeHash}/v3/settings/store/locale`;
8-
if (channelId) {
9-
url += `?channel_id=${channelId}`;
10-
}
11-
const response = await networkUtils.sendApiRequest({
12-
url,
13-
accessToken,
14-
});
15-
16-
return response.data.data;
17-
}
18-
19-
async function getStoreSettingsLocale({ apiHost, storeHash, accessToken, channelId }) {
5+
async function getStoreSettingsLocale({ apiHost, storeHash, accessToken }) {
206
try {
21-
let data = await getStoreSettingsLocaleWithChannel({
22-
apiHost,
23-
storeHash,
7+
const response = await networkUtils.sendApiRequest({
8+
url: `${apiHost}/stores/${storeHash}/v3/settings/store/locale`,
249
accessToken,
25-
channelId,
2610
});
27-
// if no data available for the channel provided, default to global setting.
28-
if (!data) {
29-
data = await getStoreSettingsLocaleWithChannel({ apiHost, storeHash, accessToken });
30-
}
31-
if (!data) {
11+
if (!response.data.data) {
3212
throw new Error('Received empty store locale in the server response'.red);
33-
} else if (!data.default_shopper_language) {
13+
} else if (!response.data.data.default_shopper_language) {
3414
throw new Error(
3515
'Received empty default_shopper_language field in the server response'.red,
3616
);
37-
} else if (!data.shopper_language_selection_method) {
17+
} else if (!response.data.data.shopper_language_selection_method) {
3818
throw new Error(
3919
'Received empty shopper_language_selection_method field in the server response'.red,
4020
);
4121
}
42-
return data;
22+
return response.data.data;
4323
} catch (err) {
4424
err.name = 'StoreSettingsLocaleError';
4525
throw err;
4626
}
4727
}
48-
4928
export { getStoreSettingsLocale };
5029
export default {
5130
getStoreSettingsLocale,

0 commit comments

Comments
 (0)