63 lines
2.5 KiB
JavaScript
63 lines
2.5 KiB
JavaScript
import { test, before, after } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import express from 'express'
|
|
import { startFakeAppwrite } from './helpers/fakeAppwrite.js'
|
|
|
|
let aw
|
|
let server
|
|
let baseUrl
|
|
|
|
before(async () => {
|
|
aw = await startFakeAppwrite({
|
|
seed: {
|
|
websiteProjects: [
|
|
{ $id: 'p1', projectName: 'Doener', repoFullName: 'JUSN/doener', customerId: 'c1', ticketId: 't1', subdomain: 'doener', kind: 'website' },
|
|
{ $id: 'p2', projectName: 'Ohne Art', repoFullName: 'JUSN/ohne', customerId: '', ticketId: '', liveDomain: 'ohne.de', subdomain: 'ohne' },
|
|
{ $id: 'p3', projectName: 'Alt', repoFullName: 'JUSN/alt', kind: 'website', archived: true },
|
|
{ $id: 'p4', projectName: 'Vorlage', repoFullName: 'JUSN/tpl', kind: 'website', isTemplate: true },
|
|
],
|
|
workorders: [{ $id: 't1', woid: '100115', customerId: 'c1', status: 'Open' }],
|
|
customers: [{ $id: 'c1', name: 'Döner Nation' }],
|
|
},
|
|
})
|
|
Object.assign(process.env, { APPWRITE_ENDPOINT: aw.endpoint, APPWRITE_API_KEY: 'test-key' })
|
|
const { default: routes } = await import('../server/routes/admin/services.js')
|
|
const app = express()
|
|
app.use('/api/admin/services', routes)
|
|
server = await new Promise((resolve) => {
|
|
const s = app.listen(0, '127.0.0.1', () => resolve(s))
|
|
})
|
|
baseUrl = `http://127.0.0.1:${server.address().port}`
|
|
})
|
|
|
|
after(async () => {
|
|
await new Promise((resolve) => server.close(resolve))
|
|
await aw.close()
|
|
})
|
|
|
|
const get = (jwt) =>
|
|
fetch(`${baseUrl}/api/admin/services`, { headers: jwt ? { Authorization: `Bearer ${jwt}` } : {} })
|
|
|
|
test('ohne Staff-JWT ⇒ 401', async () => {
|
|
assert.equal((await get()).status, 401)
|
|
})
|
|
|
|
test('Katalog + Gruppen, Archiv/Vorlage ausgeschlossen, Namen aufgelöst', async () => {
|
|
const r = await get('jwt-admin')
|
|
assert.equal(r.status, 200)
|
|
const body = await r.json()
|
|
assert.equal(body.kinds.length, 6)
|
|
assert.equal(body.features.analyse.label, 'Website-Analyse')
|
|
assert.equal(body.groups.website.length, 1)
|
|
assert.equal(body.groups.missing.length, 1)
|
|
assert.deepEqual(body.groups.website[0], {
|
|
id: 'p1', projectName: 'Doener', repoFullName: 'JUSN/doener', customerId: 'c1',
|
|
customerName: 'Döner Nation', ticketId: 't1', woid: '100115',
|
|
previewUrl: 'https://doener.project.webklar.com', previewState: '', features: {},
|
|
})
|
|
assert.equal(body.groups.missing[0].previewUrl, 'https://ohne.de')
|
|
assert.equal(body.groups.missing[0].customerName, '')
|
|
const all = Object.values(body.groups).flat().map((p) => p.id)
|
|
assert.ok(!all.includes('p3') && !all.includes('p4'))
|
|
})
|