Admin: News je Projekt aktivieren und abschalten
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a421308019
commit
6dac6aa073
6 files changed
+361
-9
No files matched your search
@@ -12,15 +12,23 @@ 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, postWebhook } = await import('./support/testApp.js')
|
||||
const { customerCookie, seedFixtures } = await import('./support/fixtures.js')
|
||||
const { startTestApp, get, rawGet, post, postWebhook } = await import('./support/testApp.js')
|
||||
const { adminCookie, customerCookie, seedFixtures } = await import('./support/fixtures.js')
|
||||
const { default: funktionenRoutes } = await import('../server/routes/funktionen.js')
|
||||
const { default: aboRoutes } = await import('../server/routes/abo.js')
|
||||
const { default: portalAdminRoutes } = await import('../server/routes/portalAdmin.js')
|
||||
const { default: publicNewsRoutes } = await import('../server/routes/publicNews.js')
|
||||
const sf = await import('../server/services/siteFeatures.js')
|
||||
const { deleteDocument } = await import('../server/services/appwriteAdmin.js')
|
||||
const { setMailTransportForTests } = await import('../server/services/mailer.js')
|
||||
const { mailSink } = await import('./support/mailSink.js')
|
||||
|
||||
const app = await startTestApp({ '/api/funktionen': funktionenRoutes, '/api/abo': aboRoutes })
|
||||
const app = await startTestApp({
|
||||
'/api/funktionen': funktionenRoutes,
|
||||
'/api/abo': aboRoutes,
|
||||
'/api/portal-admin': portalAdminRoutes,
|
||||
'/api/public/news': publicNewsRoutes,
|
||||
})
|
||||
const mails = mailSink()
|
||||
setMailTransportForTests(mails)
|
||||
after(() => {
|
||||
@@ -213,3 +221,81 @@ test('parallele_aktivierung_mailt_einmal', async () => {
|
||||
assert.equal(a.length + b.length, 1)
|
||||
assert.equal(mails.sent.slice(mailsBefore).filter((m) => m.subject === 'Deine News-Pinnwand ist bereit').length, 1)
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------- Admin ---
|
||||
const adminC = adminCookie()
|
||||
const adminPost = (customerId, body, cookie = adminC) => post(`/api/portal-admin/funktionen/${customerId}/news`, body, { cookie })
|
||||
|
||||
test('admin_aktivieren_ohne_zahlung', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'pa1', customerId: 'c1', projectName: 'Admin-Test' })
|
||||
const wosBefore = workorders().length
|
||||
const res = await adminPost('c1', { projectId: 'pa1', action: 'activate', note: 'Kulanz' })
|
||||
assert.equal(res.status, 200)
|
||||
const view = res.body.projects.find((p) => p.projectId === 'pa1').features.news
|
||||
assert.equal(view.state, 'active')
|
||||
assert.equal(view.ticketWoid, null)
|
||||
assert.match(view.adminNote, /^\d{4}-\d\d-\d\dT[\d:.]+Z Kenso: activate – Kulanz$/)
|
||||
const doc = await sf.getFeatureDoc('c1', 'pa1', 'news')
|
||||
assert.equal(doc.enabled, true)
|
||||
assert.equal(doc.unlockedByPurchase, false)
|
||||
assert.equal(workorders().length, wosBefore)
|
||||
const list = await get('/api/portal-admin/funktionen/c1', { cookie: adminC })
|
||||
assert.equal(list.projects.find((p) => p.projectId === 'pa1').features.news.state, 'active')
|
||||
})
|
||||
|
||||
test('admin_abschalten', async () => {
|
||||
const doc = await sf.getFeatureDoc('c1', 'pa1', 'news')
|
||||
const publicUrl = `/api/public/news/${doc.siteKey}`
|
||||
assert.equal((await rawGet(publicUrl)).status, 200)
|
||||
const res = await adminPost('c1', { projectId: 'pa1', action: 'disable' })
|
||||
assert.equal(res.status, 200)
|
||||
const view = res.body.projects[0].features.news
|
||||
assert.equal(view.state, 'disabled')
|
||||
assert.match(view.adminNote, /Kenso: disable \| .*Kenso: activate – Kulanz$/)
|
||||
assert.ok(view.adminNote.length <= 300)
|
||||
assert.equal((await sf.getFeatureDoc('c1', 'pa1', 'news')).enabled, false)
|
||||
const { status, body } = await rawGet(publicUrl)
|
||||
assert.ok(status === 404 || (status === 200 && (body.posts || []).length === 0), `öffentlich: ${status}`)
|
||||
})
|
||||
|
||||
test('admin_ungueltig_und_fremd', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'pa4', customerId: 'c1', projectName: 'Ohne Dokument' })
|
||||
assert.equal((await adminPost('c1', { projectId: 'pa1', action: 'loeschen' })).status, 400)
|
||||
assert.equal((await adminPost('c1', { projectId: 'p5', action: 'activate' })).status, 403)
|
||||
assert.equal((await adminPost('c1', { projectId: 'gibtsnicht', action: 'activate' })).status, 403)
|
||||
assert.equal((await adminPost('c1', { projectId: 'pa4', action: 'disable' })).status, 409)
|
||||
})
|
||||
|
||||
test('admin_notiz_bleibt_im_limit', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'pa2', customerId: 'c1', projectName: 'Notiz' })
|
||||
for (let i = 0; i < 8; i += 1) {
|
||||
await adminPost('c1', { projectId: 'pa2', action: i % 2 ? 'disable' : 'activate', note: 'x'.repeat(100) })
|
||||
}
|
||||
const note = (await sf.getFeatureDoc('c1', 'pa2', 'news')).adminNote
|
||||
assert.ok(note.length <= 300)
|
||||
assert.match(note, /^\S+ Kenso: disable – x+/)
|
||||
})
|
||||
|
||||
test('kunde_darf_admin_route_nicht', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'pa5', customerId: 'c1', projectName: 'Kundenversuch' })
|
||||
const res = await adminPost('c1', { projectId: 'pa5', action: 'activate' }, customerCookie('c1'))
|
||||
assert.ok(res.status === 401 || res.status === 403)
|
||||
assert.equal(await sf.getFeatureDoc('c1', 'pa5', 'news'), null)
|
||||
const list = await rawGet('/api/portal-admin/funktionen/c1', { cookie: customerCookie('c1') })
|
||||
assert.ok(list.status === 401 || list.status === 403)
|
||||
})
|
||||
|
||||
test('ticket_fehlt_markiert', async () => {
|
||||
aw.seed('websiteProjects', { $id: 'pa3', customerId: 'c1', projectName: 'Ticketlos' })
|
||||
await checkout('pa3')
|
||||
await postWebhook(event('checkout.session.completed', paidSession(sessions().at(-1).id, 'pa3')))
|
||||
const doc = await sf.getFeatureDoc('c1', 'pa3', 'news')
|
||||
assert.equal(doc.state, 'setup')
|
||||
const newsOf = async () =>
|
||||
(await get('/api/portal-admin/funktionen/c1', { cookie: adminC })).projects.find((p) => p.projectId === 'pa3').features.news
|
||||
assert.equal((await newsOf()).ticketMissing, false)
|
||||
await deleteDocument(config.collections.workorders, doc.ticketId)
|
||||
const missing = await newsOf()
|
||||
assert.equal(missing.ticketMissing, true)
|
||||
assert.equal(missing.ticketWoid, null)
|
||||
})
|
||||
Reference in new issue
Block a user