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 assert from 'node:assert/strict';
import test from 'node:test'; 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 { mockDb } from '../test/mockDb.js';
import type { UserRow } from '../types.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[1].text, /INSERT INTO workspace_members/);
assert.match(calls[2].text, /SELECT id, name, workspace_type/); 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']);
});
+11 -7
View File
@@ -3174,10 +3174,10 @@ function App() {
</label> </label>
{workspace?.workspaceType === 'standard' && workspaceForm.workspaceType === 'rescue' ? ( {workspace?.workspaceType === 'standard' && workspaceForm.workspaceType === 'rescue' ? (
<article className="summary-card summary-alert-card"> <article className="summary-card summary-alert-card">
<strong>Approval required before edits continue</strong> <strong>This converts the current flock</strong>
<span> <span>
Changing this household flock to a rescue flock will make it read-only until FlockPal approves the rescue verification. Saving here updates this household flock into a rescue flock. It does not create a separate flock space. The flock will be
Monitor the email address used to sign up for any follow-up details needed to approve rescue status. read-only until FlockPal approves rescue verification.
</span> </span>
</article> </article>
) : null} ) : null}
@@ -3220,7 +3220,11 @@ function App() {
/> />
</label> </label>
<button className="primary-button" type="submit" disabled={savingWorkspace}> <button className="primary-button" type="submit" disabled={savingWorkspace}>
{savingWorkspace ? 'Saving flock...' : 'Save flock settings'} {savingWorkspace
? 'Saving flock...'
: workspace?.workspaceType === 'standard' && workspaceForm.workspaceType === 'rescue'
? 'Convert current flock to rescue'
: 'Save flock settings'}
</button> </button>
</form> </form>
</article> </article>
@@ -3480,7 +3484,7 @@ function App() {
<article className="panel form-panel"> <article className="panel form-panel">
<div className="panel-header"> <div className="panel-header">
<div> <div>
<p className="eyebrow">New flock</p> <p className="eyebrow">Separate flock</p>
<h2>Add another flock space</h2> <h2>Add another flock space</h2>
</div> </div>
<button <button
@@ -3497,8 +3501,8 @@ function App() {
{expandedSettingsSection === 'new-workspace' ? ( {expandedSettingsSection === 'new-workspace' ? (
<> <>
<p className="muted"> <p className="muted">
This is the key piece for someone who helps with a rescue but also keeps their own birds at home. Each flock stays separate Use this only when you need a separate flock. To turn the current household flock into a rescue, use Flock profile and
for access and billing. billing above instead.
</p> </p>
<form className="form-panel" onSubmit={handleCreateWorkspace}> <form className="form-panel" onSubmit={handleCreateWorkspace}>
<label> <label>