Neues Appwrite-Feld subscriptions.productKey (Setup-Skript). Ohne bekannten Abo-Preis gilt ein Abo weiter als Wartungs-Abo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.4 KiB
JavaScript
63 lines
2.4 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'
|
|
|
|
const aw = await startAppwriteMock({ schema: { subscriptions: schemaKeys('subscriptions') } })
|
|
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, items, extra = {}) => ({
|
|
id,
|
|
object: 'subscription',
|
|
status: 'active',
|
|
customer: 'cus_1',
|
|
start_date: 1790000000,
|
|
current_period_end: 1792600000,
|
|
trial_end: null,
|
|
cancel_at_period_end: false,
|
|
cancel_at: null,
|
|
canceled_at: null,
|
|
ended_at: null,
|
|
metadata: { webklarCustomerId: 'c1', email: 'k@example.invalid', termsVersion: '2026-09-25-v3' },
|
|
items: { object: 'list', data: items },
|
|
...extra,
|
|
})
|
|
const item = (id, lookup_key, unit_amount, quantity = 1) => ({
|
|
id: `si_${id}`,
|
|
object: 'subscription_item',
|
|
quantity,
|
|
price: { id: `price_${id}`, object: 'price', lookup_key, unit_amount },
|
|
})
|
|
|
|
test('Setup-Skript legt productKey an', () => {
|
|
assert.ok(schemaKeys('subscriptions').includes('productKey'))
|
|
})
|
|
|
|
test('Spiegel: Hosting-Abo, Zusatzspeicher steht vorne', async () => {
|
|
st.subscriptions.set(
|
|
'sub_h',
|
|
sub('sub_h', [item('s', 'webklar_mailspeicher_5gb_monatlich_100', 100, 2), item('h', 'webklar_hosting_monatlich_1500', 1500)])
|
|
)
|
|
const doc = await syncSubscription('sub_h')
|
|
assert.equal(doc.productKey, 'hosting')
|
|
assert.equal(doc.planKey, 'webklar_hosting_monatlich_1500')
|
|
assert.equal(doc.priceAmount, 1500)
|
|
})
|
|
|
|
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])
|
|
})
|
|
|
|
test('Spiegel: unbekannter Preis gilt als Wartungs-Abo, Betrag vom ersten Posten', async () => {
|
|
st.subscriptions.set('sub_x', sub('sub_x', [item('x', null, 4900)]))
|
|
const doc = await syncSubscription('sub_x')
|
|
assert.deepEqual([doc.productKey, doc.planKey, doc.priceAmount], ['wartung', 'webklar_wartung_monatlich_5000', 4900])
|
|
})
|