fixed adding new workspace at login

This commit is contained in:
blaisadmin
2026-05-21 13:10:34 -04:00
parent e6211d7f5e
commit 62afc94f2f
3 changed files with 69 additions and 2 deletions
@@ -4,6 +4,7 @@ import test from 'node:test';
import {
createWorkspace,
deleteWorkspaceIfEmpty,
ensureDefaultWorkspaceForUser,
ensurePersonalWorkspaceForUser,
findAlternateWorkspaceForUser,
getPlatformAdminSummary,
@@ -64,6 +65,53 @@ test('ensurePersonalWorkspaceForUser creates a fresh workspace instead of claimi
assert.deepEqual(calls[2].params, [43, "Owner's Flock", 'owner@example.com']);
});
test('ensureDefaultWorkspaceForUser reuses an existing rescue workspace without creating a household flock', async () => {
const { calls } = mockDb({
rowCount: 1,
rows: [{ workspace_id: 84 }],
});
const workspaceId = await ensureDefaultWorkspaceForUser(user);
assert.equal(workspaceId, 84);
assert.equal(calls.length, 1);
assert.match(calls[0].text, /FROM workspace_members/);
assert.doesNotMatch(calls[0].text, /workspaces\.workspace_type = 'standard'/);
});
test('ensureDefaultWorkspaceForUser creates a household flock when the user has no workspace', async () => {
const { calls } = mockDb(
{
rowCount: 0,
rows: [],
},
{
rowCount: 0,
rows: [],
},
{
rowCount: 1,
rows: [{ next_id: 43 }],
},
{
rowCount: 1,
rows: [],
},
{
rowCount: 1,
rows: [],
},
);
const workspaceId = await ensureDefaultWorkspaceForUser(user);
assert.equal(workspaceId, 43);
assert.equal(calls.length, 5);
assert.match(calls[0].text, /FROM workspace_members/);
assert.match(calls[1].text, /workspaces\.workspace_type = 'standard'/);
assert.match(calls[3].text, /INSERT INTO workspaces/);
});
test('createWorkspace inserts owner membership and returns the created workspace', async () => {
const { calls } = mockDb(
{ rowCount: 1, rows: [] },