@kizlo/woocommerce 0.4.0 → 0.6.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/dist/test.d.ts CHANGED
@@ -1,8 +1,18 @@
1
- import * as kizlo18 from "kizlo";
1
+ import * as kizlo0 from "kizlo";
2
2
  import { DevPluginSource } from "kizlo/test";
3
3
 
4
4
  //#region src/test/index.d.ts
5
5
 
6
+ /**
7
+ * WooCommerce ships every gateway disabled, and paying an order needs an available one, so the
8
+ * checkout tests have nothing to reach without this. Bank transfer is the gateway with no shipping
9
+ * method or country conditions attached to it, so enabling it says the least about the rest.
10
+ *
11
+ * The title and description are set to distinctive values so the cart's payment-method metadata
12
+ * test can prove the store's configured strings flow through rather than a hardcoded default.
13
+ */
14
+ declare const BANK_TRANSFER_TITLE = "Bank transfer (Kizlo test)";
15
+ declare const BANK_TRANSFER_DESCRIPTION = "Pay by transferring to our test bank account.";
6
16
  /**
7
17
  * WooCommerce test fixture: installs WooCommerce + the kizlo-woocommerce plugin, seeds
8
18
  * products/coupons. Pass `plugins` to override the defaults — e.g. bind-mount your local
@@ -10,6 +20,6 @@ import { DevPluginSource } from "kizlo/test";
10
20
  */
11
21
  declare function woocommerce(opts?: {
12
22
  plugins?: DevPluginSource[];
13
- }): kizlo18.Fixture;
23
+ }): kizlo0.Fixture;
14
24
  //#endregion
15
- export { woocommerce };
25
+ export { BANK_TRANSFER_DESCRIPTION, BANK_TRANSFER_TITLE, woocommerce };
package/dist/test.js CHANGED
@@ -62,6 +62,45 @@ async function upsertProduct(service, product) {
62
62
  if (created.error) throw created.error;
63
63
  return created.data.id;
64
64
  }
