backend-manager 5.9.5 → 5.9.6

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 (244) hide show
  1. package/package.json +8 -1
  2. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/metadata.json +14 -0
  3. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.html +486 -0
  4. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.md +41 -0
  5. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/newsletter.mjml +97 -0
  6. package/{test/email/fixtures/clean.json → src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/structure.json} +16 -4
  7. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-11T03-28-07/summary.md +1 -0
  8. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/metadata.json +14 -0
  9. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.html +486 -0
  10. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.md +41 -0
  11. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/newsletter.mjml +97 -0
  12. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/structure.json +42 -0
  13. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-00-28/summary.md +1 -0
  14. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/metadata.json +14 -0
  15. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.html +486 -0
  16. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.md +41 -0
  17. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/newsletter.mjml +97 -0
  18. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/structure.json +42 -0
  19. package/src/test/fixtures/firebase-project/.temp/newsletter/run-2026-06-18T01-01-34/summary.md +1 -0
  20. package/src/test/fixtures/firebase-project/.temp/test-mode.json +6 -0
  21. package/src/test/fixtures/firebase-project/database-debug.log +12 -0
  22. package/src/test/fixtures/firebase-project/firestore-debug.log +136 -0
  23. package/src/test/fixtures/firebase-project/pubsub-debug.log +17 -0
  24. package/.codeclimate.yml +0 -32
  25. package/.nvmrc +0 -1
  26. package/CHANGELOG.md +0 -1440
  27. package/PROGRESS.md +0 -93
  28. package/TODO-2.md +0 -121
  29. package/TODO-CHARGEBLAST.md +0 -32
  30. package/TODO-WEBHOOK-KEY-LEGACY-REMOVAL.md +0 -15
  31. package/TODO-WEBHOOK-KEY-UPGRADE.md +0 -138
  32. package/TODO-email-auth.md +0 -14
  33. package/TODO.md +0 -187
  34. package/plans/mcp2.md +0 -247
  35. package/plans/suspended-subscription-dead-zone.md +0 -97
  36. package/scripts/test-helper-providers.js +0 -162
  37. package/scripts/update-disposable-domains.js +0 -44
  38. package/templates/_.env +0 -42
  39. package/templates/_.gitignore +0 -60
  40. package/templates/backend-manager-config.json +0 -249
  41. package/templates/database.rules.json +0 -83
  42. package/templates/firebase.json +0 -66
  43. package/templates/firestore.indexes.json +0 -4
  44. package/templates/firestore.rules +0 -112
  45. package/templates/public/404.html +0 -26
  46. package/templates/public/index.html +0 -24
  47. package/templates/remoteconfig.template.json +0 -1
  48. package/templates/storage-lifecycle-config-1-day.json +0 -9
  49. package/templates/storage-lifecycle-config-30-days.json +0 -9
  50. package/templates/storage.rules +0 -8
  51. package/test/_init/accounts-validation.js +0 -58
  52. package/test/_legacy/ai/index.js +0 -231
  53. package/test/_legacy/ai/test.jpg +0 -0
  54. package/test/_legacy/ai/test.pdf +0 -0
  55. package/test/_legacy/index.js +0 -31
  56. package/test/_legacy/payment-resolver/chargebee/orders/refunded.json +0 -0
  57. package/test/_legacy/payment-resolver/chargebee/orders/unpaid.json +0 -98
  58. package/test/_legacy/payment-resolver/chargebee/subscriptions/active.json +0 -578
  59. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-in-trial.json +0 -38
  60. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-skipped-to-active.json +0 -135
  61. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active-to-cancelled.json +0 -42
  62. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-active.json +0 -44
  63. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-cancelled.json +0 -39
  64. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-refund.json +0 -143
  65. package/test/_legacy/payment-resolver/chargebee/subscriptions/trial-to-suspended.json +0 -48
  66. package/test/_legacy/payment-resolver/coinbase/orders/regular.json +0 -204
  67. package/test/_legacy/payment-resolver/coinbase/subscriptions/cancelled.json +0 -204
  68. package/test/_legacy/payment-resolver/coinbase/subscriptions/paid-2.json +0 -125
  69. package/test/_legacy/payment-resolver/index.js +0 -1558
  70. package/test/_legacy/payment-resolver/paypal/orders/refunded.json +0 -0
  71. package/test/_legacy/payment-resolver/paypal/orders/regular.json +0 -120
  72. package/test/_legacy/payment-resolver/paypal/subscriptions/active-refund-previous-stmnt.json +0 -323
  73. package/test/_legacy/payment-resolver/paypal/subscriptions/active.json +0 -192
  74. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-in-trial.json +0 -125
  75. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-not-complete.json +0 -76
  76. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue-2.json +0 -114
  77. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-payment-overdue.json +0 -114
  78. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active-to-cancelled.json +0 -111
  79. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-active.json +0 -132
  80. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-cancelled.json +0 -107
  81. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-expired.json +0 -91
  82. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-refund.json +0 -147
  83. package/test/_legacy/payment-resolver/paypal/subscriptions/trial-to-suspended.json +0 -120
  84. package/test/_legacy/payment-resolver/stripe/orders/refunded.json +0 -0
  85. package/test/_legacy/payment-resolver/stripe/orders/regular.json +0 -91
  86. package/test/_legacy/payment-resolver/stripe/subscriptions/active.json +0 -421
  87. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-in-trial.json +0 -349
  88. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active-failed-authorization.json +0 -430
  89. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-active.json +0 -319
  90. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-cancelled.json +0 -319
  91. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-refund.json +0 -414
  92. package/test/_legacy/payment-resolver/stripe/subscriptions/trial-to-suspended.json +0 -319
  93. package/test/_legacy/payment-resolver/stripe/subscriptions/unsure.json +0 -339
  94. package/test/_legacy/test-new +0 -1178
  95. package/test/_legacy/test.md +0 -89
  96. package/test/_legacy/usage.js +0 -175
  97. package/test/_legacy/user.js +0 -31
  98. package/test/ai/tools-live.js +0 -170
  99. package/test/boot/emulator-boots.js +0 -37
  100. package/test/content/blog-generate.js +0 -160
  101. package/test/email/campaign-send.js +0 -45
  102. package/test/email/consent-lifecycle.js +0 -257
  103. package/test/email/feedback-and-plain-send.js +0 -52
  104. package/test/email/fixtures/editorial.json +0 -30
  105. package/test/email/fixtures/field-report.json +0 -53
  106. package/test/email/marketing-lifecycle.js +0 -132
  107. package/test/email/newsletter-generate.js +0 -819
  108. package/test/email/newsletter-templates.js +0 -491
  109. package/test/email/templates.js +0 -207
  110. package/test/email/transactional-send.js +0 -34
  111. package/test/email/transactional.js +0 -560
  112. package/test/email/validation.js +0 -710
  113. package/test/events/auth-delete-race.js +0 -201
  114. package/test/events/payments/journey-payments-cancel-endpoint.js +0 -100
  115. package/test/events/payments/journey-payments-cancel.js +0 -182
  116. package/test/events/payments/journey-payments-discount.js +0 -89
  117. package/test/events/payments/journey-payments-failure.js +0 -146
  118. package/test/events/payments/journey-payments-legacy-product.js +0 -149
  119. package/test/events/payments/journey-payments-one-time-failure.js +0 -111
  120. package/test/events/payments/journey-payments-one-time.js +0 -136
  121. package/test/events/payments/journey-payments-plan-change.js +0 -144
  122. package/test/events/payments/journey-payments-refund-webhook.js +0 -180
  123. package/test/events/payments/journey-payments-suspend.js +0 -181
  124. package/test/events/payments/journey-payments-trial-cancel.js +0 -130
  125. package/test/events/payments/journey-payments-trial.js +0 -171
  126. package/test/events/payments/journey-payments-uid-resolution.js +0 -132
  127. package/test/events/payments/journey-payments-upgrade.js +0 -135
  128. package/test/fixtures/chargebee/invoice-one-time.json +0 -27
  129. package/test/fixtures/chargebee/subscription-active.json +0 -44
  130. package/test/fixtures/chargebee/subscription-cancelled.json +0 -42
  131. package/test/fixtures/chargebee/subscription-in-trial.json +0 -41
  132. package/test/fixtures/chargebee/subscription-legacy-plan.json +0 -41
  133. package/test/fixtures/chargebee/subscription-non-renewing.json +0 -41
  134. package/test/fixtures/chargebee/subscription-paused.json +0 -42
  135. package/test/fixtures/chargebee/webhook-payment-failed.json +0 -51
  136. package/test/fixtures/chargebee/webhook-subscription-created.json +0 -47
  137. package/test/fixtures/paypal/order-approved.json +0 -62
  138. package/test/fixtures/paypal/order-completed.json +0 -110
  139. package/test/fixtures/paypal/subscription-active.json +0 -76
  140. package/test/fixtures/paypal/subscription-cancelled.json +0 -50
  141. package/test/fixtures/paypal/subscription-suspended.json +0 -65
  142. package/test/fixtures/stripe/checkout-session-completed.json +0 -130
  143. package/test/fixtures/stripe/invoice-payment-failed.json +0 -148
  144. package/test/fixtures/stripe/invoice-subscription-payment-failed.json +0 -28
  145. package/test/fixtures/stripe/subscription-active.json +0 -161
  146. package/test/fixtures/stripe/subscription-canceled.json +0 -161
  147. package/test/fixtures/stripe/subscription-trialing.json +0 -161
  148. package/test/functions/admin/database-read.js +0 -134
  149. package/test/functions/admin/database-write.js +0 -159
  150. package/test/functions/admin/edit-post.js +0 -366
  151. package/test/functions/admin/firestore-query.js +0 -207
  152. package/test/functions/admin/firestore-read.js +0 -129
  153. package/test/functions/admin/firestore-write.js +0 -105
  154. package/test/functions/admin/get-stats.js +0 -115
  155. package/test/functions/admin/send-email.js +0 -119
  156. package/test/functions/admin/send-notification.js +0 -208
  157. package/test/functions/admin/write-repo-content.js +0 -223
  158. package/test/functions/general/add-marketing-contact.js +0 -335
  159. package/test/functions/general/fetch-post.js +0 -54
  160. package/test/functions/general/generate-uuid.js +0 -114
  161. package/test/functions/test/authenticate.js +0 -64
  162. package/test/functions/user/create-custom-token.js +0 -73
  163. package/test/functions/user/delete.js +0 -135
  164. package/test/functions/user/get-active-sessions.js +0 -111
  165. package/test/functions/user/get-subscription-info.js +0 -99
  166. package/test/functions/user/regenerate-api-keys.js +0 -156
  167. package/test/functions/user/resolve.js +0 -52
  168. package/test/functions/user/sign-out-all-sessions.js +0 -94
  169. package/test/functions/user/sign-up.js +0 -252
  170. package/test/functions/user/submit-feedback.js +0 -104
  171. package/test/functions/user/validate-settings.js +0 -82
  172. package/test/helpers/ai-request-payload.js +0 -300
  173. package/test/helpers/ai-test-provider.js +0 -202
  174. package/test/helpers/ai-tools-format.js +0 -383
  175. package/test/helpers/content/blog-auto-publisher.js +0 -484
  176. package/test/helpers/content/feed-parser.js +0 -528
  177. package/test/helpers/content/ghostii-blocks.js +0 -134
  178. package/test/helpers/content/ghostii-feed-integration.js +0 -404
  179. package/test/helpers/content/ghostii-write-article.js +0 -243
  180. package/test/helpers/environment.js +0 -230
  181. package/test/helpers/infer-contact.js +0 -113
  182. package/test/helpers/merge-line-files.js +0 -271
  183. package/test/helpers/payment/chargebee/parse-webhook.js +0 -413
  184. package/test/helpers/payment/chargebee/to-unified-one-time.js +0 -147
  185. package/test/helpers/payment/chargebee/to-unified-subscription.js +0 -648
  186. package/test/helpers/payment/paypal/parse-webhook.js +0 -539
  187. package/test/helpers/payment/paypal/to-unified-one-time.js +0 -382
  188. package/test/helpers/payment/paypal/to-unified-subscription.js +0 -820
  189. package/test/helpers/payment/stripe/parse-webhook.js +0 -447
  190. package/test/helpers/payment/stripe/to-unified-one-time.js +0 -306
  191. package/test/helpers/payment/stripe/to-unified-subscription.js +0 -708
  192. package/test/helpers/sanitize.js +0 -222
  193. package/test/helpers/slugify.js +0 -394
  194. package/test/helpers/storage.js +0 -194
  195. package/test/helpers/user.js +0 -755
  196. package/test/helpers/webhook-forward.js +0 -418
  197. package/test/mcp/discovery.js +0 -53
  198. package/test/mcp/oauth.js +0 -161
  199. package/test/mcp/protocol.js +0 -268
  200. package/test/mcp/roles.js +0 -188
  201. package/test/mcp/utils.js +0 -245
  202. package/test/routes/admin/create-post.js +0 -364
  203. package/test/routes/admin/database.js +0 -131
  204. package/test/routes/admin/deduplicate-image-alts.js +0 -190
  205. package/test/routes/admin/email.js +0 -114
  206. package/test/routes/admin/firestore-query.js +0 -204
  207. package/test/routes/admin/firestore.js +0 -127
  208. package/test/routes/admin/infer-contact.js +0 -218
  209. package/test/routes/admin/notification.js +0 -198
  210. package/test/routes/admin/post-resize-image.js +0 -184
  211. package/test/routes/admin/post.js +0 -368
  212. package/test/routes/admin/repo-content.js +0 -223
  213. package/test/routes/admin/stats.js +0 -112
  214. package/test/routes/content/post.js +0 -54
  215. package/test/routes/general/uuid.js +0 -115
  216. package/test/routes/marketing/campaign.js +0 -125
  217. package/test/routes/marketing/contact.js +0 -370
  218. package/test/routes/marketing/email-preferences.js +0 -292
  219. package/test/routes/marketing/push-send.js +0 -32
  220. package/test/routes/marketing/webhook-forward.js +0 -61
  221. package/test/routes/marketing/webhook.js +0 -639
  222. package/test/routes/payments/cancel.js +0 -163
  223. package/test/routes/payments/discount.js +0 -80
  224. package/test/routes/payments/dispute-alert.js +0 -320
  225. package/test/routes/payments/intent.js +0 -336
  226. package/test/routes/payments/portal.js +0 -92
  227. package/test/routes/payments/refund.js +0 -179
  228. package/test/routes/payments/trial-eligibility.js +0 -71
  229. package/test/routes/payments/webhook.js +0 -107
  230. package/test/routes/test/authenticate.js +0 -59
  231. package/test/routes/test/schema.js +0 -554
  232. package/test/routes/test/usage.js +0 -342
  233. package/test/routes/user/api-keys.js +0 -156
  234. package/test/routes/user/delete.js +0 -136
  235. package/test/routes/user/feedback.js +0 -104
  236. package/test/routes/user/sessions.js +0 -199
  237. package/test/routes/user/settings-validate.js +0 -82
  238. package/test/routes/user/signup.js +0 -542
  239. package/test/routes/user/subscription.js +0 -99
  240. package/test/routes/user/token.js +0 -73
  241. package/test/routes/user/user.js +0 -157
  242. package/test/rules/notifications.js +0 -410
  243. package/test/rules/payments-carts.js +0 -371
  244. package/test/rules/user.js +0 -396
