From ce2b7a15bf90be342bd9bfc4feff8e505b8ae356 Mon Sep 17 00:00:00 2001 From: blaisadmin Date: Wed, 15 Apr 2026 22:36:28 -0400 Subject: [PATCH] fixing flock conversion --- .../repositories/workspaceRepository.test.ts | 36 ++++++++++++++++++- frontend/src/App.tsx | 18 ++++++---- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/backend/src/repositories/workspaceRepository.test.ts b/backend/src/repositories/workspaceRepository.test.ts index 092e8fc..84cf91b 100644 --- a/backend/src/repositories/workspaceRepository.test.ts +++ b/backend/src/repositories/workspaceRepository.test.ts @@ -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']); +}); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 2334382..cad3109 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -3174,10 +3174,10 @@ function App() { {workspace?.workspaceType === 'standard' && workspaceForm.workspaceType === 'rescue' ? (
- Approval required before edits continue + This converts the current flock - Changing this household flock to a rescue flock will make it read-only until FlockPal approves the rescue verification. - Monitor the email address used to sign up for any follow-up details needed to approve rescue status. + Saving here updates this household flock into a rescue flock. It does not create a separate flock space. The flock will be + read-only until FlockPal approves rescue verification.
) : null} @@ -3220,7 +3220,11 @@ function App() { /> @@ -3480,7 +3484,7 @@ function App() {
-

New flock

+

Separate flock

Add another flock space