-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathcheckout-map-user-error-codes-test.js
46 lines (39 loc) · 1.84 KB
/
checkout-map-user-error-codes-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import assert from 'assert';
import checkoutUserErrorsMapper from '../src/checkout-map-user-error-codes';
suite('checkout-map-user-error-codes-test', () => {
test('it returns an empty array if there are no user errors or warnings', () => {
assert.deepStrictEqual(checkoutUserErrorsMapper([], []), []);
});
test('it maps a cart user error code to a checkout user error code, preserving the error message and field', () => {
const userErrors = [
{
code: 'ADDRESS_FIELD_IS_TOO_LONG',
field: 'address',
message: 'The provided address is too long.'
}
];
const warnings = [];
assert.deepStrictEqual(
checkoutUserErrorsMapper(userErrors, warnings),
[{code: 'TOO_LONG', field: 'address', message: 'The provided address is too long.'}]
);
});
test('it maps a cart warning code to a checkout user error code, preserving the warning message', () => {
const userErrors = [];
const warnings = [
{
code: 'MERCHANDISE_NOT_ENOUGH_STOCK',
message: 'The product is out of stock.'
}
];
assert.deepStrictEqual(
checkoutUserErrorsMapper(userErrors, warnings),
[{code: 'NOT_ENOUGH_IN_STOCK', message: 'The product is out of stock.'}]
);
});
test('it maps cart user error and warning codes to checkout user error codes, if both cart user errors and cart warnings are present', () => {
const userErrors = [{code: 'ADDRESS_FIELD_IS_TOO_LONG', field: 'address', message: 'The provided address is too long.'}];
const warnings = [{code: 'MERCHANDISE_NOT_ENOUGH_STOCK', message: 'The product is out of stock.'}];
assert.deepStrictEqual(checkoutUserErrorsMapper(userErrors, warnings), [{code: 'TOO_LONG', field: 'address', message: 'The provided address is too long.'}, {code: 'NOT_ENOUGH_IN_STOCK', message: 'The product is out of stock.'}]);
});
});