56 lines
1.7 KiB
JavaScript
56 lines
1.7 KiB
JavaScript
import { test } from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { ANALYSE_ATTRIBUTES, main } from '../scripts/analyse-setup.mjs'
|
|
import { config } from '../server/config.js'
|
|
|
|
function mockClient(existing = []) {
|
|
const created = []
|
|
return {
|
|
created,
|
|
async listAttributes() {
|
|
return existing.map((key) => ({ key }))
|
|
},
|
|
async createAttribute(attr) {
|
|
created.push(attr.key)
|
|
},
|
|
async waitForAttribute() {},
|
|
}
|
|
}
|
|
|
|
test('Schema: 7 Attribute mit Groessen, alle optional', () => {
|
|
const sizes = Object.fromEntries(ANALYSE_ATTRIBUTES.map((a) => [a.key, a.size]))
|
|
assert.deepEqual(sizes, {
|
|
accentColor: 7,
|
|
avvVersion: 20,
|
|
avvAcceptedAt: 40,
|
|
avvAcceptedBy: 100,
|
|
activatedAt: 40,
|
|
offSince: 40,
|
|
privacyTicketId: 40,
|
|
})
|
|
assert.ok(ANALYSE_ATTRIBUTES.every((a) => a.required === false && a.type === 'string'))
|
|
})
|
|
|
|
test('main legt nur fehlende Attribute an', async () => {
|
|
const client = mockClient(['accentColor'])
|
|
const result = await main({ client, log: () => {} })
|
|
assert.equal(client.created.length, 6)
|
|
assert.ok(!client.created.includes('accentColor'))
|
|
assert.equal(result.missing.length, 6)
|
|
})
|
|
|
|
test('main --check legt nichts an', async () => {
|
|
const client = mockClient(['accentColor'])
|
|
const result = await main({ check: true, client, log: () => {} })
|
|
assert.equal(client.created.length, 0)
|
|
assert.equal(result.missing.length, 6)
|
|
})
|
|
|
|
test('Konfiguration: analyse ist standardmaessig aus', () => {
|
|
assert.equal(config.analyse.enabled, false)
|
|
assert.equal(config.analyse.url, 'http://webklar-analytics:8091')
|
|
assert.equal(config.analyse.adminToken, '')
|
|
assert.equal(config.analyse.heatSecret, '')
|
|
assert.equal(config.analyse.avvVersion, '2026-10-01')
|
|
})
|