Stripe: Testrabatt-Namen, Produktbild, Hosting-Leistungen, Tests für Bestandskunden
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c4607e9c43
commit
7df0b72019
7 files changed
+297
-52
No files matched your search
+47
-7
@@ -102,10 +102,17 @@ test('priceIdsOfInvoice: eindeutige Preis-IDs, ohne Lücken', () => {
|
||||
assert.deepEqual(priceIdsOfInvoice(inv), ['price_w'])
|
||||
})
|
||||
|
||||
// Fix round 1 / B9: feste Form statt Einzelfelder
|
||||
test('Vertragsunterlagen je Version', () => {
|
||||
assert.equal(termsDocFor('2026-10-05-v4').pdfFile, 'WEBklar-Abo-Vertragsunterlagen.pdf')
|
||||
assert.equal(termsDocFor('2026-09-25-v3').url, '/vertragsunterlagen/v3/abo-bedingungen.html')
|
||||
assert.equal(termsDocFor(null).url, '/vertragsunterlagen/v3/abo-bedingungen.html')
|
||||
assert.deepEqual(termsDocFor('2026-10-05-v4'), { url: '/abo-bedingungen.html', pdfFile: 'WEBklar-Abo-Vertragsunterlagen.pdf' })
|
||||
assert.deepEqual(termsDocFor('2026-09-25-v3'), {
|
||||
url: '/vertragsunterlagen/v3/abo-bedingungen.html',
|
||||
pdfFile: 'WEBklar-Wartungs-Abo-Vertragsunterlagen.pdf',
|
||||
})
|
||||
assert.deepEqual(termsDocFor(null), {
|
||||
url: '/vertragsunterlagen/v3/abo-bedingungen.html',
|
||||
pdfFile: 'WEBklar-Wartungs-Abo-Vertragsunterlagen.pdf',
|
||||
})
|
||||
})
|
||||
|
||||
test('Produktansicht enthält Leistungen ohne 1-Postfach-Regel bei Wartung', () => {
|
||||
@@ -114,10 +121,43 @@ test('Produktansicht enthält Leistungen ohne 1-Postfach-Regel bei Wartung', ()
|
||||
assert.ok(productView('hosting').features.flat().join(' ').includes('1 E-Mail-Postfach'))
|
||||
})
|
||||
|
||||
// Fix round 1, Important 3: Hosting darf keine Website-Pflege suggerieren (row 1 war von Wartung
|
||||
// kopiert) und muss "in 15-Minuten-Schritten" nennen.
|
||||
test('Produktansicht Hosting: Betriebssystem/Server-Software statt Website-Pflege', () => {
|
||||
const h = productView('hosting').features.flat().join(' ')
|
||||
assert.ok(h.includes('Betriebssystem und Server-Software'))
|
||||
assert.ok(!h.includes('Updates, Sicherheit'))
|
||||
assert.ok(h.includes('15-Minuten-Schritten'))
|
||||
})
|
||||
|
||||
// Fix round 1, B9: volle Form statt Einzelfelder, Kopie statt Referenz auf den Katalog (B10)
|
||||
test('productView: vollständige Form, Kopie der features', () => {
|
||||
const v = productView('hosting')
|
||||
assert.deepEqual(Object.keys(v).sort(), ['amountCents', 'features', 'key', 'minTermMonths', 'minutesPerMonth', 'name'].sort())
|
||||
assert.equal(v.key, 'hosting')
|
||||
assert.equal(v.name, 'WEBklar Hosting-Abo')
|
||||
assert.equal(v.amountCents, 1500)
|
||||
assert.equal(v.minTermMonths, 12)
|
||||
assert.equal(v.minutesPerMonth, 0)
|
||||
assert.ok(Array.isArray(v.features) && v.features.length > 0)
|
||||
v.features.push(['x', 'y'])
|
||||
assert.notEqual(productView('hosting').features.length, v.features.length)
|
||||
})
|
||||
|
||||
// F07: die Wartungs-Beschreibung darf die alte 1-Postfach-Regel nicht mehr enthalten (Version 4:
|
||||
// beliebig viele Postfächer, zusammen 5 GB). Der Stripe-Produkttext selbst wird erst beim
|
||||
// Livegang ueber scripts/stripe-products.mjs gesetzt.
|
||||
// beliebig viele E-Mail-Postfächer, zusammen 5 GB). Der Stripe-Produkttext selbst wird erst beim
|
||||
// Livegang ueber scripts/stripe-products.mjs gesetzt. B9: auch das § 19-Satzende pruefen.
|
||||
test('Wartung-Beschreibung ohne 1-Postfach-Regel (F07)', () => {
|
||||
assert.ok(!getProduct('wartung').description.includes('1 E-Mail-Postfach'))
|
||||
assert.ok(getProduct('wartung').description.includes('beliebig viele Postfächer'))
|
||||
const d = getProduct('wartung').description
|
||||
assert.ok(!d.includes('1 E-Mail-Postfach'))
|
||||
assert.ok(d.includes('beliebig viele E-Mail-Postfächer'))
|
||||
assert.ok(d.endsWith('Gemäß § 19 UStG ohne Umsatzsteuer.'))
|
||||
})
|
||||
|
||||
// Fix round 1, item 11: Domain-Zeile nennt die Endungen wie spec 3.1 / v4 § 3 Abs. 3
|
||||
test('Produktansicht: Domain-Zeile nennt die Endungen', () => {
|
||||
for (const key of ['wartung', 'hosting']) {
|
||||
const flat = productView(key).features.flat().join(' ')
|
||||
assert.ok(flat.includes('.de') && flat.includes('.com') && flat.includes('.eu') && flat.includes('.net') && flat.includes('.org'))
|
||||
}
|
||||
})
|
||||
+129
-9
@@ -9,7 +9,17 @@ const aw = await startAppwriteMock({ schema: { subscriptions: schemaKeys('subscr
|
||||
const st = await startFakeStripe()
|
||||
after(() => Promise.all([aw.close(), st.close()]))
|
||||
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
|
||||
const { syncSubscription, ensurePrice, ensureTestCoupon, ensurePortalConfiguration } = await import('../server/services/stripeBilling.js')
|
||||
const { config } = await import('../server/config.js')
|
||||
const {
|
||||
syncSubscription,
|
||||
ensurePrice,
|
||||
ensureTestCoupon,
|
||||
ensurePortalConfiguration,
|
||||
termStartOf,
|
||||
getStripe,
|
||||
PORTAL_HEADLINE,
|
||||
resetPortalConfigCacheForTests,
|
||||
} = await import('../server/services/stripeBilling.js')
|
||||
|
||||
const sub = (id, items, extra = {}) => ({
|
||||
id,
|
||||
@@ -53,6 +63,30 @@ test('Spiegel: Wartungs-Abo wie bisher', async () => {
|
||||
st.subscriptions.set('sub_w', sub('sub_w', [item('w', 'webklar_wartung_monatlich_5000', 5000)]))
|
||||
const doc = await syncSubscription('sub_w')
|
||||
assert.deepEqual([doc.productKey, doc.planKey, doc.priceAmount], ['wartung', 'webklar_wartung_monatlich_5000', 5000])
|
||||
// Fix round 1, Important 4: Bestandskunde ohne Wechsel-Metadaten -> termStartAt vom Leistungsbeginn (start_date)
|
||||
assert.equal(doc.termStartAt, new Date(1790000000 * 1000).toISOString())
|
||||
})
|
||||
|
||||
// Fix round 1, Important 4: mit Probezeit (trial_end) und ohne Wechsel-Metadaten gewinnt trial_end
|
||||
test('Spiegel: termStartAt ohne Wechsel-Metadaten faellt auf trial_end zurueck (Probezeit)', async () => {
|
||||
st.subscriptions.set('sub_trial', sub('sub_trial', [item('wt', 'webklar_wartung_monatlich_5000', 5000)], { trial_end: 1791234567 }))
|
||||
const doc = await syncSubscription('sub_trial')
|
||||
assert.equal(doc.termStartAt, new Date(1791234567 * 1000).toISOString())
|
||||
})
|
||||
|
||||
// Fix round 1, Minor 5: eine von Hand verstellte/ungueltige Metadaten-Angabe darf nicht crashen
|
||||
// (toISOString auf Invalid Date wuerde werfen) - Warnung statt Absturz, Fallback wie ohne Metadaten
|
||||
test('termStartOf: ungültiges Datum in den Metadaten -> Warnung, Fallback auf trial_end/start_date', () => {
|
||||
const original = console.warn
|
||||
const warnings = []
|
||||
console.warn = (...args) => warnings.push(args.join(' '))
|
||||
try {
|
||||
const result = termStartOf({ id: 'sub_bad', metadata: { termStartAt: 'nicht-valide' }, trial_end: 1791234567, start_date: 1790000000 })
|
||||
assert.equal(result.toISOString(), new Date(1791234567 * 1000).toISOString())
|
||||
assert.ok(warnings.some((w) => w.includes('termStartAt')))
|
||||
} finally {
|
||||
console.warn = original
|
||||
}
|
||||
})
|
||||
|
||||
test('Spiegel: unbekannter Preis gilt als Wartungs-Abo, Betrag vom ersten Posten', async () => {
|
||||
@@ -63,23 +97,91 @@ test('Spiegel: unbekannter Preis gilt als Wartungs-Abo, Betrag vom ersten Posten
|
||||
|
||||
// Stripe-Nachbau braucht dazu: POST /v1/products, POST /v1/prices, GET /v1/coupons/:id, POST /v1/coupons,
|
||||
// GET/POST /v1/billing_portal/configurations und POST /v1/billing_portal/configurations/:id (F09)
|
||||
test('ensurePrice legt Hosting einmal an', async () => {
|
||||
// Fix round 1, B9: before-Snapshot statt ueber die ganze Datei zaehlen; Preis-/Produktfelder und Bild geprueft
|
||||
test('ensurePrice legt Hosting einmal an: Preis- und Produktfelder, Bild', async () => {
|
||||
const before = st.calls.length
|
||||
const id1 = await ensurePrice('hosting'); const id2 = await ensurePrice('hosting')
|
||||
assert.equal(id1, id2)
|
||||
const created = st.calls.filter((c) => c.method === 'POST' && c.path === '/v1/prices')
|
||||
assert.equal(created.length, 1)
|
||||
assert.equal(created[0].body['lookup_key'], 'webklar_hosting_monatlich_1500')
|
||||
assert.equal(created[0].body['unit_amount'], '1500')
|
||||
const calls = st.calls.slice(before)
|
||||
const createdPrices = calls.filter((c) => c.method === 'POST' && c.path === '/v1/prices')
|
||||
assert.equal(createdPrices.length, 1)
|
||||
assert.equal(createdPrices[0].body['lookup_key'], 'webklar_hosting_monatlich_1500')
|
||||
assert.equal(createdPrices[0].body['unit_amount'], '1500')
|
||||
assert.equal(createdPrices[0].body['tax_behavior'], 'inclusive')
|
||||
assert.equal(createdPrices[0].body['recurring[interval]'], 'month')
|
||||
const createdProducts = calls.filter((c) => c.method === 'POST' && c.path === '/v1/products')
|
||||
assert.equal(createdProducts.length, 1)
|
||||
assert.equal(createdProducts[0].body['metadata[webklar]'], 'hosting-abo')
|
||||
// Important 2: Produktbild wiederhergestellt (7799d7c:71 hatte es, ging beim Verallgemeinern verloren)
|
||||
assert.equal(createdProducts[0].body['images[0]'], config.stripe.productImage)
|
||||
})
|
||||
|
||||
test('Testrabatt Hosting: 14,50 € Nachlass', async () => {
|
||||
// Important 4: ein bereits vorhandener aktiver Preis wird gefunden, nichts wird bei Stripe angelegt
|
||||
test('ensurePrice: vorhandener aktiver Preis wird gefunden, nichts wird angelegt', async () => {
|
||||
st.prices.set('price_seeded_wartung', {
|
||||
id: 'price_seeded_wartung',
|
||||
object: 'price',
|
||||
active: true,
|
||||
lookup_key: 'webklar_wartung_monatlich_5000',
|
||||
unit_amount: 5000,
|
||||
recurring: { interval: 'month' },
|
||||
tax_behavior: 'inclusive',
|
||||
})
|
||||
const before = st.calls.length
|
||||
const id = await ensurePrice('wartung')
|
||||
assert.equal(id, 'price_seeded_wartung')
|
||||
const writes = st.calls.slice(before).filter((c) => c.method === 'POST' && (c.path === '/v1/products' || c.path === '/v1/prices'))
|
||||
assert.deepEqual(writes, [])
|
||||
})
|
||||
|
||||
// Important 1 (Stripe-Nachbau-Haertung): Stripe begrenzt Coupon-Namen auf 40 Zeichen, IDs und aktive
|
||||
// lookup_keys sind eindeutig - der Nachbau soll das wie die echte API mit 400 quittieren.
|
||||
test('Stripe-Nachbau: Grenzen bei Preisen und Coupons (400)', async () => {
|
||||
const stripe = getStripe()
|
||||
st.prices.set('price_dup_lookup', {
|
||||
id: 'price_dup_lookup', object: 'price', active: true, lookup_key: 'lookup_fuer_diesen_test', unit_amount: 100,
|
||||
})
|
||||
await assert.rejects(
|
||||
stripe.prices.create({ product: 'prod_x', currency: 'eur', unit_amount: 100, lookup_key: 'lookup_fuer_diesen_test' }),
|
||||
(err) => err.statusCode === 400
|
||||
)
|
||||
st.coupons.set('coupon_dup', { id: 'coupon_dup', object: 'coupon', name: 'x' })
|
||||
await assert.rejects(
|
||||
stripe.coupons.create({ id: 'coupon_dup', name: 'y', amount_off: 100, currency: 'eur', duration: 'once' }),
|
||||
(err) => err.statusCode === 400
|
||||
)
|
||||
await assert.rejects(
|
||||
stripe.coupons.create({ name: 'x'.repeat(41), amount_off: 100, currency: 'eur', duration: 'once' }),
|
||||
(err) => err.statusCode === 400
|
||||
)
|
||||
})
|
||||
|
||||
// Important 1: Namen ≤ 40 Zeichen (Stripe-Limit; die alten Namen mit dem vollen Produktnamen waren 49/50)
|
||||
test('Testrabatt Hosting: 14,50 € Nachlass, Name ≤ 40 Zeichen', async () => {
|
||||
const before = st.calls.length
|
||||
assert.equal(await ensureTestCoupon('hosting'), 'WEBKLAR-TEST-050-HOSTING')
|
||||
assert.equal(st.calls.find((c) => c.path === '/v1/coupons' && c.method === 'POST').body['amount_off'], '1450')
|
||||
const call = st.calls.slice(before).find((c) => c.path === '/v1/coupons' && c.method === 'POST')
|
||||
assert.equal(call.body['amount_off'], '1450')
|
||||
assert.equal(call.body['name'], 'Testzugang Hosting (0,50 €)')
|
||||
assert.ok(call.body['name'].length <= 40)
|
||||
})
|
||||
|
||||
test('Testrabatt Wartung: 49,50 € Nachlass, Name ≤ 40 Zeichen', async () => {
|
||||
const before = st.calls.length
|
||||
assert.equal(await ensureTestCoupon('wartung'), 'WEBKLAR-TEST-050')
|
||||
const call = st.calls.slice(before).find((c) => c.path === '/v1/coupons' && c.method === 'POST')
|
||||
assert.equal(call.body['amount_off'], '4950')
|
||||
assert.equal(call.body['name'], 'Testzugang Wartung (0,50 €)')
|
||||
assert.ok(call.body['name'].length <= 40)
|
||||
})
|
||||
|
||||
// F09: eine bestehende eigene Konfiguration mit der alten Wartungs-Abo-Überschrift wird angepasst,
|
||||
// nicht doppelt angelegt.
|
||||
// nicht doppelt angelegt. Fix round 1, Minor 6: eigener Cache-Reset + eigene Map, damit dieser Test
|
||||
// unabhaengig vom No-op-Test (gleiche Funktion, anderer Zweig) lauffaehig bleibt - ensurePortalConfiguration
|
||||
// cached die Konfigurations-ID sonst ueber den ganzen Prozess hinweg.
|
||||
test('Kundenportal: alte Überschrift → configurations.update', async () => {
|
||||
resetPortalConfigCacheForTests()
|
||||
st.billingPortalConfigurations.clear()
|
||||
st.billingPortalConfigurations.set('bpc_old', {
|
||||
id: 'bpc_old',
|
||||
object: 'billing_portal.configuration',
|
||||
@@ -94,6 +196,24 @@ test('Kundenportal: alte Überschrift → configurations.update', async () => {
|
||||
assert.equal(updateCall.body['business_profile[headline]'], 'WEBklar – Abo verwalten')
|
||||
})
|
||||
|
||||
// Minor 6: Ueberschrift schon richtig -> kein ueberfluessiger update-Aufruf
|
||||
test('Kundenportal: Überschrift schon richtig → kein Update-Aufruf', async () => {
|
||||
resetPortalConfigCacheForTests()
|
||||
st.billingPortalConfigurations.clear()
|
||||
st.billingPortalConfigurations.set('bpc_ok', {
|
||||
id: 'bpc_ok',
|
||||
object: 'billing_portal.configuration',
|
||||
active: true,
|
||||
business_profile: { headline: PORTAL_HEADLINE },
|
||||
metadata: { webklar: 'wartungs-abo' },
|
||||
})
|
||||
const before = st.calls.length
|
||||
const id = await ensurePortalConfiguration()
|
||||
assert.equal(id, 'bpc_ok')
|
||||
const updateCalls = st.calls.slice(before).filter((c) => c.method === 'POST' && c.path.startsWith('/v1/billing_portal/configurations/'))
|
||||
assert.deepEqual(updateCalls, [])
|
||||
})
|
||||
|
||||
test('Spiegel: termStartAt aus Metadaten (Wechsel), sonst Leistungsbeginn; storageUnits', async () => {
|
||||
st.subscriptions.set(
|
||||
'sub_s',
|
||||
|
||||
@@ -66,6 +66,14 @@ export async function startFakeStripe() {
|
||||
}
|
||||
if (method === 'POST' && path === '/v1/prices') {
|
||||
const data = unflatten(body)
|
||||
// Wie echtes Stripe: ein lookup_key darf nur an einem aktiven Preis gleichzeitig haengen
|
||||
// (Fix round 1, Important 1 - haertet den Nachbau, ensurePrice fragt vorher ohnehin per GET)
|
||||
if (data.lookup_key) {
|
||||
const clash = [...prices.values()].find((p) => p.lookup_key === data.lookup_key && p.active !== false)
|
||||
if (clash) {
|
||||
return [400, { error: { type: 'invalid_request_error', param: 'lookup_key', message: `An active price already exists for lookup_key: '${data.lookup_key}'.` } }]
|
||||
}
|
||||
}
|
||||
const obj = {
|
||||
id: nextId('price'),
|
||||
object: 'price',
|
||||
@@ -84,6 +92,10 @@ export async function startFakeStripe() {
|
||||
if (method === 'GET' && (m = path.match(/^\/v1\/invoices\/([^/]+)$/))) {
|
||||
return invoices.has(m[1]) ? [200, invoices.get(m[1])] : noSuch('invoice', m[1])
|
||||
}
|
||||
// scripts/stripe-products.mjs --pruefen liest das Produkt zurueck (Beschreibung, Bild)
|
||||
if (method === 'GET' && (m = path.match(/^\/v1\/products\/([^/]+)$/))) {
|
||||
return products.has(m[1]) ? [200, products.get(m[1])] : noSuch('product', m[1])
|
||||
}
|
||||
if (method === 'POST' && path === '/v1/products') {
|
||||
const data = unflatten(body)
|
||||
const obj = {
|
||||
@@ -93,6 +105,7 @@ export async function startFakeStripe() {
|
||||
name: data.name || '',
|
||||
description: data.description ?? null,
|
||||
statement_descriptor: data.statement_descriptor ?? null,
|
||||
images: data.images || [],
|
||||
metadata: data.metadata || {},
|
||||
}
|
||||
products.set(obj.id, obj)
|
||||
@@ -104,6 +117,13 @@ export async function startFakeStripe() {
|
||||
if (method === 'POST' && path === '/v1/coupons') {
|
||||
const data = unflatten(body)
|
||||
const id = data.id || nextId('coupon')
|
||||
// Wie echtes Stripe: Name auf 40 Zeichen begrenzt, IDs eindeutig (Fix round 1, Important 1)
|
||||
if (data.name && data.name.length > 40) {
|
||||
return [400, { error: { type: 'invalid_request_error', param: 'name', message: 'Name must be no more than 40 characters.' } }]
|
||||
}
|
||||
if (coupons.has(id)) {
|
||||
return [400, { error: { type: 'invalid_request_error', message: `Coupon with ID '${id}' already exists.` } }]
|
||||
}
|
||||
const obj = {
|
||||
id,
|
||||
object: 'coupon',
|
||||
|
||||
Reference in new issue
Block a user