Tests: Stripe- und Appwrite-Nachbau im Testprozess
getStripe() nutzt in Tests über STRIPE_API_BASE den Nachbau auf 127.0.0.1; in Produktion ist der Wert leer und nichts ändert sich. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
877fde7a6f
commit
54defb75c4
6 files changed
+271
-1
No files matched your search
@@ -0,0 +1,45 @@
|
||||
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'
|
||||
|
||||
// Nachbauten starten und die Umgebung setzen, BEVOR config.js geladen wird
|
||||
const aw = await startAppwriteMock({ schema: { subscriptions: ['customerId', 'status'] } })
|
||||
const st = await startFakeStripe()
|
||||
after(() => Promise.all([aw.close(), st.close()]))
|
||||
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
|
||||
const { createDocument, getDocument, listDocuments, Query } = await import('../server/services/appwriteAdmin.js')
|
||||
const { getStripe } = await import('../server/services/stripeBilling.js')
|
||||
|
||||
test('Appwrite-Nachbau: anlegen, lesen, filtern', async () => {
|
||||
await createDocument('subscriptions', { customerId: 'c1', status: 'active' }, 'sub_a')
|
||||
await createDocument('subscriptions', { customerId: 'c2', status: 'active' }, 'sub_c')
|
||||
assert.equal((await getDocument('subscriptions', 'sub_a')).status, 'active')
|
||||
const list = await listDocuments('subscriptions', [Query.equal('customerId', 'c1'), Query.limit(5)])
|
||||
assert.deepEqual(list.map((d) => d.$id), ['sub_a'])
|
||||
})
|
||||
|
||||
test('Appwrite-Nachbau: doppelte ID 409, fehlendes Dokument 404', async () => {
|
||||
await assert.rejects(createDocument('subscriptions', { customerId: 'c1' }, 'sub_a'), (e) => e.status === 409)
|
||||
await assert.rejects(getDocument('subscriptions', 'gibt_es_nicht'), (e) => e.status === 404)
|
||||
})
|
||||
|
||||
test('Appwrite-Nachbau: Schema wie Appwrite', async () => {
|
||||
await assert.rejects(createDocument('subscriptions', { unbekannt: 1 }, 'sub_b'), (e) => e.status === 400)
|
||||
})
|
||||
|
||||
test('Stripe-Nachbau: getStripe spricht mit 127.0.0.1', async () => {
|
||||
st.subscriptions.set('sub_1', { id: 'sub_1', object: 'subscription', items: { object: 'list', data: [] } })
|
||||
assert.equal((await getStripe().subscriptions.retrieve('sub_1')).id, 'sub_1')
|
||||
assert.equal(st.calls.at(-1).path, '/v1/subscriptions/sub_1')
|
||||
})
|
||||
|
||||
test('Stripe-Nachbau: unbekannte ID 404', async () => {
|
||||
await assert.rejects(getStripe().prices.retrieve('price_weg'), (e) => e.statusCode === 404)
|
||||
})
|
||||
|
||||
test('useTestEnv lehnt fremde Hosts ab', () => {
|
||||
assert.throws(() => useTestEnv({ appwriteUrl: 'https://ticket.webklar.com/v1', stripeUrl: st.url }))
|
||||
assert.equal(new URL(process.env.APPWRITE_ENDPOINT).hostname, '127.0.0.1')
|
||||
})
|
||||
Reference in new issue
Block a user