/** "업데이트 내용이 있습니다" (docs/07 §11.1): the server tells which web build it serves. */ import { afterEach, expect, test } from 'bun:test'; import { mkdtempSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { webBuildId } from './server'; import { Client, api, boot, guest } from './test-utils'; const running: ReturnType[] = []; const clients: Client[] = []; afterEach(async () => { for (const c of clients.splice(0)) c.close(); for (const s of running.splice(0)) await s.stop(); }); function webDir(html: string): string { const dir = mkdtempSync(join(process.env.TMPDIR ?? tmpdir(), 'bg-web-')); writeFileSync(join(dir, 'index.html'), html); return dir; } test('the build id comes from the meta tag of the served index.html', () => { expect(webBuildId(webDir(''))).toBe('abc123def456'); expect(webBuildId(webDir(''))).toBeNull(); expect(webBuildId('/nonexistent/dir')).toBeNull(); }); test('/api/version and the socket welcome carry the build', async () => { const s = boot(undefined, { staticDir: webDir('') }); running.push(s); const r = await api(s.base, '/api/version'); expect(r.res.headers.get('cache-control')).toBe('no-store'); expect(r.body).toEqual({ build: '0123456789ab' }); const g = await guest(s.base, '버전확인'); const c = await new Client(s.base, g.cookie, g.id).connect(); clients.push(c); expect(c.lastOf('welcome')!.build).toBe('0123456789ab'); }); test('without a web build (dev, tests) there is nothing to compare', async () => { const s = boot(); running.push(s); expect((await api(s.base, '/api/version')).body).toEqual({ build: null }); });