@unchainedshop/core 3.1.1 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "main": "lib/core-index.js",
5
5
  "types": "lib/core-index.d.ts",
6
6
  "type": "module",
@@ -9,8 +9,8 @@
9
9
  "build": "tsc -b",
10
10
  "prepublishOnly": "npm run clean && npm run build",
11
11
  "watch": "tsc -w ",
12
- "test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
13
- "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
12
+ "test": "tsx --test",
13
+ "test:watch": "tsx --test --watch"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -54,8 +54,7 @@
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "^22.13.4",
57
- "jest": "^29.7.0",
58
- "ts-jest": "^29.2.5",
57
+ "tsx": "^4.19.2",
59
58
  "typescript": "^5.7.3"
60
59
  }
61
60
  }
@@ -1,49 +1,52 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert/strict';
1
3
  import { BaseDiscountAdapter } from './BaseDiscountAdapter.js';
2
4
 
3
5
  describe('BaseDiscountAdapter instantiation', () => {
4
6
  const adapter = BaseDiscountAdapter;
5
7
  const context = null as any;
6
8
  it('should initialize with default values', async () => {
7
- expect(adapter.orderIndex).toEqual(0);
8
- expect(adapter.log).toEqual(expect.any(Function));
9
- expect(await adapter.isManualAdditionAllowed('')).toEqual(false);
10
- expect(await adapter.isManualRemovalAllowed()).toEqual(false);
11
- expect(await adapter.actions(context)).toEqual({
12
- isValidForSystemTriggering: expect.any(Function),
13
- reserve: expect.any(Function),
14
- release: expect.any(Function),
15
- isValidForCodeTriggering: expect.any(Function),
16
- discountForPricingAdapterKey: expect.any(Function),
17
- });
9
+ assert.equal(adapter.orderIndex, 0);
10
+ assert.equal(typeof adapter.log, 'function');
11
+ assert.equal(await adapter.isManualAdditionAllowed(''), false);
12
+ assert.equal(await adapter.isManualRemovalAllowed(), false);
13
+ assert.deepStrictEqual(Object.keys(await adapter.actions(context)), [
14
+ 'isValidForSystemTriggering',
15
+ 'reserve',
16
+ 'release',
17
+ 'isValidForCodeTriggering',
18
+ 'discountForPricingAdapterKey',
19
+ ]);
18
20
  });
19
21
 
20
22
  describe('actions', () => {
21
23
  it('isValidForSystemTriggering', async () => {
22
24
  const result = await adapter.actions(context);
23
- expect(await result.isValidForSystemTriggering()).toEqual(false);
25
+ assert.equal(await result.isValidForSystemTriggering(), false);
24
26
  });
25
27
 
26
28
  it('reserve', async () => {
27
29
  const result = await adapter.actions(context);
28
- expect(await result.reserve({ code: '' })).toEqual({});
30
+ assert.deepEqual(await result.reserve({ code: '' }), {});
29
31
  });
30
32
 
31
33
  it('release', async () => {
32
34
  const result = await adapter.actions(context);
33
- expect(await result.release()).toEqual(null);
35
+ assert.equal(await result.release(), null);
34
36
  });
35
37
 
36
38
  it('isValidForCodeTriggering', async () => {
37
39
  const result = await adapter.actions(context);
38
- expect(await result.isValidForCodeTriggering({ code: '' })).toEqual(false);
40
+ assert.equal(await result.isValidForCodeTriggering({ code: '' }), false);
39
41
  });
40
42
 
41
43
  it('discountForPricingAdapterKey', async () => {
42
44
  const result = await adapter.actions(context);
43
45
  const calculationSheet = {};
44
- expect(
46
+ assert.equal(
45
47
  await result.discountForPricingAdapterKey({ calculationSheet, pricingAdapterKey: 'key' } as any),
46
- ).toEqual(null);
48
+ null,
49
+ );
47
50
  });
48
51
  });
49
52
  });
@@ -1,4 +1,6 @@
1
+ import { describe, it } from 'node:test';
1
2
  import { resolveRatioAndTaxDivisorForPricingSheet } from './BasePricingSheet';
