@unchainedshop/core-products 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-products",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "main": "lib/products-index.js",
5
5
  "types": "lib/products-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",
@@ -37,8 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^22.13.4",
40
- "jest": "^29.7.0",
41
- "ts-jest": "^29.2.5",
40
+ "tsx": "^4.19.2",
42
41
  "typescript": "^5.7.3"
43
42
  }
44
43
  }
@@ -1,12 +1,14 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  import { buildFindSelector } from './configureProductsModule';
2
4
 
3
5
  describe('Product', () => {
4
6
  describe('buildFindSelector', () => {
5
7
  it('Return correct filter object object when no parameter is passed', () => {
6
- expect(buildFindSelector({} as any)).toEqual({ status: { $eq: 'ACTIVE' } });
8
+ assert.deepStrictEqual(buildFindSelector({} as any), { status: { $eq: 'ACTIVE' } });
7
9
  });
8
10
  it('Return correct filter object object when passed includeDraft:true, productsIds, productSelector, queryString, slugs, tags ', () => {
9
- expect(
11
+ assert.deepStrictEqual(
10
12
  buildFindSelector({
11
13
  includeDrafts: true,
12
14
  productIds: ['product-1-id', 'product-id-2'],
@@ -15,18 +17,19 @@ describe('Product', () => {
15
17
  slugs: ['slug-1', 'slug-2'],
16
18
  tags: ['tag-1', 'tag-2'],
17
19
  } as any),
18
- ).toEqual({
19
- type: 'SIMPLE_PRODUCT',
20
- _id: { $in: ['product-1-id', 'product-id-2'] },
21
- slugs: { $in: ['slug-1', 'slug-2'] },
22
- tags: { $all: ['tag-1', 'tag-2'] },
23
- $text: { $search: 'hello world' },
24
- status: { $in: ['ACTIVE', null] },
25
- });
20
+ {
21
+ type: 'SIMPLE_PRODUCT',
22
+ _id: { $in: ['product-1-id', 'product-id-2'] },
23
+ slugs: { $in: ['slug-1', 'slug-2'] },
24
+ tags: { $all: ['tag-1', 'tag-2'] },
25
+ $text: { $search: 'hello world' },
26
+ status: { $in: ['ACTIVE', null] },
27
+ },
28
+ );
26
29
  });
27
30
 
28
31
  it('Return correct filter object object when passed includeDraft:true, productsIds, productSelector, queryString, slugs ', () => {
29
- expect(
32
+ assert.deepStrictEqual(
30
33
  buildFindSelector({
31
34
  includeDrafts: true,
32
35
  productIds: ['product-1-id', 'product-id-2'],
@@ -34,63 +37,67 @@ describe('Product', () => {
34
37
  queryString: 'hello world',
35
38
  slugs: ['slug-1', 'slug-2'],
36
39
  } as any),
37
- ).toEqual({
38
- type: 'SIMPLE_PRODUCT',
39
- _id: { $in: ['product-1-id', 'product-id-2'] },
40
- slugs: { $in: ['slug-1', 'slug-2'] },
41
- $text: { $search: 'hello world' },
42
- status: { $in: ['ACTIVE', null] },
43
- });
40
+ {
41
+ type: 'SIMPLE_PRODUCT',
42
+ _id: { $in: ['product-1-id', 'product-id-2'] },
43
+ slugs: { $in: ['slug-1', 'slug-2'] },
44
+ $text: { $search: 'hello world' },
45
+ status: { $in: ['ACTIVE', null] },
46
+ },
47
+ );
44
48
  });
45
49
 
46
50
  it('Return correct filter object object when passed includeDraft:true, productsIds, productSelector, queryString ', () => {
47
- expect(
51
+ assert.deepStrictEqual(
48
52
  buildFindSelector({
49
53
  includeDrafts: true,
50
54
  productIds: ['product-1-id', 'product-id-2'],
51
55
  productSelector: { type: 'SIMPLE_PRODUCT' },
52
56
  queryString: 'hello world',
53
57
  } as any),
54
- ).toEqual({
55
- type: 'SIMPLE_PRODUCT',
56
- _id: { $in: ['product-1-id', 'product-id-2'] },
57
- $text: { $search: 'hello world' },
58
- status: { $in: ['ACTIVE', null] },
59
- });
58
+ {
59
+ type: 'SIMPLE_PRODUCT',
60
+ _id: { $in: ['product-1-id', 'product-id-2'] },
61
+ $text: { $search: 'hello world' },
62
+ status: { $in: ['ACTIVE', null] },
63
+ },
64
+ );
60
65
  });
61
66
 
62
67
  it('Return correct filter object object when passed includeDraft:true, productsIds, productSelector ', () => {
63
- expect(
68
+ assert.deepStrictEqual(
64
69
  buildFindSelector({
65
70
  includeDrafts: true,
66
71
  productIds: ['product-1-id', 'product-id-2'],
67
72
  productSelector: { type: 'SIMPLE_PRODUCT' },
68
73
  } as any),
69
- ).toEqual({
70
- type: 'SIMPLE_PRODUCT',
71
- _id: { $in: ['product-1-id', 'product-id-2'] },
72
- status: { $in: ['ACTIVE', null] },
73
- });
74
+ {
75
+ type: 'SIMPLE_PRODUCT',
76
+ _id: { $in: ['product-1-id', 'product-id-2'] },
77
+ status: { $in: ['ACTIVE', null] },
78
+ },
79
+ );
74
80
  });
75
81
 
76
82
  it('Return correct filter object object when passed includeDraft:true, productsIds ', () => {
77
- expect(
83
+ assert.deepStrictEqual(
78
84
  buildFindSelector({ includeDrafts: true, productIds: ['product-1-id', 'product-id-2'] } as any),
79
- ).toEqual({
80
- _id: { $in: ['product-1-id', 'product-id-2'] },
81
- status: { $in: ['ACTIVE', null] },
82
- });
85
+ {
86
+ _id: { $in: ['product-1-id', 'product-id-2'] },
87
+ status: { $in: ['ACTIVE', null] },
88
+ },
89
+ );
83
90
  });
84
91
 
85
92
  it('Return filter tags if passed as a string ', () => {
86
- expect(buildFindSelector({ tags: 'string-tag' } as any)).toEqual({
93
+ assert.deepStrictEqual(buildFindSelector({ tags: 'string-tag' } as any), {
87
94
  tags: 'string-tag',
88
95
  status: { $eq: 'ACTIVE' },
89
96
  });
90
97
  });
91
98
 
92
99
  it('includeDrafts true should add null to status filter array as null ', () => {
93
- expect(buildFindSelector({ includeDrafts: true } as any)).toEqual({
100
+ assert.deepStrictEqual(buildFindSelector({ includeDrafts: true } as any), {
94
101
  status: { $in: ['ACTIVE', null] },
95
102
  });
96
103
  });
@@ -1,17 +1,19 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  import { getDecimals, normalizeRate } from '../configureProductPrices.js';
2
4
 
3
5
  describe('Rate conversion', () => {
4
6
  it('getDecimals', () => {
5
- expect(getDecimals(18)).toBe(9);
6
- expect(getDecimals(8)).toBe(8);
7
- expect(getDecimals(1)).toBe(1);
8
- expect(getDecimals(null)).toBe(2);
9
- expect(getDecimals(undefined)).toBe(2);
10
- expect(getDecimals(0)).toBe(0);
7
+ assert.strictEqual(getDecimals(18), 9);
8
+ assert.strictEqual(getDecimals(8), 8);
9
+ assert.strictEqual(getDecimals(1), 1);
10
+ assert.strictEqual(getDecimals(null), 2);
11
+ assert.strictEqual(getDecimals(undefined), 2);
12
+ assert.strictEqual(getDecimals(0), 0);
11
13
  });
12
14
 
13
15
  it('normalizeRate converting between FIAT with 2 decimals', () => {
14
- expect(
16
+ assert.strictEqual(
15
17
  normalizeRate(
16
18
  {
17
19
  isoCode: 'USD',
@@ -23,9 +25,10 @@ describe('Rate conversion', () => {
23
25
  } as any,
24
26
  { quoteCurrency: 'USD', rate: 0.9 } as any,
25
27
  ),
26
- ).toBe(1.1111111111111112);
28
+ 1.1111111111111112,
29
+ );
27
30
 
28
- expect(
31
+ assert.strictEqual(
29
32
  normalizeRate(
30
33
  {
31
34
  isoCode: 'CHF', // in Rappen
@@ -37,11 +40,12 @@ describe('Rate conversion', () => {
37
40
  } as any,
38
41
  { quoteCurrency: 'USD', rate: 0.9 } as any,
39
42
  ),
40
- ).toBe(0.9);
43
+ 0.9,
44
+ );
41
45
  });
42
46
 
43
47
  it('normalizeRate converting between FIAT with 0 and 2 decimals', () => {
44
- expect(
48
+ assert.strictEqual(
45
49
  normalizeRate(
46
50
  {
47
51
  isoCode: 'CLP', // in Pesos
@@ -53,9 +57,10 @@ describe('Rate conversion', () => {
53
57
  } as any,
54
58
  { baseCurrency: 'CLP', quoteCurrency: 'CHF', rate: 0.0010451376 } as any,
55
59
  ),
56
- ).toBe(0.10451376);
60
+ 0.10451376,
61
+ );
57
62
 
58
- expect(
63
+ assert.strictEqual(
59
64
  normalizeRate(
60
65
  {
61
66
  isoCode: 'CLP', // in Pesos
@@ -73,11 +78,12 @@ describe('Rate conversion', () => {
73
78
  timestamp: undefined,
74
79
  },
75
80
  ),
76
- ).toBe(0.10451942626276765);
81
+ 0.10451942626276765,
82
+ );
77
83
  });
78
84
 
79
85
  it('normalizeRate converting FIAT to/from Crypto with Crypto->Fiat Pair', () => {
80
- expect(
86
+ assert.strictEqual(
81
87
  normalizeRate(
82
88
  {
83
89
  isoCode: 'USD', // in Pennies
@@ -89,9 +95,10 @@ describe('Rate conversion', () => {
89
95
  } as any,
90
96
  { baseCurrency: 'BTC', quoteCurrency: 'USD', rate: 19284.61 } as any,
91
97
  ),
92
- ).toBe(518.5482102049251);
98
+ 518.5482102049251,
99
+ );
93
100
 
94
- expect(
101
+ assert.strictEqual(
95
102
  normalizeRate(
96
103
  {
97
104
  isoCode: 'ETH', // in GWEI
@@ -103,13 +110,14 @@ describe('Rate conversion', () => {
103
110
  } as any,
104
111
  { baseCurrency: 'ETH', quoteCurrency: 'CHF', rate: 1311.63 } as any,
105
112
  ),
106
- ).toBe(0.000131163);
113
+ 0.000131163,
114
+ );
107
115
 
108
116
  // 1 ETH = 0.000131163
109
117
  });
110
118
 
111
119
  it('normalizeRate converting FIAT to/from Crypto with Fiat->Crypto Pair', () => {
112
- expect(
120
+ assert.strictEqual(
113
121
  normalizeRate(
114
122
  {
115
123
  isoCode: 'USD', // in Pennies
@@ -121,12 +129,13 @@ describe('Rate conversion', () => {
121
129
  } as any,
122
130
  { baseCurrency: 'USD', quoteCurrency: 'BTC', rate: 0.000052 } as any,
123
131
  ),
124
- ).toBe(52);
132
+ 52,
133
+ );
125
134
 
126
135
  // 1 USD = 100 Pennies
127
136
  // 100 Pennies = 5200 Satoshis
128
137
 
129
- expect(
138
+ assert.strictEqual(
130
139
  normalizeRate(
131
140
  {
132
141
  isoCode: 'ETH', // in GWEI
@@ -138,7 +147,8 @@ describe('Rate conversion', () => {
138
147
  } as any,
139
148
  { baseCurrency: 'CLP', quoteCurrency: 'ETH', rate: 0.000000794 } as any,
140
149
  ),
141
- ).toBe(0.0012594458438287153);
150
+ 0.0012594458438287153,
151
+ );
142
152
 
143
153
  // 1 ETH = 1,000,000,000 GWEI (10^9)
144
154
  // 1,000,000,000 GWEI = 1’259’445 CLP
@@ -1,14 +1,16 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  import { getPriceLevels } from './getPriceLevels.js';
2
4
  import product from '../../mock/product.js';
3
5
 
4
6
  describe('Price level', () => {
5
7
  it('Should return empty array when country code is not specified', () => {
6
- expect(getPriceLevels({ product, currencyCode: 'CHF' } as any)).toHaveLength(0);
8
+ assert.strictEqual(getPriceLevels({ product, currencyCode: 'CHF' } as any).length, 0);
7
9
  });
8
10
 
9
11
  it('Should return empty array when country code is not specified', () => {
10
- expect(getPriceLevels({ product, countryCode: 'ET' } as any)).toHaveLength(1);
11
- expect(getPriceLevels({ product, countryCode: 'ET' } as any)).toEqual([
12
+ assert.strictEqual(getPriceLevels({ product, countryCode: 'ET' } as any).length, 1);
13
+ assert.deepStrictEqual(getPriceLevels({ product, countryCode: 'ET' } as any), [
12
14
  {
13
15
  amount: 20000,
14
16
  maxQuantity: 2,
@@ -18,8 +20,8 @@ describe('Price level', () => {
18
20
  countryCode: 'ET',
19
21
  },
20
22
  ]);
21
- expect(getPriceLevels({ product, countryCode: 'CH' } as any)).toHaveLength(3);
22
- expect(getPriceLevels({ product, countryCode: 'CH' } as any)).toEqual([
23
+ assert.strictEqual(getPriceLevels({ product, countryCode: 'CH' } as any).length, 3);
24
+ assert.deepStrictEqual(getPriceLevels({ product, countryCode: 'CH' } as any), [
23
25
  {
24
26
  amount: 1000,
25
27
  maxQuantity: null,
@@ -48,7 +50,7 @@ describe('Price level', () => {
48
50
  });
49
51
 
50
52
  it('Should return all prices for a given country sorted by max quantity ASC', () => {
51
- expect(getPriceLevels({ product, countryCode: 'CH' } as any)).toEqual([
53
+ assert.deepStrictEqual(getPriceLevels({ product, countryCode: 'CH' } as any), [
52
54
  {
53
55
  amount: 1000,
54
56
  maxQuantity: null,
@@ -77,7 +79,13 @@ describe('Price level', () => {
77
79
  });
78
80
 
79
81
  it('Should return all prices currencyCode', () => {
80
- expect(getPriceLevels({ product, countryCode: 'CH', currencyCode: 'CHF' } as any)).toHaveLength(2);
81
- expect(getPriceLevels({ product, countryCode: 'CH', currencyCode: 'ETH' } as any)).toHaveLength(1);
82
+ assert.strictEqual(
83
+ getPriceLevels({ product, countryCode: 'CH', currencyCode: 'CHF' } as any).length,
84
+ 2,
85
+ );
86
+ assert.strictEqual(
87
+ getPriceLevels({ product, countryCode: 'CH', currencyCode: 'ETH' } as any).length,
88
+ 1,
89
+ );
82
90
  });
83
91
  });
@@ -1,49 +1,53 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  import { getPriceRange } from './getPriceRange.js';
2
4
  import product from '../../mock/product.js';
3
5
  import { getPriceLevels } from './getPriceLevels.js';
4
6
 
5
7
  describe('Price Range', () => {
6
8
  it('Should return the minimum and maximum price of a product when there are multiple prices', () => {
7
- expect(
9
+ assert.deepStrictEqual(
8
10
  getPriceRange({
9
11
  productId: product._id,
10
12
  prices: getPriceLevels({ product, countryCode: 'CH', currencyCode: 'CHF' } as any),
11
13
  }),
12
- ).toEqual({
13
- minPrice: {
14
- isTaxable: false,
15
- isNetPrice: false,
16
- amount: 750,
17
- currencyCode: 'CHF',
14
+ {
15
+ minPrice: {
16
+ isTaxable: false,
17
+ isNetPrice: false,
18
+ amount: 750,
19
+ currencyCode: 'CHF',
20
+ },
21
+ maxPrice: {
22
+ isTaxable: false,
23
+ isNetPrice: false,
24
+ amount: 1000,
25
+ currencyCode: 'CHF',
26
+ },
18
27
  },
19
- maxPrice: {
20
- isTaxable: false,
21
- isNetPrice: false,
22
- amount: 1000,
23
- currencyCode: 'CHF',
24
- },
25
- });
28
+ );
26
29
  });
27
30
 
28
31
  it('Should still return and object with min and max price field when no price list is provided', () => {
29
- expect(
32
+ assert.deepStrictEqual(
30
33
  getPriceRange({
31
34
  productId: product._id,
32
35
  prices: getPriceLevels({ product, countryCode: 'DE', currencyCode: 'EUR' } as any),
33
36
  }),
34
- ).toEqual({
35
- minPrice: {
36
- isTaxable: false,
37
- isNetPrice: false,
38
- amount: NaN,
39
- currencyCode: undefined,
40
- },
41
- maxPrice: {
42
- isTaxable: false,
43
- isNetPrice: false,
44
- amount: NaN,
45
- currencyCode: undefined,
37
+ {
38
+ minPrice: {
39
+ isTaxable: false,
40
+ isNetPrice: false,
41
+ amount: NaN,
42
+ currencyCode: undefined,
43
+ },
44
+ maxPrice: {
45
+ isTaxable: false,
46
+ isNetPrice: false,
47
+ amount: NaN,
48
+ currencyCode: undefined,
49
+ },
46
50
  },
47
- });
51
+ );
48
52
  });
49
53
  });
@@ -1,5 +1,7 @@
1
+ import { describe, it } from 'node:test';
2
+ import assert from 'node:assert';
1
3
  describe('Product', () => {
2
4
  it('Product', () => {
3
- expect(true).toBeTruthy();
5
+ assert(true);
4
6
  });
5
7
  });
package/jest.config.js DELETED
@@ -1,18 +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
- rootDir: '.',
18
- };