44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
import { describe, it, expect, beforeEach } from 'vitest';
|
|
import { resetDb } from '../helpers/db.js';
|
|
import { migrateUp } from '../../lib/db/migrate.js';
|
|
import * as spaces from '../../lib/db/repos/spaces.js';
|
|
|
|
const owner = { kind: 'user', id: null };
|
|
|
|
beforeEach(async () => { await resetDb(); await migrateUp(); });
|
|
|
|
describe('spaces repo', () => {
|
|
it('creates and returns a space', async () => {
|
|
const s = await spaces.create({ slug: 'homelab', name: 'Homelab' }, owner);
|
|
expect(s.id).toBeDefined();
|
|
expect(s.slug).toBe('homelab');
|
|
});
|
|
|
|
it('getBySlug returns the row', async () => {
|
|
await spaces.create({ slug: 'a', name: 'A' }, owner);
|
|
const got = await spaces.getBySlug('a');
|
|
expect(got.name).toBe('A');
|
|
});
|
|
|
|
it('list returns all', async () => {
|
|
await spaces.create({ slug: 'a', name: 'A' }, owner);
|
|
await spaces.create({ slug: 'b', name: 'B' }, owner);
|
|
const all = await spaces.list();
|
|
expect(all).toHaveLength(2);
|
|
});
|
|
|
|
it('update changes fields and bumps updated_at', async () => {
|
|
const s = await spaces.create({ slug: 'a', name: 'A' }, owner);
|
|
const u = await spaces.update(s.id, { name: 'Renamed' }, owner);
|
|
expect(u.name).toBe('Renamed');
|
|
expect(new Date(u.updated_at).getTime())
|
|
.toBeGreaterThanOrEqual(new Date(s.updated_at).getTime());
|
|
});
|
|
|
|
it('del removes the row', async () => {
|
|
const s = await spaces.create({ slug: 'a', name: 'A' }, owner);
|
|
await spaces.del(s.id, owner);
|
|
expect(await spaces.getBySlug('a')).toBeUndefined();
|
|
});
|
|
});
|