Skip to content

Commit 6369c31

Browse files
committed
chore: fix test
1 parent 5fc4c74 commit 6369c31

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/routes/catalog/update.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import { assertValidProduct } from '../../utils/product.js';
13+
import { assertValidProduct, hasUppercase } from '../../utils/product.js';
1414
import { errorResponse } from '../../utils/http.js';
1515
import StorageClient from './StorageClient.js';
1616

@@ -20,17 +20,24 @@ import StorageClient from './StorageClient.js';
2020
* @returns {Promise<Response>} - A promise that resolves to the product response.
2121
*/
2222
export default async function update(ctx) {
23-
const { config, log } = ctx;
23+
const { config, log, data: product } = ctx;
2424

2525
if (config.sku === '*') {
2626
return errorResponse(501, 'not implemented');
2727
}
2828

29-
const product = ctx.data;
3029
if (!product || typeof product !== 'object') {
3130
return errorResponse(400, 'invalid product data');
3231
}
3332

33+
if (hasUppercase(config.sku)) {
34+
return errorResponse(400, 'sku must be lowercase');
35+
}
36+
37+
if (config.sku !== product.sku) {
38+
return errorResponse(400, 'sku must match the product data');
39+
}
40+
3441
assertValidProduct(product);
3542

3643
const storage = StorageClient.fromContext(ctx);

test/routes/catalog/handler.test.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('catalogHandler Tests', () => {
4444
it('should return 405 when method is not allowed', async () => {
4545
const ctx = DEFAULT_CONTEXT({
4646
info: { method: 'HEAD' },
47-
url: { pathname: '/org/site/catalog/store/view/product/sku1' },
47+
url: { pathname: '/org/site/catalog/store/view/products/sku1' },
4848
config: {},
4949
});
5050
const request = {};
@@ -53,23 +53,10 @@ describe('catalogHandler Tests', () => {
5353
assert.equal(response.status, 405);
5454
});
5555

56-
it('should return 400 when sku is uppercase', async () => {
57-
const ctx = DEFAULT_CONTEXT({
58-
info: { method: 'GET' },
59-
url: { pathname: '/org/site/catalog/store/view/product/PRODUCT-SKU' },
60-
config: {},
61-
});
62-
const request = {};
63-
const response = await catalogHandler(ctx, request);
64-
65-
assert.equal(response.status, 400);
66-
assert.equal(response.headers.get('x-error'), 'Invalid SKU: SKU cannot contain uppercase letters');
67-
});
68-
6956
it('should call handleProductLookupRequest when method is GET and subRoute is "lookup"', async () => {
7057
const ctx = DEFAULT_CONTEXT({
7158
info: { method: 'GET' },
72-
url: { pathname: '/org/site/catalog/store/view/lookup/sku' },
59+
url: { pathname: '/org/site/catalog/store/view/lookup' },
7360
config: {},
7461
});
7562
const request = {};
@@ -86,7 +73,7 @@ describe('catalogHandler Tests', () => {
8673
it('should return 405 if subRoute is "lookup" but method is not GET', async () => {
8774
const ctx = DEFAULT_CONTEXT({
8875
info: { method: 'PUT' },
89-
url: { pathname: '/org/site/catalog/store/view/lookup/sku' },
76+
url: { pathname: '/org/site/catalog/store/view/lookup' },
9077
config: {},
9178
});
9279
const request = {};

0 commit comments

Comments
 (0)