Skip to content

Commit abad813

Browse files
jonas-hoebenreichMayishadaledupreezwjrosa
authored
Make normalizeLineItems More Robust by Adding Fallback (#4624)
* check for null value and add fallback to displayItem.name * add test --------- Co-authored-by: Mayisha <[email protected]> Co-authored-by: daledupreez <[email protected]> Co-authored-by: Wesley Rosa <[email protected]>
1 parent 1f0c7c3 commit abad813

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

client/express-checkout/utils/__tests__/normalize.test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,44 @@ describe( 'Express checkout normalization', () => {
9494
);
9595
} );
9696

97+
test( 'normalizes line item properly where label is not set', () => {
98+
const displayItems = [
99+
{
100+
name: 'Item 1',
101+
label: null,
102+
amount: 100,
103+
},
104+
{
105+
name: 'Item 2',
106+
label: undefined,
107+
amount: 200,
108+
},
109+
{
110+
name: 'Item 3',
111+
amount: 300,
112+
},
113+
];
114+
115+
const expected = [
116+
{
117+
name: 'Item 1',
118+
amount: 100,
119+
},
120+
{
121+
name: 'Item 2',
122+
amount: 200,
123+
},
124+
{
125+
name: 'Item 3',
126+
amount: 300,
127+
},
128+
];
129+
130+
expect( normalizeLineItems( displayItems ) ).toStrictEqual(
131+
expected
132+
);
133+
} );
134+
97135
test( 'normalizes discount line item properly', () => {
98136
const displayItems = [
99137
{

client/express-checkout/utils/normalize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const normalizeLineItems = ( displayItems ) => {
1818
}
1919

2020
return {
21-
name: displayItem.label,
21+
name: displayItem.label ?? displayItem.name,
2222
amount,
2323
};
2424
} );

0 commit comments

Comments
 (0)