27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import * as attachments from '../../lib/db/repos/attachments.js';
|
|
|
|
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
describe('attachments repo', () => {
|
|
it('records an attachment', async () => {
|
|
const a = await attachments.create({
|
|
entity_type: 'page',
|
|
entity_id: '11111111-1111-1111-1111-111111111111',
|
|
filename: 'spec.pdf', mime_type: 'application/pdf',
|
|
size_bytes: 1024, blob_path: 'aa/abc', checksum: 'abc'
|
|
});
|
|
expect(a.filename).toBe('spec.pdf');
|
|
});
|
|
|
|
it('listForEntity returns descending by uploaded_at', async () => {
|
|
const eid = '11111111-1111-1111-1111-111111111111';
|
|
await attachments.create({ entity_type: 'page', entity_id: eid, filename: 'a', blob_path: 'a' });
|
|
await attachments.create({ entity_type: 'page', entity_id: eid, filename: 'b', blob_path: 'b' });
|
|
const list = await attachments.listForEntity('page', eid);
|
|
expect(list).toHaveLength(2);
|
|
});
|
|
});
|