65
+ async function upsertVariableProduct(service) {
66
+ const slug = "test-product-variable";
67
+ let productId = (await service.get(`${WC_CORE_BASE}/products`, { searchParams: { slug } })).data?.[0]?.id;
68
+ if (!productId) {
69
+ const created = await service.post(`${WC_CORE_BASE}/products`, { body: {
70
+ name: "Test Product Variable",
71
+ slug,
72
+ type: "variable",
73
+ status: "publish",
74
+ attributes: [{
75
+ name: "Size",
76
+ visible: true,
77
+ variation: true,
78
+ options: ["Small", "Large"]
79
+ }]
80
+ } });
81
+ if (created.error) throw created.error;
82
+ productId = created.data.id;
83
+ }
84
+ const existingVariation = (await service.get(`${WC_CORE_BASE}/products/${productId}/variations`, { searchParams: { per_page: 100 } })).data?.find((variation) => variation.sku === "TEST-VARIATION-LARGE");
85
+ if (existingVariation) return {
86
+ productId,
87
+ variationId: existingVariation.id
88
+ };
89
+ const createdVariation = await service.post(`${WC_CORE_BASE}/products/${productId}/variations`, { body: {
90
+ regular_price: "15",
91
+ sku: "TEST-VARIATION-LARGE",
92
+ status: "publish",
93
+ attributes: [{
94
+ name: "Size",
95
+ option: "Large"
96
+ }]
97
+ } });
98
+ if (createdVariation.error) throw createdVariation.error;
99
+ return {
100
+ productId,
101
+ variationId: createdVariation.data.id
102
+ };
103
+ }
65
104
  async function upsertCoupon(service, coupon) {
66
105
  if ((await service.get(`${WC_CORE_BASE}/coupons`, { searchParams: { code: coupon.code } })).data?.[0]) return;
67
106
  const created = await service.post(`${WC_CORE_BASE}/coupons`, { body: coupon });
@@ -95,11 +134,43 @@ async function linkRecommendations(service, productIds) {
95
134
  * WooCommerce ships every gateway disabled, and paying an order needs an available one, so the
96
135
  * checkout tests have nothing to reach without this. Bank transfer is the gateway with no shipping
97
136
  * method or country conditions attached to it, so enabling it says the least about the rest.
137
+ *
138
+ * The title and description are set to distinctive values so the cart's payment-method metadata
139
+ * test can prove the store's configured strings flow through rather than a hardcoded default.
98
140
  */
141
+ const BANK_TRANSFER_TITLE = "Bank transfer (Kizlo test)";
142
+ const BANK_TRANSFER_DESCRIPTION = "Pay by transferring to our test bank account.";
99
143
  async function enableBankTransfer(service) {
100
- const updated = await service.put(`${WC_CORE_BASE}/payment_gateways/bacs`, { body: { enabled: true } });
144
+ const updated = await service.put(`${WC_CORE_BASE}/payment_gateways/bacs`, { body: {
145
+ enabled: true,
146
+ title: BANK_TRANSFER_TITLE,
147
+ description: BANK_TRANSFER_DESCRIPTION
148
+ } });
101
149
  if (updated.error) throw updated.error;
102
150
  }
151
+ async function enableFlatRate(service) {
152
+ let zoneId = (await service.get(`${WC_CORE_BASE}/shipping/zones`, {})).data?.find((zone) => zone.name === "Kizlo Test Zone")?.id;
153
+ if (!zoneId) {
154
+ const created = await service.post(`${WC_CORE_BASE}/shipping/zones`, { body: {
155
+ name: "Kizlo Test Zone",
156
+ order: 0
157
+ } });
158
+ if (created.error) throw created.error;
159
+ zoneId = created.data.id;
160
+ }
161
+ const locations = await service.put(`${WC_CORE_BASE}/shipping/zones/${zoneId}/locations`, { body: [{
162
+ code: "US",
163
+ type: "country"
164
+ }] });
165
+ if (locations.error) throw locations.error;
166
+ if ((await service.get(`${WC_CORE_BASE}/shipping/zones/${zoneId}/methods`, {})).data?.some((method) => method.method_id === "flat_rate")) return;
167
+ const createdMethod = await service.post(`${WC_CORE_BASE}/shipping/zones/${zoneId}/methods`, { body: {
168
+ method_id: "flat_rate",
169
+ enabled: true,
170
+ settings: { cost: "5" }
171
+ } });
172
+ if (createdMethod.error) throw createdMethod.error;
173
+ }
103
174
  /**
104
175
  * WooCommerce bundles Action Scheduler, which keeps its actions in the posts table until it
105
176
  * migrates to its own tables, and registers two global post statuses (`in-progress`, `failed`)
@@ -140,8 +211,10 @@ function woocommerce(opts = {}) {
140
211
  }
141
212
  if (productIds[0]) await linkProductCategory(service, productIds[0]);
142
213
  await linkRecommendations(service, productIds);
214
+ await upsertVariableProduct(service);
143
215
  for (const coupon of COUPONS) await upsertCoupon(service, coupon);
144
216
  await enableBankTransfer(service);
217
+ await enableFlatRate(service);
145
218
  return { productId };
146
219
  },
147
220
  async cleanup({ service, userId }) {
@@ -159,8 +232,10 @@ async function deleteAllOrdersFor(service, customerId) {
159
232
  await Promise.all(orders.data.map((o) => service.delete(`${WC_CORE_BASE}/orders/${o.id}`, { searchParams: { force: true } })));
160
233
  }
161
234
  async function resetCart(service, customerId) {
162
- await service.delete(`${WC_STORE_BASE}/cart/items`, { headers: { "X-Kizlo-User-Id": String(customerId) } });
235
+ const email = (await service.get(`${WC_CORE_BASE}/customers/${customerId}`, {})).data?.email;
236
+ if (!email) return;
237
+ await service.delete(`${WC_STORE_BASE}/cart/items`, { headers: { "X-Kizlo-User-Email": email } });
163
238
  }
164
239
 
165
240
  //#endregion
166
- export { woocommerce };
241
+ export { BANK_TRANSFER_DESCRIPTION, BANK_TRANSFER_TITLE, woocommerce };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizlo/woocommerce",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "WooCommerce integration for Kizlo.",