Schützt Webhooks und den öffentlichen Kündigungs-/Widerrufsknopf, falls das Setup-Skript erst nach dem Deploy läuft; der Fehler steht laut im Log. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
2.1 KiB
JavaScript
52 lines
2.1 KiB
JavaScript
import { test, after } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { startAppwriteMock } from './support/appwriteMock.js'
|
|
import { startFakeStripe } from './support/fakeStripe.js'
|
|
import { useTestEnv } from './support/testEnv.js'
|
|
import { schemaKeys } from './support/schema.js'
|
|
|
|
// Produktion, bevor das Setup-Skript gelaufen ist: Appwrite kennt productKey noch nicht
|
|
const aw = await startAppwriteMock({
|
|
schema: { subscriptions: schemaKeys('subscriptions').filter((key) => key !== 'productKey') },
|
|
})
|
|
const st = await startFakeStripe()
|
|
after(() => Promise.all([aw.close(), st.close()]))
|
|
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
|
|
const { syncSubscription } = await import('../server/services/stripeBilling.js')
|
|
|
|
const sub = (id, cancelAtPeriodEnd) => ({
|
|
id,
|
|
object: 'subscription',
|
|
status: 'active',
|
|
customer: 'cus_1',
|
|
start_date: 1790000000,
|
|
current_period_end: 1792600000,
|
|
cancel_at_period_end: cancelAtPeriodEnd,
|
|
metadata: { webklarCustomerId: 'c1', email: 'k@example.invalid', termsVersion: '2026-09-25-v3' },
|
|
items: {
|
|
object: 'list',
|
|
data: [{ id: 'si_w', quantity: 1, price: { id: 'price_w', lookup_key: 'webklar_wartung_monatlich_5000', unit_amount: 5000 } }],
|
|
},
|
|
})
|
|
|
|
test('Fehlendes Feld in Appwrite: Abo wird trotzdem gespiegelt (anlegen und ändern)', async () => {
|
|
const errors = []
|
|
const original = console.error
|
|
console.error = (...args) => errors.push(args.join(' '))
|
|
try {
|
|
st.subscriptions.set('sub_w', sub('sub_w', false))
|
|
const created = await syncSubscription('sub_w')
|
|
assert.equal(created.status, 'active')
|
|
assert.equal('productKey' in created, false)
|
|
|
|
// z. B. Kündigung über den öffentlichen Knopf: Stripe ist schon geändert, der Spiegel muss folgen
|
|
st.subscriptions.set('sub_w', sub('sub_w', true))
|
|
const updated = await syncSubscription('sub_w')
|
|
assert.equal(updated.cancelAtPeriodEnd, true)
|
|
assert.equal(aw.docs('subscriptions').get('sub_w').cancelAtPeriodEnd, true)
|
|
} finally {
|
|
console.error = original
|
|
}
|
|
assert.ok(errors.some((line) => line.includes('productKey')), 'Fehler im Log nennt das fehlende Feld')
|
|
})
|