29 lines
1.5 KiB
JavaScript
29 lines
1.5 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { useTestEnv } from './support/testEnv.js'
|
|
|
|
// Reiner Test von customerStripeInvoice: config.js liest die Umgebung beim ersten Import, die Adressen werden nie angefragt.
|
|
useTestEnv({ appwriteUrl: 'http://127.0.0.1:9', stripeUrl: 'http://127.0.0.1:9' })
|
|
const { customerStripeInvoice } = await import('../server/services/customerInvoices.js')
|
|
|
|
const roh = (over = {}) => ({
|
|
id: 'in_1', number: 'WEBKLAR-0009', status: 'open', effective_at: 1_791_000_000, due_date: 1_792_000_000,
|
|
total: 50000, amount_remaining: 50000, hosted_invoice_url: 'https://invoice.stripe.com/i/in_1',
|
|
invoice_pdf: 'https://pay.stripe.com/invoice/in_1/pdf', metadata: {}, ...over,
|
|
})
|
|
|
|
test('Rechnung der Kunden-Liste: projekt kommt aus metadata.projektName, sonst leer', () => {
|
|
assert.equal(customerStripeInvoice(roh({ metadata: { projektName: 'Website Anelia Wolf' } })).projekt, 'Website Anelia Wolf')
|
|
assert.equal(customerStripeInvoice(roh()).projekt, '')
|
|
assert.equal(customerStripeInvoice(roh({ metadata: { webklarCustomerId: 'c1', art: 'abo' } })).projekt, '')
|
|
const ohneMetadaten = roh()
|
|
delete ohneMetadaten.metadata
|
|
assert.equal(customerStripeInvoice(ohneMetadaten).projekt, '')
|
|
})
|
|
|
|
test('Rechnung der Kunden-Liste: die bisherigen Felder bleiben, projekt kommt dazu', () => {
|
|
assert.deepEqual(Object.keys(customerStripeInvoice(roh())).sort(), [
|
|
'amount', 'balance', 'cancelled', 'date', 'dueDate', 'hasPdf', 'id', 'number', 'overdue', 'paid', 'portalUrl', 'projekt', 'source', 'status',
|
|
])
|
|
})
|