Admin E-Mail-Speicher: belegter Speicher wie in konsoleH, klare Vorgabe je Kunde
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
12a24514a4
commit
cc42ab16c1
4 files changed
+69
-13
No files matched your search
@@ -21,7 +21,7 @@ const aw = await startAppwriteMock({
|
||||
const st = await startFakeStripe()
|
||||
useTestEnv({ appwriteUrl: aw.url, stripeUrl: st.url })
|
||||
const { config } = await import('../server/config.js')
|
||||
const { startTestApp, get, post, rawGet } = await import('./support/testApp.js')
|
||||
const { startTestApp, get, post, rawGet, sessionCookie } = await import('./support/testApp.js')
|
||||
const { hostingDoc, hosting2Doc, wartungDoc, subscriptionDoc, consent, customerCookie, adminCookie, seedFixtures, stripeSubscription } =
|
||||
await import('./support/fixtures.js')
|
||||
const { default: portalAdminRoutes } = await import('../server/routes/portalAdmin.js')
|
||||
@@ -77,6 +77,8 @@ beforeEach(async () => {
|
||||
await clearEvents()
|
||||
mails.sent.length = 0
|
||||
seedFixtures(aw)
|
||||
// sub_h wurde von 3 auf 1 Paket verringert; konsoleH haelt bis zum Periodenende noch 3 (offene Aufgabe unten)
|
||||
aw.seed('subscriptions', { ...hostingDoc, storageUnits: 1, storagePaidUnits: 3, storagePaidPeriodEnd: hostingDoc.currentPeriodEnd })
|
||||
aw.seed('subscriptions', { ...hosting2Doc, storageUnits: 2, storagePaidUnits: 2, storagePaidPeriodEnd: hosting2Doc.currentPeriodEnd })
|
||||
st.subscriptions.set('sub_h', stripeSubscription({ id: 'sub_h', customerId: 'c1', productKey: 'hosting' }))
|
||||
st.subscriptions.set('sub_h2', stripeSubscription({ id: 'sub_h2', customerId: 'c2', productKey: 'hosting', storageUnits: 2 }))
|
||||
@@ -85,9 +87,9 @@ beforeEach(async () => {
|
||||
})
|
||||
|
||||
test('Admin: offene Speicher-Aufgaben und vergebene GB', async () => {
|
||||
// zwei aktive Abos: storageUnits 0 und 2 → 5 + 15 = 20 GB
|
||||
// sub_h: 1 Paket, aber 3→1 erst zum Periodenende → konsoleH haelt 5 + 15 = 20 GB; sub_h2: 5 + 10 = 15 GB
|
||||
const r = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
assert.equal(r.allocatedGb, 20)
|
||||
assert.equal(r.allocatedGb, 35)
|
||||
assert.equal(r.packageGb, 50)
|
||||
assert.equal(r.warnGb, 40)
|
||||
assert.equal(r.packageName, 'Webhosting M')
|
||||
@@ -115,13 +117,52 @@ test('Admin: vergebene GB zaehlen nur laufende Abos (active, trialing, past_due)
|
||||
aw.seed('subscriptions', subscriptionDoc('sub_pd', { ...wartungDoc, customerId: 'c3', status: 'past_due', storageUnits: 1 }))
|
||||
try {
|
||||
const r = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
assert.equal(r.allocatedGb, 30)
|
||||
assert.equal(r.allocatedGb, 45)
|
||||
} finally {
|
||||
await deleteDocument(config.collections.subscriptions, 'sub_alt')
|
||||
await deleteDocument(config.collections.subscriptions, 'sub_pd')
|
||||
}
|
||||
})
|
||||
|
||||
test('Admin: belegter Speicher zaehlt die Verringerung erst nach Erledigt', async () => {
|
||||
const before = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
assert.equal(before.allocatedGb, 35, 'offene Aufgabe 3→1: konsoleH haelt noch 20 GB fuer sub_h')
|
||||
const task = before.tasks.find((t) => t.kind === 'periodenende')
|
||||
await post(`/api/portal-admin/storage-tasks/${task.id}/done`, {}, ADMIN)
|
||||
const after = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
assert.equal(after.allocatedGb, 25, 'nach Erledigt: 5 + 5 = 10 GB fuer sub_h, dazu 15 GB fuer sub_h2')
|
||||
})
|
||||
|
||||
test('Admin: Aufgabe nennt Gesamtspeicher des Kunden und Kontakt-Domain', async () => {
|
||||
const { tasks } = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
assert.equal(tasks[0].targetGb, 15)
|
||||
assert.equal(tasks[0].contactDomain, 'example.invalid')
|
||||
assert.equal(tasks[1].targetGb, 10)
|
||||
})
|
||||
|
||||
test('Admin: Erledigt ohne E-Mail des Mitarbeiters wird abgelehnt (400)', async () => {
|
||||
const noEmail = { cookie: sessionCookie({ role: 'admin', appwriteUserId: 'u_admin', name: 'Kenso' }) }
|
||||
const r = await post('/api/portal-admin/storage-tasks/speicher-einrichten-c2/done', {}, noEmail)
|
||||
assert.equal(r.status, 400)
|
||||
assert.equal((await getContractEvent('speicher-einrichten-c2')).status, 'offen')
|
||||
})
|
||||
|
||||
test('Admin: Erledigt auf ein gescheitertes Ereignis → 409', async () => {
|
||||
await storageEvent({ id: 'speicher-gescheitert-x', customerId: 'c1', subscriptionId: 'sub_h', kind: 'einrichten', fromUnits: 0, toUnits: 4, dueAt: iso(-2000), status: 'gescheitert' })
|
||||
const r = await post('/api/portal-admin/storage-tasks/speicher-gescheitert-x/done', {}, ADMIN)
|
||||
assert.equal(r.status, 409)
|
||||
assert.equal((await getContractEvent('speicher-gescheitert-x')).status, 'gescheitert')
|
||||
})
|
||||
|
||||
test('Admin: gescheiterte Aenderungen nur der letzten 30 Tage', async () => {
|
||||
await storageEvent({ id: 'speicher-gescheitert-neu', customerId: 'c1', subscriptionId: 'sub_h', kind: 'einrichten', fromUnits: 0, toUnits: 4, dueAt: iso(-2000), status: 'gescheitert' })
|
||||
await storageEvent({ id: 'speicher-gescheitert-alt', customerId: 'c1', subscriptionId: 'sub_h', kind: 'einrichten', fromUnits: 0, toUnits: 5, dueAt: iso(-2000), status: 'gescheitert' })
|
||||
aw.seed('contractEvents', { ...(await getContractEvent('speicher-gescheitert-alt')), $createdAt: iso(-31 * 24 * HOUR) })
|
||||
aw.seed('contractEvents', { ...(await getContractEvent('speicher-gescheitert-neu')), $createdAt: iso(-29 * 24 * HOUR) })
|
||||
const r = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
assert.deepEqual(r.failed.map((f) => f.id), ['speicher-gescheitert-neu'])
|
||||
})
|
||||
|
||||
test('Admin: Aufgabe erledigen', async () => {
|
||||
const { tasks } = await get('/api/portal-admin/storage-tasks', ADMIN)
|
||||
const { status, body: { task } } = await post(`/api/portal-admin/storage-tasks/${tasks[0].id}/done`, {}, ADMIN)
|
||||
|
||||
Reference in new issue
Block a user