Stripe: Preise je Produkt, Testrabatt Hosting, Kundenportal „Abo verwalten“, Mindestlaufzeit ab termStartAt
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7799d7c4de
commit
e5cc57cefd
7 files changed
+402
-35
No files matched your search
@@ -9,7 +9,7 @@ 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 } = await import('../server/services/stripeBilling.js')
|
||||
const { syncSubscription, ensurePrice, ensureTestCoupon, ensurePortalConfiguration } = await import('../server/services/stripeBilling.js')
|
||||
|
||||
const sub = (id, items, extra = {}) => ({
|
||||
id,
|
||||
@@ -60,3 +60,53 @@ test('Spiegel: unbekannter Preis gilt als Wartungs-Abo, Betrag vom ersten Posten
|
||||
const doc = await syncSubscription('sub_x')
|
||||
assert.deepEqual([doc.productKey, doc.planKey, doc.priceAmount], ['wartung', 'webklar_wartung_monatlich_5000', 4900])
|
||||
})
|
||||
|
||||
// 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 () => {
|
||||
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')
|
||||
})
|
||||
|
||||
test('Testrabatt Hosting: 14,50 € Nachlass', async () => {
|
||||
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')
|
||||
})
|
||||
|
||||
// F09: eine bestehende eigene Konfiguration mit der alten Wartungs-Abo-Überschrift wird angepasst,
|
||||
// nicht doppelt angelegt.
|
||||
test('Kundenportal: alte Überschrift → configurations.update', async () => {
|
||||
st.billingPortalConfigurations.set('bpc_old', {
|
||||
id: 'bpc_old',
|
||||
object: 'billing_portal.configuration',
|
||||
active: true,
|
||||
business_profile: { headline: 'Webklar – Wartungs-Abo verwalten' },
|
||||
metadata: { webklar: 'wartungs-abo' },
|
||||
})
|
||||
const id = await ensurePortalConfiguration()
|
||||
assert.equal(id, 'bpc_old')
|
||||
const updateCall = st.calls.find((c) => c.method === 'POST' && c.path === '/v1/billing_portal/configurations/bpc_old')
|
||||
assert.ok(updateCall)
|
||||
assert.equal(updateCall.body['business_profile[headline]'], 'WEBklar – Abo verwalten')
|
||||
})
|
||||
|
||||
test('Spiegel: termStartAt aus Metadaten (Wechsel), sonst Leistungsbeginn; storageUnits', async () => {
|
||||
st.subscriptions.set(
|
||||
'sub_s',
|
||||
sub('sub_s', [item('w2', 'webklar_wartung_monatlich_5000', 5000), item('s2', 'webklar_mailspeicher_5gb_monatlich_100', 100, 3)], {
|
||||
metadata: {
|
||||
webklarCustomerId: 'c1',
|
||||
email: 'k@example.invalid',
|
||||
termsVersion: '2026-09-25-v3',
|
||||
termStartAt: '2026-10-05T10:00:00.000Z',
|
||||
},
|
||||
})
|
||||
)
|
||||
const doc = await syncSubscription('sub_s')
|
||||
assert.equal(doc.termStartAt, '2026-10-05T10:00:00.000Z')
|
||||
assert.equal(doc.storageUnits, 3)
|
||||
})
|
||||
Reference in new issue
Block a user