@@ -1,528 +0,0 @@
1
- /**
2
- * Test: content/feed-parser
3
- * Unit tests for the RSS 2.0, Atom 1.0, and JSON Feed parser + article content extractor.
4
- *
5
- * Run: npx mgr test helpers/content/feed-parser
6
- *
7
- * Pure function tests (parseFeed, stripHtml, extractElement) — required
8
- * directly and called with plain inputs. NOT a mock.
9
- */
10
- const { parseFeed, stripHtml, extractTextFromHtml } = require('../../../src/manager/libraries/content/feed-parser.js');
11
-
12
- // --- Sample feeds for testing ---
13
-
14
- const RSS_FULL = `<?xml version="1.0" encoding="UTF-8"?>
15
- <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
16
- <channel>
17
- <title>Tech News</title>
18
- <link>https://example.com</link>
19
- <description>Latest tech news</description>
20
- <item>
21
- <guid>https://example.com/article-1</guid>
22
- <title>First Article Title</title>
23
- <link>https://example.com/article-1</link>
24
- <description>Short description of the first article.</description>
25
- <content:encoded><![CDATA[<p>Full content of the first article with <strong>HTML</strong> formatting.</p>]]></content:encoded>
26
- <pubDate>Mon, 16 Jun 2025 10:00:00 GMT</pubDate>
27
- <dc:creator>Jane Doe</dc:creator>
28
- </item>
29
- <item>
30
- <guid isPermaLink="false">article-2-id</guid>
31
- <title>Second Article Title</title>
32
- <link>https://example.com/article-2</link>
33
- <description>Short description of the second article.</description>
34
- <pubDate>Tue, 17 Jun 2025 12:00:00 GMT</pubDate>
35
- </item>
36
- </channel>
37
- </rss>`;
38
-
39
- const RSS_MINIMAL = `<?xml version="1.0"?>
40
- <rss version="2.0">
41
- <channel>
42
- <title>Minimal</title>
43
- <item>
44
- <title>Only Title</title>
45
- <link>https://example.com/only</link>
46
- </item>
47
- </channel>
48
- </rss>`;
49
-
50
- const RSS_EMPTY_CHANNEL = `<?xml version="1.0"?>
51
- <rss version="2.0">
52
- <channel>
53
- <title>Empty</title>
54
- </channel>
55
- </rss>`;
56
-
57
- const ATOM_FULL = `<?xml version="1.0" encoding="utf-8"?>
58
- <feed xmlns="http://www.w3.org/2005/Atom">
59
- <title>Atom Feed</title>
60
- <entry>
61
- <id>urn:uuid:entry-1</id>
62
- <title>Atom Entry One</title>
63
- <link rel="alternate" href="https://example.com/atom-1"/>
64
- <link rel="enclosure" href="https://example.com/atom-1.mp3"/>
65
- <summary>Summary of entry one.</summary>
66
- <content>Full content of entry one.</content>
67
- <published>2025-06-16T10:00:00Z</published>
68
- </entry>
69
- <entry>
70
- <id>urn:uuid:entry-2</id>
71
- <title type="html">Atom Entry &amp; Two</title>
72
- <link href="https://example.com/atom-2"/>
73
- <updated>2025-06-17T12:00:00Z</updated>
74
- </entry>
75
- </feed>`;
76
-
77
- const ATOM_EMPTY = `<?xml version="1.0"?>
78
- <feed xmlns="http://www.w3.org/2005/Atom">
79
- <title>Empty Atom</title>
80
- </feed>`;
81
-
82
- const JSON_FEED = JSON.stringify({
83
- version: 'https://jsonfeed.org/version/1.1',
84
- title: 'JSON Feed',
85
- items: [
86
- {
87
- id: 'json-1',
88
- title: 'JSON Article One',
89
- url: 'https://example.com/json-1',
90
- summary: 'Short summary.',
91
- content_html: '<p>Full HTML content.</p>',
92
- content_text: 'Full text content.',
93
- date_published: '2025-06-16T10:00:00Z',
94
- },
95
- {
96
- id: 'json-2',
97
- title: 'JSON Article Two',
98
- url: 'https://example.com/json-2',
99
- content_text: 'Second article text.',
100
- date_modified: '2025-06-17T12:00:00Z',
101
- },
102
- ],
103
- });
104
-
105
- const RSSAPP_FORMAT = JSON.stringify({
106
- items: [
107
- {
108
- title: 'RSS.app Item',
109
- url: 'https://example.com/rssapp-1',
110
- content_text: 'Content from RSS.app feed.',
111
- },
112
- ],
113
- });
114
-
115
- module.exports = {
116
- description: 'content/feed-parser',
117
- type: 'group',
118
-
119
- tests: [
120
- // ============================
121
- // RSS 2.0 PARSING
122
- // ============================
123
- {
124
- name: 'rss-parses-standard-items',
125
- async run({ assert }) {
126
- const { items } = parseFeed(RSS_FULL);
127
- assert.equal(items.length, 2, 'should parse 2 items');
128
- assert.equal(items[0].title, 'First Article Title');
129
- assert.equal(items[1].title, 'Second Article Title');
130
- },
131
- },
132
-
133
- {
134
- name: 'rss-extracts-guid-as-id',
135
- async run({ assert }) {
136
- const { items } = parseFeed(RSS_FULL);
137
- assert.equal(items[0].id, 'https://example.com/article-1', 'text guid');
138
- assert.equal(items[1].id, 'article-2-id', 'guid with isPermaLink attr');
139
- },
140
- },
141
-
142
- {
143
- name: 'rss-extracts-link-as-url',
144
- async run({ assert }) {
145
- const { items } = parseFeed(RSS_FULL);
146
- assert.equal(items[0].url, 'https://example.com/article-1');
147
- assert.equal(items[1].url, 'https://example.com/article-2');
148
- },
149
- },
150
-
151
- {
152
- name: 'rss-extracts-description-as-summary',
153
- async run({ assert }) {
154
- const { items } = parseFeed(RSS_FULL);
155
- assert.equal(items[0].summary, 'Short description of the first article.');
156
- },
157
- },
158
-
159
- {
160
- name: 'rss-extracts-content-encoded-as-content',
161
- async run({ assert }) {
162
- const { items } = parseFeed(RSS_FULL);
163
- assert.ok(items[0].content.includes('Full content of the first article'), 'has content:encoded text');
164
- assert.ok(!items[0].content.includes('<p>'), 'HTML stripped from content');
165
- },
166
- },
167
-
168
- {
169
- name: 'rss-falls-back-to-description-when-no-content-encoded',
170
- async run({ assert }) {
171
- const { items } = parseFeed(RSS_FULL);
172
- assert.equal(items[1].content, 'Short description of the second article.');
173
- },
174
- },
175
-
176
- {
177
- name: 'rss-extracts-pubdate',
178
- async run({ assert }) {
179
- const { items } = parseFeed(RSS_FULL);
180
- assert.equal(items[0].publishedAt, 'Mon, 16 Jun 2025 10:00:00 GMT');
181
- },
182
- },
183
-
184
- {
185
- name: 'rss-handles-missing-optional-fields',
186
- async run({ assert }) {
187
- const { items } = parseFeed(RSS_MINIMAL);
188
- assert.equal(items.length, 1);
189
- assert.equal(items[0].title, 'Only Title');
190
- assert.equal(items[0].url, 'https://example.com/only');
191
- assert.equal(items[0].summary, '', 'no description');
192
- assert.equal(items[0].publishedAt, '', 'no pubDate');
193
- },
194
- },
195
-
196
- {
197
- name: 'rss-preserves-item-order',
198
- async run({ assert }) {
199
- const { items } = parseFeed(RSS_FULL);
200
- assert.equal(items[0].title, 'First Article Title', 'first item is first');
201
- assert.equal(items[1].title, 'Second Article Title', 'second item is second');
202
- },
203
- },
204
-
205
- {
206
- name: 'rss-empty-channel-returns-empty-items',
207
- async run({ assert }) {
208
- const { items } = parseFeed(RSS_EMPTY_CHANNEL);
209
- assert.equal(items.length, 0);
210
- },
211
- },
212
-
213
- // ============================
214
- // ATOM 1.0 PARSING
215
- // ============================
216
- {
217
- name: 'atom-parses-standard-entries',
218
- async run({ assert }) {
219
- const { items } = parseFeed(ATOM_FULL);
220
- assert.equal(items.length, 2, 'should parse 2 entries');
221
- assert.equal(items[0].title, 'Atom Entry One');
222
- },
223
- },
224
-
225
- {
226
- name: 'atom-extracts-id',
227
- async run({ assert }) {
228
- const { items } = parseFeed(ATOM_FULL);
229
- assert.equal(items[0].id, 'urn:uuid:entry-1');
230
- assert.equal(items[1].id, 'urn:uuid:entry-2');
231
- },
232
- },
233
-
234
- {
235
- name: 'atom-picks-alternate-link-href',
236
- async run({ assert }) {
237
- const { items } = parseFeed(ATOM_FULL);
238
- assert.equal(items[0].url, 'https://example.com/atom-1', 'picks rel=alternate over enclosure');
239
- },
240
- },
241
-
242
- {
243
- name: 'atom-falls-back-to-first-link-when-no-rel',
244
- async run({ assert }) {
245
- const { items } = parseFeed(ATOM_FULL);
246
- assert.equal(items[1].url, 'https://example.com/atom-2', 'link without rel');
247
- },
248
- },
249
-
250
- {
251
- name: 'atom-extracts-summary-and-content',
252
- async run({ assert }) {
253
- const { items } = parseFeed(ATOM_FULL);
254
- assert.equal(items[0].summary, 'Summary of entry one.');
255
- assert.equal(items[0].content, 'Full content of entry one.');
256
- },
257
- },
258
-
259
- {
260
- name: 'atom-extracts-published-or-updated',
261
- async run({ assert }) {
262
- const { items } = parseFeed(ATOM_FULL);
263
- assert.equal(items[0].publishedAt, '2025-06-16T10:00:00Z', 'published');
264
- assert.equal(items[1].publishedAt, '2025-06-17T12:00:00Z', 'updated fallback');
265
- },
266
- },
267
-
268
- {
269
- name: 'atom-empty-feed-returns-empty-items',
270
- async run({ assert }) {
271
- const { items } = parseFeed(ATOM_EMPTY);
272
- assert.equal(items.length, 0);
273
- },
274
- },
275
-
276
- // ============================
277
- // JSON FEED PARSING
278
- // ============================
279
- {
280
- name: 'json-parses-standard-items',
281
- async run({ assert }) {
282
- const { items } = parseFeed(JSON_FEED);
283
- assert.equal(items.length, 2);
284
- assert.equal(items[0].title, 'JSON Article One');
285
- assert.equal(items[1].title, 'JSON Article Two');
286
- },
287
- },
288
-
289
- {
290
- name: 'json-extracts-id-and-url',
291
- async run({ assert }) {
292
- const { items } = parseFeed(JSON_FEED);
293
- assert.equal(items[0].id, 'json-1');
294
- assert.equal(items[0].url, 'https://example.com/json-1');
295
- },
296
- },
297
-
298
- {
299
- name: 'json-prefers-content-html-over-content-text',
300
- async run({ assert }) {
301
- const { items } = parseFeed(JSON_FEED);
302
- assert.equal(items[0].content, '<p>Full HTML content.</p>');
303
- },
304
- },
305
-
306
- {
307
- name: 'json-falls-back-to-content-text',
308
- async run({ assert }) {
309
- const { items } = parseFeed(JSON_FEED);
310
- assert.equal(items[1].content, 'Second article text.');
311
- },
312
- },
313
-
314
- {
315
- name: 'json-extracts-dates',
316
- async run({ assert }) {
317
- const { items } = parseFeed(JSON_FEED);
318
- assert.equal(items[0].publishedAt, '2025-06-16T10:00:00Z', 'date_published');
319
- assert.equal(items[1].publishedAt, '2025-06-17T12:00:00Z', 'date_modified fallback');
320
- },
321
- },
322
-
323
- {
324
- name: 'json-handles-rssapp-format',
325
- async run({ assert }) {
326
- const { items } = parseFeed(RSSAPP_FORMAT);
327
- assert.equal(items.length, 1);
328
- assert.equal(items[0].title, 'RSS.app Item');
329
- assert.equal(items[0].content, 'Content from RSS.app feed.');
330
- },
331
- },
332
-
333
- {
334
- name: 'json-empty-items-returns-empty',
335
- async run({ assert }) {
336
- const { items } = parseFeed(JSON.stringify({ items: [] }));
337
- assert.equal(items.length, 0);
338
- },
339
- },
340
-
341
- // ============================
342
- // EDGE CASES
343
- // ============================
344
- {
345
- name: 'returns-empty-for-null-input',
346
- async run({ assert }) {
347
- assert.deepEqual(parseFeed(null), { items: [] });
348
- },
349
- },
350
-
351
- {
352
- name: 'returns-empty-for-undefined-input',
353
- async run({ assert }) {
354
- assert.deepEqual(parseFeed(undefined), { items: [] });
355
- },
356
- },
357
-
358
- {
359
- name: 'returns-empty-for-empty-string',
360
- async run({ assert }) {
361
- assert.deepEqual(parseFeed(''), { items: [] });
362
- },
363
- },
364
-
365
- {
366
- name: 'returns-empty-for-invalid-xml',
367
- async run({ assert }) {
368
- const { items } = parseFeed('<not<valid>xml');
369
- assert.equal(items.length, 0);
370
- },
371
- },
372
-
373
- {
374
- name: 'returns-empty-for-non-feed-json',
375
- async run({ assert }) {
376
- const { items } = parseFeed(JSON.stringify({ data: [1, 2, 3] }));
377
- assert.equal(items.length, 0);
378
- },
379
- },
380
-
381
- {
382
- name: 'returns-empty-for-plain-text',
383
- async run({ assert }) {
384
- const { items } = parseFeed('just some plain text content');
385
- assert.equal(items.length, 0);
386
- },
387
- },
388
-
389
- {
390
- name: 'handles-bom-prefix',
391
- async run({ assert }) {
392
- const withBom = '' + RSS_MINIMAL;
393
- const { items } = parseFeed(withBom);
394
- assert.equal(items.length, 1, 'BOM does not break parsing');
395
- assert.equal(items[0].title, 'Only Title');
396
- },
397
- },
398
-
399
- {
400
- name: 'handles-namespace-prefixed-elements',
401
- async run({ assert }) {
402
- const { items } = parseFeed(RSS_FULL);
403
- assert.ok(items[0].content.includes('Full content'), 'content:encoded parsed despite namespace');
404
- },
405
- },
406
-
407
- {
408
- name: 'truncates-long-content',
409
- async run({ assert }) {
410
- const longContent = 'x'.repeat(20000);
411
- const feed = JSON.stringify({
412
- items: [{ id: '1', title: 'Long', url: 'https://example.com', content_text: longContent }],
413
- });
414
- const { items } = parseFeed(feed);
415
- assert.ok(items[0].content.length <= 1024 * 14, 'content truncated to 14KB');
416
- },
417
- },
418
-
419
- {
420
- name: 'truncates-long-summary',
421
- async run({ assert }) {
422
- const longSummary = 'y'.repeat(1000);
423
- const feed = JSON.stringify({
424
- items: [{ id: '1', title: 'Long Summary', url: 'https://example.com', summary: longSummary }],
425
- });
426
- const { items } = parseFeed(feed);
427
- assert.ok(items[0].summary.length <= 500, 'summary truncated to 500 chars');
428
- },
429
- },
430
-
431
- // ============================
432
- // STRIP HTML
433
- // ============================
434
- {
435
- name: 'stripHtml-removes-tags',
436
- async run({ assert }) {
437
- assert.equal(stripHtml('<p>Hello <strong>world</strong></p>'), 'Hello world');
438
- },
439
- },
440
-
441
- {
442
- name: 'stripHtml-normalizes-whitespace',
443
- async run({ assert }) {
444
- assert.equal(stripHtml('<p>Hello</p> <p>World</p>'), 'Hello World');
445
- },
446
- },
447
-
448
- {
449
- name: 'stripHtml-handles-empty-string',
450
- async run({ assert }) {
451
- assert.equal(stripHtml(''), '');
452
- },
453
- },
454
-
455
- // ============================
456
- // EXTRACT TEXT FROM HTML (Cheerio)
457
- // ============================
458
- {
459
- name: 'extractTextFromHtml-extracts-from-article-tag',
460
- async run({ assert }) {
461
- const html = '<html><body><nav>Menu</nav><article class="post"><p>Article content</p></article><footer>Footer</footer></body></html>';
462
- const text = extractTextFromHtml(html);
463
- assert.ok(text.includes('Article content'), 'extracts article text');
464
- assert.ok(!text.includes('Menu'), 'nav removed');
465
- assert.ok(!text.includes('Footer'), 'footer removed');
466
- },
467
- },
468
-
469
- {
470
- name: 'extractTextFromHtml-falls-back-to-main',
471
- async run({ assert }) {
472
- const html = '<html><body><main><p>Main content</p></main><aside>Sidebar</aside></body></html>';
473
- const text = extractTextFromHtml(html);
474
- assert.ok(text.includes('Main content'), 'extracts main text');
475
- assert.ok(!text.includes('Sidebar'), 'aside removed');
476
- },
477
- },
478
-
479
- {
480
- name: 'extractTextFromHtml-falls-back-to-body',
481
- async run({ assert }) {
482
- const html = '<html><body><p>Body content here</p></body></html>';
483
- const text = extractTextFromHtml(html);
484
- assert.ok(text.includes('Body content here'), 'extracts body text');
485
- },
486
- },
487
-
488
- {
489
- name: 'extractTextFromHtml-strips-scripts-and-styles',
490
- async run({ assert }) {
491
- const html = '<html><body><article><script>alert("xss")</script><style>.x{color:red}</style><p>Clean text</p></article></body></html>';
492
- const text = extractTextFromHtml(html);
493
- assert.ok(text.includes('Clean text'), 'keeps article text');
494
- assert.ok(!text.includes('alert'), 'script removed');
495
- assert.ok(!text.includes('color'), 'style removed');
496
- },
497
- },
498
-
499
- {
500
- name: 'extractTextFromHtml-strips-forms-and-buttons',
501
- async run({ assert }) {
502
- const html = '<html><body><article><p>Article text</p><form><input placeholder="Email"><button>Subscribe</button></form></article></body></html>';
503
- const text = extractTextFromHtml(html);
504
- assert.ok(text.includes('Article text'), 'keeps article text');
505
- assert.ok(!text.includes('Subscribe'), 'button removed');
506
- },
507
- },
508
-
509
- {
510
- name: 'extractTextFromHtml-strips-ad-classes',
511
- async run({ assert }) {
512
- const html = '<html><body><article><p>Real content</p><div class="advertisement">Buy stuff</div><div class="social-share">Share this</div></article></body></html>';
513
- const text = extractTextFromHtml(html);
514
- assert.ok(text.includes('Real content'), 'keeps article text');
515
- assert.ok(!text.includes('Buy stuff'), 'ad removed');
516
- assert.ok(!text.includes('Share this'), 'social share removed');
517
- },
518
- },
519
-
520
- {
521
- name: 'extractTextFromHtml-returns-empty-for-empty-html',
522
- async run({ assert }) {
523
- assert.equal(extractTextFromHtml(''), '');
524
- assert.equal(extractTextFromHtml('<html><body></body></html>'), '');
525
- },
526
- },
527
- ],
528
- };
@@ -1,134 +0,0 @@
1
- /**
2
- * Test: content/ghostii.blocksToPost()
3
- * Unit tests for the Ghostii-JSON → BEM-post transform.
4
- *
5
- * Run: npx mgr test helpers/content/ghostii-blocks
6
- *
7
- * Ghostii is unopinionated about BEM: its /write/article response is a generic
8
- * block array ([{ name, content }], name ∈ heading-1..6/image/paragraph/blockquote/list).
9
- * blocksToPost() is the SSOT that turns those blocks into what admin/post wants —
10
- * title + header image as SEPARATE fields, body = content only.
11
- *
12
- * Pure function (no I/O) → required directly and called with plain inputs. NOT a mock.
13
- *
14
- * Contract:
15
- * - title ← first heading-1 block, leading markdown `#` stripped
16
- * - headerImageUrl ← first image block's URL (from `![alt](url)`)
17
- * - body ← every remaining block, joined with blank lines, trimmed
18
- * - the title block and the header-image block are EXCLUDED from body
19
- * - section images (non-first image blocks) STAY in the body
20
- * - non-array / empty input → all empty strings
21
- */
22
- const { blocksToPost } = require('../../../src/manager/libraries/content/ghostii.js');
23
-
24
- module.exports = {
25
- description: 'content/ghostii.blocksToPost()',
26
- type: 'group',
27
-
28
- tests: [
29
- {
30
- name: 'extracts-title-from-heading-1-stripping-marker',
31
- async run({ assert }) {
32
- const result = blocksToPost([
33
- { name: 'heading-1', content: '# My Great Article' },
34
- { name: 'paragraph', content: 'Body.' },
35
- ]);
36
- assert.equal(result.title, 'My Great Article');
37
- },
38
- },
39
-
40
- {
41
- name: 'extracts-header-image-url-from-first-image-block',
42
- async run({ assert }) {
43
- const result = blocksToPost([
44
- { name: 'heading-1', content: '# Title' },
45
- { name: 'image', content: '![Title](https://images.unsplash.com/photo-abc?w=1080)' },
46
- { name: 'paragraph', content: 'Body.' },
47
- ]);
48
- assert.equal(result.headerImageUrl, 'https://images.unsplash.com/photo-abc?w=1080');
49
- },
50
- },
51
-
52
- {
53
- name: 'body-excludes-title-and-header-image',
54
- async run({ assert }) {
55
- const result = blocksToPost([
56
- { name: 'heading-1', content: '# Title' },
57
- { name: 'image', content: '![Title](https://img/header.jpg)' },
58
- { name: 'heading-2', content: '## First Section' },
59
- { name: 'paragraph', content: 'First paragraph.' },
60
- ]);
61
- assert.equal(result.body, '## First Section\n\nFirst paragraph.', 'body is content only');
62
- assert.notMatch(result.body, /^#\s/m, 'no H1 title in body');
63
- assert.notMatch(result.body, /^!\[Title\]\(https:\/\/img\/header\.jpg\)/m, 'no header image in body');
64
- },
65
- },
66
-
67
- {
68
- name: 'keeps-section-images-in-body',
69
- async run({ assert }) {
70
- const result = blocksToPost([
71
- { name: 'heading-1', content: '# Title' },
72
- { name: 'image', content: '![Title](https://img/header.jpg)' },
73
- { name: 'heading-2', content: '## Section' },
74
- { name: 'paragraph', content: 'Text.' },
75
- { name: 'image', content: '![Section](https://img/section.jpg)' },
76
- { name: 'paragraph', content: 'More text.' },
77
- ]);
78
- // Only the FIRST image is the header; later images belong to the body.
79
- assert.ok(result.body.includes('![Section](https://img/section.jpg)'), 'section image stays in body');
80
- assert.equal((result.body.match(/!\[/g) || []).length, 1, 'exactly one (section) image in body');
81
- },
82
- },
83
-
84
- {
85
- name: 'preserves-blockquotes-and-lists-in-body',
86
- async run({ assert }) {
87
- const result = blocksToPost([
88
- { name: 'heading-1', content: '# Title' },
89
- { name: 'heading-2', content: '## Section' },
90
- { name: 'blockquote', content: '> A pithy quote.' },
91
- { name: 'list', content: '- one\n- two' },
92
- ]);
93
- assert.ok(result.body.includes('> A pithy quote.'), 'blockquote kept');
94
- assert.ok(result.body.includes('- one\n- two'), 'list kept');
95
- },
96
- },
97
-
98
- {
99
- name: 'handles-missing-heading-1-and-image-gracefully',
100
- async run({ assert }) {
101
- const result = blocksToPost([
102
- { name: 'heading-2', content: '## Only Section' },
103
- { name: 'paragraph', content: 'Text.' },
104
- ]);
105
- assert.equal(result.title, '', 'no title when no heading-1');
106
- assert.equal(result.headerImageUrl, '', 'no header image when no image block');
107
- assert.equal(result.body, '## Only Section\n\nText.', 'body is all blocks when nothing excluded');
108
- },
109
- },
110
-
111
- {
112
- name: 'uses-only-the-first-image-as-header',
113
- async run({ assert }) {
114
- const result = blocksToPost([
115
- { name: 'image', content: '![first](https://img/first.jpg)' },
116
- { name: 'paragraph', content: 'Text.' },
117
- { name: 'image', content: '![second](https://img/second.jpg)' },
118
- ]);
119
- assert.equal(result.headerImageUrl, 'https://img/first.jpg', 'first image is the header');
120
- assert.ok(result.body.includes('https://img/second.jpg'), 'second image stays in body');
121
- assert.ok(!result.body.includes('https://img/first.jpg'), 'first image not in body');
122
- },
123
- },
124
-
125
- {
126
- name: 'non-array-or-empty-input-returns-empty-strings',
127
- async run({ assert }) {
128
- assert.deepEqual(blocksToPost([]), { title: '', headerImageUrl: '', body: '' }, 'empty array');
129
- assert.deepEqual(blocksToPost(null), { title: '', headerImageUrl: '', body: '' }, 'null');
130
- assert.deepEqual(blocksToPost(undefined), { title: '', headerImageUrl: '', body: '' }, 'undefined');
131
- },
132
- },
133
- ],
134
- };