import { test } from 'node:test' import assert from 'node:assert/strict' import { PROJECT_KIND_ATTRIBUTES, main } from '../scripts/projektarten-setup.mjs' 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: genau die 8 Attribute, alle optional', () => { assert.deepEqual( PROJECT_KIND_ATTRIBUTES.map((a) => a.key), ['kind', 'forCustomer', 'kindSetBy', 'kindSetAt', 'createdByGitea', 'assignMailSentAt', 'assignReminderSentAt', 'assignMailAttempts'] ) assert.ok(PROJECT_KIND_ATTRIBUTES.every((a) => a.required === false)) const byKey = Object.fromEntries(PROJECT_KIND_ATTRIBUTES.map((a) => [a.key, a])) assert.equal(byKey.kind.size, 20) assert.equal(byKey.kindSetBy.size, 64) assert.equal(byKey.createdByGitea.size, 64) assert.equal(byKey.kindSetAt.size, 40) assert.equal(byKey.forCustomer.type, 'boolean') assert.equal(byKey.assignMailAttempts.type, 'integer') }) test('main legt nur fehlende Attribute an (kind existiert schon)', async () => { const client = mockClient(['kind']) const result = await main({ check: false, client, log: () => {} }) assert.equal(client.created.length, 7) assert.ok(!client.created.includes('kind')) assert.deepEqual(result.missing.length, 7) }) test('main --check legt nichts an und meldet Fehlende', async () => { const client = mockClient(['kind']) const result = await main({ check: true, client, log: () => {} }) assert.equal(client.created.length, 0) assert.equal(result.missing.length, 7) })