const test = require('node:test'); const assert = require('node:assert/strict'); const { createQrCodeSvg, buildQrCodeContent } = require('../src/data/qr-code'); const { buildSlidePayload } = require('../src/data/slides'); test('createQrCodeSvg renders a qr svg for non-empty values', async () => { const svg = await createQrCodeSvg('https://example.com'); assert.equal(typeof svg, 'string'); assert.match(svg, /^]/); }); test('buildQrCodeContent stores qr svg content for qr-code regions', async () => { const content = await buildQrCodeContent('https://example.com'); assert.equal(content.type, 'qr-code'); assert.equal(content.value, 'https://example.com'); assert.equal(typeof content.qr_svg, 'string'); assert.match(content.qr_svg, /^]/); }); test('buildSlidePayload stores qr-code slide content from the submitted url', async () => { const pool = { async query(sql) { if (sql.includes('FROM c_templates st')) { return [[{ id: 7, name: 'Template 7', canvas_size_id: 1, canvas_size_width: 1920, canvas_size_height: 1080 }]]; } if (sql.includes('FROM c_template_regions')) { return [[{ id: 22, template_id: 7, region_key: 'qrRegion', region_type: 'qr-code', label: 'QR' }]]; } return [[]]; } }; const payload = await buildSlidePayload(pool, { body: { title: 'QR Slide', template_id: '7', region_qr_code_22: 'https://example.com' }, files: [] }, null); const content = JSON.parse(payload.contentJson); assert.equal(content.qrRegion.type, 'qr-code'); assert.equal(content.qrRegion.value, 'https://example.com'); assert.equal(typeof content.qrRegion.qr_svg, 'string'); assert.match(content.qrRegion.qr_svg, /^]/); });