fixing rescue settings
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { createWorkspace, ensurePersonalWorkspaceForUser, updateWorkspace } from './workspaceRepository.js';
|
||||
import { createWorkspace, deleteWorkspaceIfEmpty, ensurePersonalWorkspaceForUser, findAlternateWorkspaceForUser, updateWorkspace } from './workspaceRepository.js';
|
||||
import { mockDb } from '../test/mockDb.js';
|
||||
import type { UserRow } from '../types.js';
|
||||
|
||||
@@ -95,3 +95,49 @@ test('updateWorkspace converts an existing household flock to rescue without ins
|
||||
assert.doesNotMatch(calls[0].text, /INSERT INTO workspaces/);
|
||||
assert.deepEqual(calls[0].params, [42, 'Converted Rescue', 'rescue', 'billing@example.com', 'rescue_free']);
|
||||
});
|
||||
|
||||
test('deleteWorkspaceIfEmpty blocks deletion when birds are still assigned', async () => {
|
||||
const { calls } = mockDb(
|
||||
{
|
||||
rowCount: 1,
|
||||
rows: [{ count: '2' }],
|
||||
},
|
||||
);
|
||||
|
||||
const result = await deleteWorkspaceIfEmpty(42);
|
||||
|
||||
assert.deepEqual(result, { deleted: false, reason: 'birds_present' });
|
||||
assert.equal(calls.length, 1);
|
||||
assert.match(calls[0].text, /FROM birds/);
|
||||
});
|
||||
|
||||
test('deleteWorkspaceIfEmpty deletes an empty workspace', async () => {
|
||||
const { calls } = mockDb(
|
||||
{
|
||||
rowCount: 1,
|
||||
rows: [{ count: '0' }],
|
||||
},
|
||||
{
|
||||
rowCount: 1,
|
||||
rows: [{ id: 42 }],
|
||||
},
|
||||
);
|
||||
|
||||
const result = await deleteWorkspaceIfEmpty(42);
|
||||
|
||||
assert.deepEqual(result, { deleted: true });
|
||||
assert.equal(calls.length, 2);
|
||||
assert.match(calls[1].text, /DELETE FROM workspaces/);
|
||||
});
|
||||
|
||||
test('findAlternateWorkspaceForUser returns another workspace when available', async () => {
|
||||
const { calls } = mockDb({
|
||||
rowCount: 1,
|
||||
rows: [{ workspace_id: 84 }],
|
||||
});
|
||||
|
||||
const workspaceId = await findAlternateWorkspaceForUser('user-1', 42);
|
||||
|
||||
assert.equal(workspaceId, 84);
|
||||
assert.deepEqual(calls[0].params, ['user-1', 42]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user