/* * 원본에만 있는 관계를 화면에 낼 수 있는지 판정하는 부분. * * 조회 자체는 DB 와 어댑터를 물어야 돌아가므로 테스트가 다루지 않는다. 여기서 확인하는 것은 * 원본이 준 값을 그대로 믿지 않는다는 것이다. */ import { test } from 'node:test' import assert from 'node:assert/strict' import { usableLinkGroups } from '../server/service/reference/reference-link-groups.js' test('정상 그룹은 그대로 남는다', () => { const got = usableLinkGroups([ { via: 'mes.rel.report', from: 'productionReports', tense: 'past', ids: ['PR-1'], total: 2 } ]) assert.equal(got.length, 1) assert.equal(got[0].tense, 'past') }) test('★ 전체 수가 없는 그룹은 버린다 — 화면이 목록 길이를 전체 수로 쓰게 된다', () => { /* * 원본이 20개만 보내고 전체 수를 빼면, 실제 200건이 화면에 20건으로 표시된다. 오류가 나지 * 않으므로 아무도 알아채지 못한다. */ const got = usableLinkGroups([{ via: 'mes.rel.report', from: 'x', ids: ['a', 'b'] } as any]) assert.equal(got.length, 0) }) test('전체 수가 0 인 그룹은 버린다 — 원본이 그 축을 취급하지 않는다는 뜻이다', () => { assert.equal(usableLinkGroups([{ via: 'v', from: 'f', ids: [], total: 0 }]).length, 0) }) test('이름이 없는 그룹은 버린다 — 화면에 이름 없는 줄이 된다', () => { const got = usableLinkGroups([ { via: '', from: 'f', ids: ['a'], total: 1 }, { via: ' ', from: 'f', ids: ['a'], total: 1 }, { from: 'f', ids: ['a'], total: 1 } as any ]) assert.equal(got.length, 0) }) test('원본이 아무것도 안 주거나 목록에 빈 값이 섞여도 견딘다', () => { assert.deepEqual(usableLinkGroups(undefined), []) assert.deepEqual(usableLinkGroups(null), []) assert.equal(usableLinkGroups([null as any, undefined as any]).length, 0) }) test('★ 이 테스트가 실제로 무언가를 확인한다 — 통과와 탈락이 둘 다 있어야 한다', () => { const got = usableLinkGroups([ { via: 'ok', from: 'f', ids: ['a'], total: 1 }, { via: 'no-total', from: 'f', ids: ['a'] } as any, { via: '', from: 'f', ids: ['a'], total: 5 } ]) assert.equal(got.length, 1, '통과한 것이 하나여야 한다') assert.equal(got[0].via, 'ok') })