fixing flock conversion

This commit is contained in:
blaisadmin
2026-04-15 22:36:28 -04:00
parent 368ede5619
commit ce2b7a15bf
2 changed files with 46 additions and 8 deletions
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createWorkspace, ensurePersonalWorkspaceForUser } from './workspaceRepository.js';
import { createWorkspace, ensurePersonalWorkspaceForUser, updateWorkspace } from './workspaceRepository.js';
import { mockDb } from '../test/mockDb.js';
import type { UserRow } from '../types.js';
@@ -61,3 +61,37 @@ test('createWorkspace inserts owner membership and returns the created workspace
assert.match(calls[1].text, /INSERT INTO workspace_members/);
assert.match(calls[2].text, /SELECT id, name, workspace_type/);
});
test('updateWorkspace converts an existing household flock to rescue without inserting a new flock', async () => {
const { calls } = mockDb({
rowCount: 1,
rows: [
{
id: 42,
name: 'Converted Rescue',
workspace_type: 'rescue',
billing_email: 'billing@example.com',
billing_plan: 'rescue_free',
subscription_status: 'active',
rescue_verification_status: 'pending',
created_at: '2026-04-14T00:00:00.000Z',
updated_at: '2026-04-15T00:00:00.000Z',
},
],
});
const workspace = await updateWorkspace({
workspaceId: 42,
name: 'Converted Rescue',
workspaceType: 'rescue',
billingEmail: 'billing@example.com',
billingPlan: 'rescue_free',
});
assert.equal(workspace?.id, 42);
assert.equal(workspace?.workspace_type, 'rescue');
assert.equal(calls.length, 1);
assert.match(calls[0].text, /UPDATE workspaces/);
assert.doesNotMatch(calls[0].text, /INSERT INTO workspaces/);
assert.deepEqual(calls[0].params, [42, 'Converted Rescue', 'rescue', 'billing@example.com', 'rescue_free']);
});