3
+ import assert from 'node:assert';
2
4
 
3
5
  describe('resolveRatioAndTaxDivisorForPricingSheet', () => {
4
6
  it('total is 0 and pricing is provided', () => {
@@ -8,7 +10,7 @@ describe('resolveRatioAndTaxDivisorForPricingSheet', () => {
8
10
  net: () => 10,
9
11
  };
10
12
  const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 0);
11
- expect(result).toEqual({ ratio: 1, taxDivisor: 1 });
13
+ assert.deepStrictEqual(result, { ratio: 1, taxDivisor: 1 });
12
14
  });
13
15
 
14
16
  it('gross - tax is 0', () => {
@@ -18,7 +20,7 @@ describe('resolveRatioAndTaxDivisorForPricingSheet', () => {
18
20
  net: () => 0,
19
21
  };
20
22
  const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 20);
21
- expect(result).toEqual({ ratio: 0, taxDivisor: 0 });
23
+ assert.deepStrictEqual(result, { ratio: 0, taxDivisor: 0 });
22
24
  });
23
25
 
24
26
  it('gross - tax is not 0', () => {
@@ -28,7 +30,7 @@ describe('resolveRatioAndTaxDivisorForPricingSheet', () => {
28
30
  net: () => 10,
29
31
  };
30
32
  const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 20);
31
- expect(result).toEqual({ ratio: 1, taxDivisor: 2 });
33
+ assert.deepStrictEqual(result, { ratio: 1, taxDivisor: 2 });
32
34
  });
33
35
 
34
36
  it('taxSum is 0', () => {
@@ -38,6 +40,6 @@ describe('resolveRatioAndTaxDivisorForPricingSheet', () => {
38
40
  net: () => 20,
39
41
  };
40
42
  const result = resolveRatioAndTaxDivisorForPricingSheet(pricing, 20);
41
- expect(result).toEqual({ ratio: 1, taxDivisor: 1 });
43
+ assert.deepStrictEqual(result, { ratio: 1, taxDivisor: 1 });
42
44
  });
43
45
  });
@@ -1,5 +1,8 @@
1
+ import assert from 'node:assert';
2
+ import { describe, it } from 'node:test';
3
+
1
4
  describe('MessagingDirector', () => {
2
5
  it('Stub', () => {
3
- expect(true).toBe(true);
6
+ assert(true);
4
7
  });
5
8
  });
@@ -1,3 +1,5 @@
1
+ import { beforeEach, describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  import { ProductPricingSheet } from './ProductPricingSheet.js';
2
4
 
3
5
  const TAX = { category: 'TAX', amount: 50, isNetPrice: false, isTaxable: false };
@@ -40,90 +42,90 @@ describe('ProductPricingSheet', () => {
40
42
  });
41
43
 
42
44
  it('should return an object that implements the IProductPricingSheet interface', () => {
43
- expect(pricingSheet).toBeDefined();
44
- expect(pricingSheet.quantity).toEqual(2);
45
- expect(pricingSheet.currency).toEqual('CHF');
46
- expect(typeof pricingSheet.addItem).toBe('function');
47
- expect(typeof pricingSheet.addDiscount).toBe('function');
48
- expect(typeof pricingSheet.addTax).toBe('function');
49
- expect(typeof pricingSheet.taxSum).toBe('function');
50
- expect(typeof pricingSheet.unitPrice).toBe('function');
51
- expect(typeof pricingSheet.discountPrices).toBe('function');
45
+ assert(pricingSheet);
46
+ assert.equal(pricingSheet.quantity, 2);
47
+ assert.equal(pricingSheet.currency, 'CHF');
48
+ assert.equal(typeof pricingSheet.addItem, 'function');
49
+ assert.equal(typeof pricingSheet.addDiscount, 'function');
50
+ assert.equal(typeof pricingSheet.addTax, 'function');
51
+ assert.equal(typeof pricingSheet.taxSum, 'function');
52
+ assert.equal(typeof pricingSheet.unitPrice, 'function');
53
+ assert.equal(typeof pricingSheet.discountPrices, 'function');
52
54
  });
53
55
 
54
56
  it('gross() should return the GROSS sum of all ProductPricingCalculation', () => {
55
- expect(pricingSheet.gross()).toEqual(535);
57
+ assert.equal(pricingSheet.gross(), 535);
56
58
  });
57
59
 
58
60
  it('net() should return the NET sum of all ProductPricingCalculation (i.e before TAX)', () => {
59
- expect(pricingSheet.net()).toEqual(460);
61
+ assert.equal(pricingSheet.net(), 460);
60
62
  });
61
63
 
62
64
  describe('total()', () => {
63
65
  it('should return sum of all ProductPricingCalculations ', () => {
64
- expect(pricingSheet.total()).toEqual({ amount: 535, currency: 'CHF' });
65
- expect(pricingSheet.total()).toEqual({ amount: pricingSheet.gross(), currency: 'CHF' });
66
+ assert.deepEqual(pricingSheet.total(), { amount: 535, currency: 'CHF' });
67
+ assert.deepEqual(pricingSheet.total(), { amount: pricingSheet.gross(), currency: 'CHF' });
66
68
  });
67
69
 
68
70
  it('should return sum of all ProductPricingCalculations ', () => {
69
- expect(pricingSheet.total({ useNetPrice: true })).toEqual({ amount: 460, currency: 'CHF' });
70
- expect(pricingSheet.total({ useNetPrice: true })).toEqual({
71
+ assert.deepEqual(pricingSheet.total({ useNetPrice: true }), { amount: 460, currency: 'CHF' });
72
+ assert.deepEqual(pricingSheet.total({ useNetPrice: true }), {
71
73
  amount: pricingSheet.net(),
72
74
  currency: 'CHF',
73
75
  });
74
76
  });
75
77
 
76
78
  it('should return sum of all ProductPricingCalculations for the provided category ', () => {
77
- expect(pricingSheet.total({ category: 'ITEM' })).toEqual({ amount: 400, currency: 'CHF' });
78
- expect(pricingSheet.total({ category: 'DISCOUNT' })).toEqual({ amount: 60, currency: 'CHF' });
79
- expect(pricingSheet.total({ category: 'TAX' })).toEqual({ amount: 75, currency: 'CHF' });
79
+ assert.deepEqual(pricingSheet.total({ category: 'ITEM' }), { amount: 400, currency: 'CHF' });
80
+ assert.deepEqual(pricingSheet.total({ category: 'DISCOUNT' }), { amount: 60, currency: 'CHF' });
81
+ assert.deepEqual(pricingSheet.total({ category: 'TAX' }), { amount: 75, currency: 'CHF' });
80
82
  });
81
83
  });
82
84
 
83
85
  describe('isValid()', () => {
84
86
  it('should return true if there is at least 1 registered ProductPricingCalculation ', () => {
85
- expect(pricingSheet.isValid()).toEqual(true);
87
+ assert.equal(pricingSheet.isValid(), true);
86
88
  });
87
89
  it('should return false if there is no registered ProductPricingCalculation ', () => {
88
90
  const sheet = ProductPricingSheet({ ...pricingSheetParams, calculation: [] });
89
- expect(sheet.isValid()).toEqual(false);
91
+ assert.equal(sheet.isValid(), false);
90
92
  });
91
93
  });
92
94
 
93
95
  describe('getRawPricingSheet', () => {
94
96
  it('should return all registered ProductPricingCalculation', () => {
95
- expect(pricingSheet.getRawPricingSheet()).toEqual(calculations);
97
+ assert.deepEqual(pricingSheet.getRawPricingSheet(), calculations);
96
98
  });
97
99
  });
98
100
 
99
101
  describe('taxSum', () => {
100
102
  it('should return the sum of TAX calculation registered on the adapter', () => {
101
- expect(pricingSheet.taxSum()).toEqual(75);
103
+ assert.equal(pricingSheet.taxSum(), 75);
102
104
  });
103
105
  });
104
106
 
105
107
  describe('unitPrice', () => {
106
108
  it('should return the GROSS sum for a product price useNetPrice:false', () => {
107
- expect(pricingSheet.unitPrice({ useNetPrice: false })).toEqual({ amount: 268, currency: 'CHF' });
109
+ assert.deepEqual(pricingSheet.unitPrice({ useNetPrice: false }), { amount: 268, currency: 'CHF' });
108
110
  });
109
111
 
110
112
  it('should return the NET sum for a product price when useNetPrice:true', () => {
111
- expect(pricingSheet.unitPrice({ useNetPrice: true })).toEqual({ amount: 230, currency: 'CHF' });
113
+ assert.deepEqual(pricingSheet.unitPrice({ useNetPrice: true }), { amount: 230, currency: 'CHF' });
112
114
  });
113
115
  });
114
116
 
115
117
  describe('discountPrices', () => {
116
118
  it('should return the sum of all discounts registered on the price sheet based on discountId', () => {
117
- expect(pricingSheet.discountPrices('for-all')).toEqual([
119
+ assert.deepEqual(pricingSheet.discountPrices('for-all'), [
118
120
  { amount: 40, currency: 'CHF', discountId: 'for-all' },
119
121
  ]);
120
- expect(pricingSheet.discountPrices('special')).toEqual([
122
+ assert.deepEqual(pricingSheet.discountPrices('special'), [
121
123
  { amount: 20, currency: 'CHF', discountId: 'special' },
122
124
  ]);
123
125
  });
124
126
 
125
127
  it('should return empty array if discount with the provided discountId is not found', () => {
126
- expect(pricingSheet.discountPrices('non-existing')).toEqual([]);
128
+ assert.deepEqual(pricingSheet.discountPrices('non-existing'), []);
127
129
  });
128
130
  });
129
131
  });
@@ -1,21 +1,23 @@
1
+ import { describe, it } from 'node:test';
1
2
  import { periodForReferenceDate } from './EnrollmentAdapter.js';
3
+ import assert from 'node:assert';
2
4
 
3
5
  describe('periodForReferenceDate', () => {
4
6
  it('Should return 1 week interval from When passed a given date', () => {
5
- expect(periodForReferenceDate(new Date('2022-12-03T17:00:00.000Z'))).toEqual({
7
+ assert.deepStrictEqual(periodForReferenceDate(new Date('2022-12-03T17:00:00.000Z')), {
6
8
  start: new Date('2022-12-03T17:00:00.000Z'),
7
9
  end: new Date('2022-12-10T17:00:00.000Z'),
8
10
  });
9
11
  });
10
12
  it('Should return 2 week interval from When passed 2 as interval', () => {
11
- expect(periodForReferenceDate(new Date('2022-12-03T17:00:00.000Z'), 2)).toEqual({
13
+ assert.deepStrictEqual(periodForReferenceDate(new Date('2022-12-03T17:00:00.000Z'), 2), {
12
14
  start: new Date('2022-12-03T17:00:00.000Z'),
13
15
  end: new Date('2022-12-17T17:00:00.000Z'),
14
16
  });
15
17
  });
16
18
 
17
19
  it('Should return 2 HOURS when interval is set to HOURS', () => {
18
- expect(periodForReferenceDate(new Date('2022-12-03T17:00:00.000Z'), 2, 'HOURS')).toEqual({
20
+ assert.deepStrictEqual(periodForReferenceDate(new Date('2022-12-03T17:00:00.000Z'), 2, 'HOURS'), {
19
21
  start: new Date('2022-12-03T17:00:00.000Z'),
20
22
  end: new Date('2022-12-03T19:00:00.000Z'),
21
23
  });
package/jest.config.js DELETED
@@ -1,17 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- export default {
3
- preset: 'ts-jest/presets/default-esm', // or other ESM presets
4
- testEnvironment: 'node',
5
- extensionsToTreatAsEsm: ['.ts'],
6
- transform: {
7
- '^.+\\.tsx?$': [
8
- 'ts-jest',
9
- {
10
- useESM: true,
11
- },
12
- ],
13
- },
14
- moduleNameMapper: {
15
- '^(\\.{1,2}/.*)\\.js$': '$1',
16
- },
17
- };
@@ -1,5 +0,0 @@
1
- describe('Bookmark', () => {
2
- it('Check Bookmarks module', () => {
3
- expect(true).toBeTruthy();
4
- });
5
- });