@merchi/sdk 1.42.17 → 1.42.18

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.
@@ -26,3 +26,28 @@ test('Get quote update job cost', function () {
26
26
  expect(item.totalCost).toEqual(100);
27
27
  });
28
28
  });
29
+ test('a cart item preserves a job without a tax relationship', function () {
30
+ var merchi = new Merchi();
31
+ var job = new merchi.Job().fromJson({ quantity: 100, taxType: null });
32
+ var item = new merchi.CartItem();
33
+ // The cart transfers this nullable API value through its untyped entity adapter.
34
+ expect(function () { item.taxType = job.taxType; }).not.toThrow();
35
+ expect(item.toJson()).toMatchObject({ taxType: null });
36
+ expect(Array.from(item.toFormData().entries())).toEqual([
37
+ ['taxType-0-id', '-1'],
38
+ ['taxType-count', '1'],
39
+ ]);
40
+ });
41
+ test('clearing a cart tax relationship preserves normal entity linking', function () {
42
+ var merchi = new Merchi();
43
+ var item = new merchi.CartItem();
44
+ var tax = new merchi.CountryTax();
45
+ tax.id = 7;
46
+ item.taxType = tax;
47
+ expect(tax.backObjects.has(item)).toBe(true);
48
+ expect(function () { item.taxType = null; }).not.toThrow();
49
+ expect(item.toJson()).toMatchObject({ taxType: null });
50
+ item.taxType = tax;
51
+ expect(tax.backObjects.has(item)).toBe(true);
52
+ expect(item.taxType).toBe(tax);
53
+ });
package/dist/entity.d.ts CHANGED
@@ -198,7 +198,7 @@ export declare class Entity {
198
198
  toJson: () => any;
199
199
  protected forEachProperty: (fn: (i: PropertyInfo) => void) => void;
200
200
  toFormData: (options?: SerialiseOptions, fileIndex?: Counter) => FormData;
201
- protected addBackObject: (remote?: Entity) => void;
201
+ protected addBackObject: (remote?: Entity | null) => void;
202
202
  protected addBackObjectList: (remotes?: Entity[]) => void;
203
203
  updateOrder: (property: string) => void;
204
204
  protected markDirty: (property: string, newValue: any) => void;
package/dist/entity.js CHANGED
@@ -423,7 +423,7 @@ var Entity = /** @class */ (function () {
423
423
  return result;
424
424
  };
425
425
  this.addBackObject = function (remote) {
426
- if (remote !== undefined) {
426
+ if (remote !== undefined && remote !== null) {
427
427
  remote.backObjects.add(_this);
428
428
  }
429
429
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merchi/sdk",
3
- "version": "1.42.17",
3
+ "version": "1.42.18",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",
@@ -31,3 +31,33 @@ test('Get quote update job cost', () => {
31
31
  expect(item.totalCost).toEqual(100);
32
32
  });
33
33
  });
34
+
35
+
36
+ test('a cart item preserves a job without a tax relationship', () => {
37
+ const merchi = new Merchi();
38
+ const job = new merchi.Job().fromJson({ quantity: 100, taxType: null });
39
+ const item = new merchi.CartItem();
40
+
41
+ // The cart transfers this nullable API value through its untyped entity adapter.
42
+ expect(() => { (item as any).taxType = job.taxType; }).not.toThrow();
43
+ expect(item.toJson()).toMatchObject({ taxType: null });
44
+ expect(Array.from((item.toFormData() as any).entries())).toEqual([
45
+ ['taxType-0-id', '-1'],
46
+ ['taxType-count', '1'],
47
+ ]);
48
+ });
49
+
50
+ test('clearing a cart tax relationship preserves normal entity linking', () => {
51
+ const merchi = new Merchi();
52
+ const item = new merchi.CartItem();
53
+ const tax = new merchi.CountryTax();
54
+ tax.id = 7;
55
+ item.taxType = tax;
56
+ expect(tax.backObjects.has(item)).toBe(true);
57
+
58
+ expect(() => { (item as any).taxType = null; }).not.toThrow();
59
+ expect(item.toJson()).toMatchObject({ taxType: null });
60
+ item.taxType = tax;
61
+ expect(tax.backObjects.has(item)).toBe(true);
62
+ expect(item.taxType).toBe(tax);
63
+ });
package/src/entity.ts CHANGED
@@ -347,7 +347,7 @@ export class Entity {
347
347
  const get = () => {
348
348
  return info.currentValue;
349
349
  };
350
- const set = (newValue?: Entity) => {
350
+ const set = (newValue?: Entity | null) => {
351
351
  info.currentValue = newValue;
352
352
  this.addBackObject(newValue);
353
353
  this.markDirty(info.property, newValue);
@@ -1040,8 +1040,8 @@ export class Entity {
1040
1040
  return result;
1041
1041
  };
1042
1042
 
1043
- protected addBackObject = (remote?: Entity) => {
1044
- if (remote !== undefined) {
1043
+ protected addBackObject = (remote?: Entity | null) => {
1044
+ if (remote !== undefined && remote !== null) {
1045
1045
  remote.backObjects.add(this);
1046
1046
  }
1047
1047
  };