@rebilly/instruments 3.16.4-beta.0 → 3.16.5-beta.0

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": "@rebilly/instruments",
3
- "version": "3.16.4-beta.0",
3
+ "version": "3.16.5-beta.0",
4
4
  "author": "Rebilly",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "component-emitter": "^1.3.0",
38
38
  "core-js": "3.23.3",
39
39
  "jest": "^27.0.6",
40
- "msw": "0.38.2",
40
+ "msw": "0.45.0",
41
41
  "msw-when-then": "^1.5.1",
42
42
  "rollup": "^2.35.1",
43
43
  "rollup-plugin-ignore": "^1.0.10",
@@ -147,11 +147,10 @@ export async function fetchData({
147
147
 
148
148
  let productsPromise;
149
149
  if (state.options?.invoiceId || state.data?.transaction?.hasInvoice) {
150
- const { invoice, products } = await fetchInvoiceAndProducts(
151
- {
152
- data: {
153
- id: state.options?.invoiceId || state.data?.transaction?.invoiceId
154
- },
150
+ const { invoice, products } = await fetchInvoiceAndProducts({
151
+ data: {
152
+ id: state.options?.invoiceId || state.data?.transaction?.invoiceId
153
+ },
155
154
  state,
156
155
  });
157
156
  productsPromise = Promise.resolve(products);
@@ -10,7 +10,8 @@ export async function fetchInvoiceAndProducts({ data = null, state = null }) {
10
10
  expand: 'items.*.product'
11
11
  });
12
12
 
13
- const products = fields.items.map(items => new ProductModel(items._embedded.product));
13
+ const products = fields.items.filter(item => item._embedded)
14
+ .map(items => new ProductModel(items._embedded.product));
14
15
 
15
16
  return {
16
17
  products,
@@ -53,4 +53,36 @@ describe('Storefront Invoices', () => {
53
53
  }
54
54
  `);
55
55
  });
56
+
57
+ it('can fetch an invoice when it does not have any products', async () => {
58
+ const id = '1234';
59
+ const testInvoice = {
60
+ id: 'test-invoice-id-1',
61
+ items: [
62
+ {
63
+ id: 'test',
64
+ price: 0.99,
65
+ }
66
+ ]
67
+ };
68
+
69
+ when(get(`${storefrontURL}/invoices/${id}`)).thenReturn(ok(testInvoice));
70
+
71
+ const instance = new StorefontTestingInstance({
72
+ data: {
73
+ invoice: {
74
+ id
75
+ }
76
+ }
77
+ });
78
+
79
+ const { invoice, products } = await fetchInvoiceAndProducts({
80
+ data: { id },
81
+ state: instance
82
+ });
83
+
84
+ expect(invoice).toBeInstanceOf(InvoiceModel);
85
+ expect(products).toBeInstanceOf(Array);
86
+ expect(products.length).toBe(0);
87
+ });
56
88
  });