@nuvler/cli 0.5.17 → 0.5.18

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.
@@ -0,0 +1,126 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {
4
+ formatWhatsappRequest,
5
+ whatsappRequestLabel,
6
+ whatsappRequestUrl,
7
+ } from "../dist/src/whatsapp-message.js";
8
+
9
+ const combo = {
10
+ productSlug: "combo",
11
+ title: "Combo",
12
+ sku: "",
13
+ quantity: 1,
14
+ unitPrice: 59.9,
15
+ kitGroups: [
16
+ { id: "s", name: "Salgados", quantity: 50, options: [] },
17
+ { id: "b", name: "Bebidas", quantity: 2, options: [] },
18
+ ],
19
+ composition: [
20
+ { groupId: "s", variantId: "a", name: "Kibe", quantity: 20 },
21
+ { groupId: "s", variantId: "c", name: "Coxinha", quantity: 30 },
22
+ { groupId: "b", variantId: "d", name: "Suco", quantity: 2 },
23
+ ],
24
+ };
25
+ const kit = {
26
+ productSlug: "kit",
27
+ title: "Kit 100",
28
+ sku: "",
29
+ unitPrice: 129,
30
+ kitSize: 100,
31
+ composition: [{ variantId: "a", name: "Kibe", quantity: 100 }],
32
+ };
33
+
34
+ test("WhatsApp requests separate products, groups and individual choices with real line breaks", () => {
35
+ const message = formatWhatsappRequest([combo, kit]).replace(/\u00a0/g, " ");
36
+ assert.ok(
37
+ message.startsWith(
38
+ "Olá! Gostaria de solicitar os itens abaixo. Podem confirmar os valores e a disponibilidade?\n\n",
39
+ ),
40
+ );
41
+ assert.ok(
42
+ message.includes(
43
+ "*Salgados — 50 unidades por combo*\n\n• Kibe: 20\n\n• Coxinha: 30\n\n*Bebidas — 2 unidades por combo*\n\n• Suco: 2",
44
+ ),
45
+ );
46
+ assert.ok(message.includes("\n\n*2. Kit 100*\n"));
47
+ assert.ok(message.endsWith("*Total estimado: R$ 188,90*"));
48
+ assert.doesNotMatch(message, /Composição por kit|orçamento|; /);
49
+ assert.equal(whatsappRequestLabel, "Enviar solicitação pelo WhatsApp");
50
+ assert.equal(decodeURIComponent(encodeURIComponent(message)), message);
51
+ });
52
+
53
+ test("multiple quantities affect subtotals and the total, without multiplying per-combo choices", () => {
54
+ const message = formatWhatsappRequest([{ ...combo, quantity: 2 }]).replace(
55
+ /\u00a0/g,
56
+ " ",
57
+ );
58
+ assert.ok(
59
+ message.includes(
60
+ "Quantidade: 2\n\nValor unitário: R$ 59,90\n\nSubtotal: R$ 119,80",
61
+ ),
62
+ );
63
+ assert.ok(message.includes("• Kibe: 20"));
64
+ assert.ok(message.endsWith("*Total estimado: R$ 119,80*"));
65
+ });
66
+
67
+ test("hidden and incomplete prices never generate a misleading total", () => {
68
+ assert.doesNotMatch(
69
+ formatWhatsappRequest([combo, kit], false),
70
+ /R\$|Valor unitário|Subtotal|Total estimado/,
71
+ );
72
+ assert.doesNotMatch(
73
+ formatWhatsappRequest([combo, { ...kit, unitPrice: null }]),
74
+ /Total estimado/,
75
+ );
76
+ const ordinary = formatWhatsappRequest([
77
+ {
78
+ productSlug: "p",
79
+ title: "Produto",
80
+ sku: "ABC",
81
+ variantName: "Cor: Azul",
82
+ productUrl: "https://example.com/p",
83
+ },
84
+ ]);
85
+ assert.ok(ordinary.includes("Cor: Azul\n\nReferência: ABC"));
86
+ assert.ok(ordinary.endsWith("https://example.com/p"));
87
+ });
88
+
89
+ test("WhatsApp URLs preserve paragraph breaks, formatting, accents and special characters", () => {
90
+ const message = formatWhatsappRequest(
91
+ [
92
+ {
93
+ ...combo,
94
+ title: "Combo & opções + queijo",
95
+ productUrl: "/combos/combo",
96
+ },
97
+ ],
98
+ true,
99
+ "https://loja.example",
100
+ );
101
+ const href = whatsappRequestUrl("+55 (11) 99999-9999", message);
102
+ const url = new URL(href);
103
+ assert.equal(url.pathname, "/5511999999999");
104
+ assert.equal(url.searchParams.get("text"), message);
105
+ assert.ok(href.includes("%0A%0A"));
106
+ assert.ok(message.includes("https://loja.example/combos/combo"));
107
+ assert.doesNotMatch(message, /[^\n]\n[^\n]/);
108
+ });
109
+
110
+ test("relative product links use the current store origin and invalid links are omitted", () => {
111
+ assert.ok(
112
+ formatWhatsappRequest(
113
+ [{ ...kit, productUrl: "/salgados/kit" }],
114
+ true,
115
+ "https://outraloja.example",
116
+ ).includes("https://outraloja.example/salgados/kit"),
117
+ );
118
+ assert.doesNotMatch(
119
+ formatWhatsappRequest([{ ...kit, productUrl: "/salgados/kit" }]),
120
+ /\/salgados\/kit/,
121
+ );
122
+ assert.doesNotMatch(
123
+ formatWhatsappRequest([{ ...kit, productUrl: "javascript:alert(1)" }]),
124
+ /javascript:/,
125
+ );
126
+ });
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc -p tsconfig.json --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@nuvler/theme-sdk": "^1.4.7"
16
+ "@nuvler/theme-sdk": "^1.4.8"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuvler/cli": "^0.5.17",
22
+ "@nuvler/cli": "^0.5.18",
23
23
  "@types/react": "^19.0.0",
24
24
  "react": "^19.0.0",
25
25
  "typescript": "^5.9.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/cli",
3
- "version": "0.5.17",
3
+ "version": "0.5.18",
4
4
  "description": "CLI oficial para criação, validação, preview e empacotamento de temas Nuvler",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,8 +20,8 @@
20
20
  "typecheck": "tsc -p tsconfig.json --noEmit"
21
21
  },
22
22
  "dependencies": {
23
- "@nuvler/theme-schema": "^1.4.5",
24
- "@nuvler/theme-sdk": "^1.4.7",
23
+ "@nuvler/theme-schema": "^1.4.6",
24
+ "@nuvler/theme-sdk": "^1.4.8",
25
25
  "@vitejs/plugin-react": "^6.0.5",
26
26
  "commander": "^15.0.0",
27
27
  "react": "19.2.8",
@@ -10,7 +10,7 @@
10
10
  "typecheck": "tsc -p tsconfig.json --noEmit"
11
11
  },
12
12
  "dependencies": {
13
- "@nuvler/theme-sdk": "^1.4.3",
13
+ "@nuvler/theme-sdk": "^1.4.8",
14
14
  "react": "19.2.8",
15
15
  "react-dom": "19.2.8"
16
16
  },