@labdigital/commercetools-mock 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +73 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +73 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/repositories/cart-discount.ts +49 -1
- package/src/repositories/category.ts +49 -0
- package/src/repositories/product-projection.ts +24 -3
- package/src/repositories/store.ts +8 -0
- package/src/services/cart-discount.test.ts +362 -0
- package/src/services/category.test.ts +117 -2
- package/src/services/product-projection.test.ts +24 -14
package/dist/index.cjs
CHANGED
|
@@ -2195,7 +2195,12 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
|
|
|
2195
2195
|
stackingMode: draft.stackingMode || "Stacking",
|
|
2196
2196
|
validFrom: draft.validFrom,
|
|
2197
2197
|
validUntil: draft.validUntil,
|
|
2198
|
-
value: this.transformValueDraft(draft.value)
|
|
2198
|
+
value: this.transformValueDraft(draft.value),
|
|
2199
|
+
custom: createCustomFields(
|
|
2200
|
+
draft.custom,
|
|
2201
|
+
context.projectKey,
|
|
2202
|
+
this._storage
|
|
2203
|
+
)
|
|
2199
2204
|
};
|
|
2200
2205
|
this.saveNew(context, resource);
|
|
2201
2206
|
return resource;
|
|
@@ -2249,6 +2254,29 @@ var CartDiscountRepository = class extends AbstractResourceRepository {
|
|
|
2249
2254
|
},
|
|
2250
2255
|
changeIsActive: (context, resource, { isActive }) => {
|
|
2251
2256
|
resource.isActive = isActive;
|
|
2257
|
+
},
|
|
2258
|
+
changeTarget: (context, resource, { target }) => {
|
|
2259
|
+
resource.target = target;
|
|
2260
|
+
},
|
|
2261
|
+
setCustomField: (context, resource, { name, value }) => {
|
|
2262
|
+
if (!resource.custom) {
|
|
2263
|
+
return;
|
|
2264
|
+
}
|
|
2265
|
+
if (value === null) {
|
|
2266
|
+
if (name in resource.custom.fields) {
|
|
2267
|
+
delete resource.custom.fields[name];
|
|
2268
|
+
} else {
|
|
2269
|
+
throw new CommercetoolsError(
|
|
2270
|
+
{
|
|
2271
|
+
code: "InvalidOperation",
|
|
2272
|
+
message: "Cannot remove custom field " + name + " because it does not exist."
|
|
2273
|
+
},
|
|
2274
|
+
400
|
|
2275
|
+
);
|
|
2276
|
+
}
|
|
2277
|
+
} else {
|
|
2278
|
+
resource.custom.fields[name] = value;
|
|
2279
|
+
}
|
|
2252
2280
|
}
|
|
2253
2281
|
};
|
|
2254
2282
|
};
|
|
@@ -2259,6 +2287,11 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
2259
2287
|
getTypeId() {
|
|
2260
2288
|
return "category";
|
|
2261
2289
|
}
|
|
2290
|
+
assetFromAssetDraft = (draft, context) => ({
|
|
2291
|
+
...draft,
|
|
2292
|
+
id: (0, import_uuid4.v4)(),
|
|
2293
|
+
custom: createCustomFields(draft.custom, context.projectKey, this._storage)
|
|
2294
|
+
});
|
|
2262
2295
|
create(context, draft) {
|
|
2263
2296
|
const resource = {
|
|
2264
2297
|
...getBaseResourceProperties(),
|
|
@@ -2361,6 +2394,30 @@ var CategoryRepository = class extends AbstractResourceRepository {
|
|
|
2361
2394
|
} else {
|
|
2362
2395
|
resource.custom.fields[name] = value;
|
|
2363
2396
|
}
|
|
2397
|
+
},
|
|
2398
|
+
removeAsset: (context, resource, { assetId, assetKey }) => {
|
|
2399
|
+
if (!resource.assets) {
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
if (assetId) {
|
|
2403
|
+
resource.assets = resource.assets.filter(function(obj) {
|
|
2404
|
+
return obj.id !== assetId;
|
|
2405
|
+
});
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
if (assetKey) {
|
|
2409
|
+
resource.assets = resource.assets.filter(function(obj) {
|
|
2410
|
+
return obj.key !== assetKey;
|
|
2411
|
+
});
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
},
|
|
2415
|
+
addAsset: (context, resource, { asset }) => {
|
|
2416
|
+
if (!resource.assets) {
|
|
2417
|
+
resource.assets = [this.assetFromAssetDraft(asset, context)];
|
|
2418
|
+
} else {
|
|
2419
|
+
resource.assets.push(this.assetFromAssetDraft(asset, context));
|
|
2420
|
+
}
|
|
2364
2421
|
}
|
|
2365
2422
|
};
|
|
2366
2423
|
};
|
|
@@ -4269,6 +4326,18 @@ var ProductProjectionRepository = class extends AbstractResourceRepository {
|
|
|
4269
4326
|
create(context, draft) {
|
|
4270
4327
|
throw new Error("No valid action");
|
|
4271
4328
|
}
|
|
4329
|
+
get(context, id, params = {}) {
|
|
4330
|
+
const resource = this._storage.get(
|
|
4331
|
+
context.projectKey,
|
|
4332
|
+
"product",
|
|
4333
|
+
id,
|
|
4334
|
+
params
|
|
4335
|
+
);
|
|
4336
|
+
if (resource) {
|
|
4337
|
+
return this._searchService.transform(resource, false);
|
|
4338
|
+
}
|
|
4339
|
+
return null;
|
|
4340
|
+
}
|
|
4272
4341
|
query(context, params = {}) {
|
|
4273
4342
|
let resources = this._storage.all(context.projectKey, "product").map((r) => this._searchService.transform(r, params.staged ?? false)).filter((p) => {
|
|
4274
4343
|
if (!params.staged) {
|
|
@@ -4907,6 +4976,9 @@ var StoreRepository = class extends AbstractResourceRepository {
|
|
|
4907
4976
|
} else {
|
|
4908
4977
|
resource.custom.fields[name] = value;
|
|
4909
4978
|
}
|
|
4979
|
+
},
|
|
4980
|
+
setCountries: (context, resource, { countries }) => {
|
|
4981
|
+
resource.countries = countries ?? [];
|
|
4910
4982
|
}
|
|
4911
4983
|
};
|
|
4912
4984
|
};
|