|
1 |
| -import { expect, describe, it } from '@jest/globals'; |
2 |
| -import DefaultMutator from '../default.js'; |
| 1 | +import { expect, describe, it } from '@jest/globals' |
| 2 | +import DefaultMutator from '../default.js' |
3 | 3 |
|
4 | 4 | class ExampleMutator extends DefaultMutator {
|
5 |
| - setSkuAttribute(sku) { |
6 |
| - return `*${sku}*`; |
7 |
| - } |
| 5 | + setSkuAttribute (sku) { |
| 6 | + return `*${sku}*` |
| 7 | + } |
8 | 8 |
|
9 |
| - setProductGroupAttribute(productGroup) { |
10 |
| - return `*${productGroup}*`; |
11 |
| - } |
| 9 | + setProductGroupAttribute (productGroup) { |
| 10 | + return `*${productGroup}*` |
| 11 | + } |
12 | 12 |
|
13 |
| - setSubTestAttribute(value) { |
14 |
| - return `*${value}*`; |
15 |
| - } |
| 13 | + setSubTestAttribute (value) { |
| 14 | + return `*${value}*` |
| 15 | + } |
16 | 16 |
|
17 |
| - setSubFirstAttribute(value) { |
18 |
| - return value; |
19 |
| - } |
| 17 | + setSubFirstAttribute (value) { |
| 18 | + return value |
| 19 | + } |
20 | 20 |
|
21 |
| - setSubLastAttribute(value) { |
22 |
| - return value; |
23 |
| - } |
| 21 | + setSubLastAttribute (value) { |
| 22 | + return value |
| 23 | + } |
24 | 24 | }
|
25 | 25 |
|
26 | 26 | describe('Test the filter mutator', () => {
|
27 |
| - it('It should skip empty values', () => { |
28 |
| - const result = DefaultMutator.create({ |
29 |
| - test: 'ok', |
30 |
| - test2: null, |
31 |
| - test3: undefined, |
32 |
| - test4: NaN, |
33 |
| - test5: false, |
34 |
| - test6: 0, |
35 |
| - test7: 1, |
36 |
| - }); |
37 |
| - expect({ ...result }).toEqual({ |
38 |
| - test: 'ok', |
39 |
| - test5: false, |
40 |
| - test6: 0, |
41 |
| - test7: 1, |
42 |
| - }); |
43 |
| - }); |
| 27 | + it('It should skip empty values', () => { |
| 28 | + const result = DefaultMutator.create({ |
| 29 | + test: 'ok', |
| 30 | + test2: null, |
| 31 | + test3: undefined, |
| 32 | + test4: NaN, |
| 33 | + test5: false, |
| 34 | + test6: 0, |
| 35 | + test7: 1 |
| 36 | + }) |
| 37 | + expect({ ...result }).toEqual({ |
| 38 | + test: 'ok', |
| 39 | + test5: false, |
| 40 | + test6: 0, |
| 41 | + test7: 1 |
| 42 | + }) |
| 43 | + }) |
44 | 44 |
|
45 |
| - it('It should set the item', () => { |
46 |
| - const result = ExampleMutator.create({ sku: 42, test: 'ok' }); |
47 |
| - expect({ ...result }).toEqual({ sku: '*42*', test: 'ok' }); |
48 |
| - }); |
| 45 | + it('It should set the item', () => { |
| 46 | + const result = ExampleMutator.create({ sku: 42, test: 'ok' }) |
| 47 | + expect({ ...result }).toEqual({ sku: '*42*', test: 'ok' }) |
| 48 | + }) |
49 | 49 |
|
50 |
| - it('It should set the item only if the value isnt null', () => { |
51 |
| - const result = ExampleMutator.create({ |
52 |
| - sku: null, |
53 |
| - test: 'ok', |
54 |
| - test2: null, |
55 |
| - }); |
56 |
| - expect({ ...result }).toEqual({ test: 'ok' }); |
57 |
| - }); |
| 50 | + it('It should set the item only if the value isnt null', () => { |
| 51 | + const result = ExampleMutator.create({ |
| 52 | + sku: null, |
| 53 | + test: 'ok', |
| 54 | + test2: null |
| 55 | + }) |
| 56 | + expect({ ...result }).toEqual({ test: 'ok' }) |
| 57 | + }) |
58 | 58 |
|
59 |
| - it('It should only call a setter', () => { |
60 |
| - const result = ExampleMutator.create({ sku: 42 }); |
61 |
| - expect({ ...result }).toEqual({ sku: '*42*' }); |
62 |
| - }); |
| 59 | + it('It should only call a setter', () => { |
| 60 | + const result = ExampleMutator.create({ sku: 42 }) |
| 61 | + expect({ ...result }).toEqual({ sku: '*42*' }) |
| 62 | + }) |
63 | 63 |
|
64 |
| - it('It should handle the product.group', () => { |
65 |
| - const result = ExampleMutator.create({ product: { group: 'test' } }); |
66 |
| - expect({ ...result }).toEqual({ product: { group: '*test*' } }); |
67 |
| - }); |
| 64 | + it('It should handle the product.group', () => { |
| 65 | + const result = ExampleMutator.create({ product: { group: 'test' } }) |
| 66 | + expect({ ...result }).toEqual({ product: { group: '*test*' } }) |
| 67 | + }) |
68 | 68 |
|
69 |
| - it('It should handle the product_group', () => { |
70 |
| - const result = ExampleMutator.create({ product_group: 'test' }); |
71 |
| - expect({ ...result }).toEqual({ product_group: '*test*' }); |
72 |
| - }); |
| 69 | + it('It should handle the product_group', () => { |
| 70 | + const result = ExampleMutator.create({ product_group: 'test' }) |
| 71 | + expect({ ...result }).toEqual({ product_group: '*test*' }) |
| 72 | + }) |
73 | 73 |
|
74 |
| - it('It should not call a setter', () => { |
75 |
| - const result = ExampleMutator.create({ test: 'ok', test2: 'also ok' }); |
76 |
| - expect({ ...result }).toEqual({ test: 'ok', test2: 'also ok' }); |
77 |
| - }); |
| 74 | + it('It should not call a setter', () => { |
| 75 | + const result = ExampleMutator.create({ test: 'ok', test2: 'also ok' }) |
| 76 | + expect({ ...result }).toEqual({ test: 'ok', test2: 'also ok' }) |
| 77 | + }) |
78 | 78 |
|
79 |
| - it('It should hydrate the object with new data', () => { |
80 |
| - const result = ExampleMutator.create({ test: 'ok', test2: 'also ok' }); |
81 |
| - expect({ ...result }).toEqual({ test: 'ok', test2: 'also ok' }); |
82 |
| - result.hydrate({ sku: 43 }); |
83 |
| - expect({ ...result }).toEqual({ |
84 |
| - sku: '*43*', |
85 |
| - test: 'ok', |
86 |
| - test2: 'also ok', |
87 |
| - }); |
88 |
| - result.hydrate({ test: 'another text' }); |
89 |
| - expect({ ...result }).toEqual({ |
90 |
| - sku: '*43*', |
91 |
| - test: 'another text', |
92 |
| - test2: 'also ok', |
93 |
| - }); |
94 |
| - }); |
| 79 | + it('It should hydrate the object with new data', () => { |
| 80 | + const result = ExampleMutator.create({ test: 'ok', test2: 'also ok' }) |
| 81 | + expect({ ...result }).toEqual({ test: 'ok', test2: 'also ok' }) |
| 82 | + result.hydrate({ sku: 43 }) |
| 83 | + expect({ ...result }).toEqual({ |
| 84 | + sku: '*43*', |
| 85 | + test: 'ok', |
| 86 | + test2: 'also ok' |
| 87 | + }) |
| 88 | + result.hydrate({ test: 'another text' }) |
| 89 | + expect({ ...result }).toEqual({ |
| 90 | + sku: '*43*', |
| 91 | + test: 'another text', |
| 92 | + test2: 'also ok' |
| 93 | + }) |
| 94 | + }) |
95 | 95 |
|
96 |
| - it('It should also mutate the sub fields', () => { |
97 |
| - const result = ExampleMutator.create({ |
98 |
| - noMutation: 'ok', |
99 |
| - sub: { |
100 |
| - first: 1, |
101 |
| - test: 42, |
102 |
| - last: 99, |
103 |
| - }, |
104 |
| - }); |
105 |
| - expect({ ...result }).toEqual({ |
106 |
| - noMutation: 'ok', |
107 |
| - sub: { |
108 |
| - first: 1, |
109 |
| - test: '*42*', |
110 |
| - last: 99, |
111 |
| - }, |
112 |
| - }); |
113 |
| - }); |
| 96 | + it('It should also mutate the sub fields', () => { |
| 97 | + const result = ExampleMutator.create({ |
| 98 | + noMutation: 'ok', |
| 99 | + sub: { |
| 100 | + first: 1, |
| 101 | + test: 42, |
| 102 | + last: 99 |
| 103 | + } |
| 104 | + }) |
| 105 | + expect({ ...result }).toEqual({ |
| 106 | + noMutation: 'ok', |
| 107 | + sub: { |
| 108 | + first: 1, |
| 109 | + test: '*42*', |
| 110 | + last: 99 |
| 111 | + } |
| 112 | + }) |
| 113 | + }) |
114 | 114 |
|
115 |
| - it('It should handle the product_group', () => { |
116 |
| - const result = ExampleMutator.create({ |
117 |
| - product: { group: 'test' }, |
118 |
| - another: { test: 'ok' }, |
119 |
| - }); |
120 |
| - expect({ ...result }).toEqual({ |
121 |
| - product: { group: '*test*' }, |
122 |
| - another: { test: 'ok' }, |
123 |
| - }); |
124 |
| - }); |
125 |
| -}); |
| 115 | + it('It should handle the product_group', () => { |
| 116 | + const result = ExampleMutator.create({ |
| 117 | + product: { group: 'test' }, |
| 118 | + another: { test: 'ok' } |
| 119 | + }) |
| 120 | + expect({ ...result }).toEqual({ |
| 121 | + product: { group: '*test*' }, |
| 122 | + another: { test: 'ok' } |
| 123 | + }) |
| 124 | + }) |
| 125 | +}) |
0 commit comments