37 lines
1.8 KiB
JavaScript
37 lines
1.8 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'
|
|
|
|
const aw = await startAppwriteMock()
|
|
const st = await startFakeStripe()
|
|
after(() => Promise.all([aw.close(), st.close()]))
|
|
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
|
|
const { listPlanUsage, computeLedger } = await import('../server/services/hourLedger.js')
|
|
|
|
const andrej = { employeeId: 'andrej', name: 'Andrej Stevanovski', task: 'Farbkonzept' }
|
|
aw.seed('workorders', { $id: 'wo1', customerId: 'c1', woid: '100200', topic: 'Startseite' })
|
|
const sheet = (id, over) => ({
|
|
$id: id, workorderId: 'wo1', woid: '100200', wsid: id, countsToPlan: true, totalTime: 60,
|
|
startDate: '30.09.2026', employeeName: 'Justin Klein', details: 'Arbeit', ...over,
|
|
})
|
|
aw.seed('worksheets', sheet('ws1', { supporters: JSON.stringify([andrej]) }))
|
|
aw.seed('worksheets', sheet('ws2', { supporters: 'kaputt', startDate: '29.09.2026' }))
|
|
|
|
test('Stundenkonto zieht die Unterstützung mit ab', async () => {
|
|
const usage = await listPlanUsage('c1')
|
|
const ws1 = usage.find((u) => u.id === 'ws1')
|
|
assert.equal(ws1.minutes, 90)
|
|
assert.equal(ws1.supportMinutes, 30)
|
|
const ws2 = usage.find((u) => u.id === 'ws2')
|
|
assert.equal(ws2.minutes, 60)
|
|
assert.equal(ws2.supportMinutes, 0)
|
|
})
|
|
|
|
test('90-min-Eintrag bei 60 min Guthaben: 30 min Mehraufwand', () => {
|
|
const credits = [{ $id: 'k1', minutes: 60, grantedAt: '2026-09-01T00:00:00Z', expiresAt: '2027-09-01T00:00:00Z' }]
|
|
const ledger = computeLedger(credits, [{ id: 'ws1', date: '2026-09-30T12:00:00Z', minutes: 90, supportMinutes: 30 }], { now: new Date('2026-09-30T13:00:00Z') })
|
|
assert.equal(ledger.entries?.[0]?.overageMinutes ?? ledger.usage?.[0]?.overageMinutes, 30)
|
|
})
|