|
4 | 4 | import { test, before, after } from 'node:test'; |
5 | 5 | import assert from 'node:assert/strict'; |
6 | 6 | import { api, get, post, put, list, track, cleanup, ensureProject, waitFor, waitRun } from '../lib/api.mjs'; |
7 | | -import { cfg } from '../lib/env.mjs'; |
| 7 | +import { cfg, requireToken } from '../lib/env.mjs'; |
8 | 8 | import { createWorkflow, script, approval, trackRun } from '../lib/fixtures.mjs'; |
9 | 9 |
|
10 | 10 | const P = cfg.projectId; |
@@ -52,6 +52,33 @@ test('list supports project filter, search and pagination', async () => { |
52 | 52 |
|
53 | 53 | const detailOf = async id => get(`/api/issues/${id}`); |
54 | 54 |
|
| 55 | +test('creates a Markdown requirement and serves its attached image to authenticated users', async () => { |
| 56 | + const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVR4nGPQc/8PAAIbAXVXkdKiAAAAAElFTkSuQmCC', 'base64'); |
| 57 | + const description = '## Reproduction\n\nSee the **attached image**.'; |
| 58 | + const form = new FormData(); |
| 59 | + form.set('issue', JSON.stringify({ projectId: P, kind: 'requirement', title: `E2E requirement image ${cfg.runTag}`, description })); |
| 60 | + form.append('images', new Blob([png], { type: 'image/png' }), 'reproduction.png'); |
| 61 | + |
| 62 | + const created = await post('/api/issues', form); |
| 63 | + removeLater(created.id); |
| 64 | + const detail = await detailOf(created.id); |
| 65 | + assert.equal(detail.issue.description, description); |
| 66 | + assert.equal(detail.images.length, 1); |
| 67 | + const [image] = detail.images; |
| 68 | + assert.ok(image.id); |
| 69 | + assert.equal(image.name, 'reproduction.png'); |
| 70 | + |
| 71 | + const path = `/api/issues/${created.id}/images/${image.id}`; |
| 72 | + await get(path, { auth: false, expect: 401 }); |
| 73 | + const response = await fetch(cfg.base + path, { |
| 74 | + headers: { Authorization: `Bearer ${requireToken()}` }, |
| 75 | + signal: AbortSignal.timeout(15_000), |
| 76 | + }); |
| 77 | + assert.equal(response.status, 200); |
| 78 | + assert.equal(response.headers.get('content-type'), 'image/png'); |
| 79 | + assert.deepEqual(Buffer.from(await response.arrayBuffer()), png); |
| 80 | +}); |
| 81 | + |
55 | 82 | test('edit keeps identity and records an operation', async () => { |
56 | 83 | const { issue: current } = await detailOf(issue.id); |
57 | 84 | const saved = await put('/api/issues', { ...current, title: `${current.title}(已编辑)`, priority: 'high' }); |
|
0 commit comments