fixing flock conversion
This commit is contained in:
@@ -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']);
|
||||
});
|
||||
|
||||
+11
-7
@@ -3174,10 +3174,10 @@ function App() {
|
||||
</label>
|
||||
{workspace?.workspaceType === 'standard' && workspaceForm.workspaceType === 'rescue' ? (
|
||||
<article className="summary-card summary-alert-card">
|
||||
<strong>Approval required before edits continue</strong>
|
||||
<strong>This converts the current flock</strong>
|
||||
<span>
|
||||
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.
|
||||
</span>
|
||||
</article>
|
||||
) : null}
|
||||
@@ -3220,7 +3220,11 @@ function App() {
|
||||
/>
|
||||
</label>
|
||||
<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>
|
||||
</form>
|
||||
</article>
|
||||
@@ -3480,7 +3484,7 @@ function App() {
|
||||
<article className="panel form-panel">
|
||||
<div className="panel-header">
|
||||
<div>
|
||||
<p className="eyebrow">New flock</p>
|
||||
<p className="eyebrow">Separate flock</p>
|
||||
<h2>Add another flock space</h2>
|
||||
</div>
|
||||
<button
|
||||
@@ -3497,8 +3501,8 @@ function App() {
|
||||
{expandedSettingsSection === 'new-workspace' ? (
|
||||
<>
|
||||
<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
|
||||
for access and billing.
|
||||
Use this only when you need a separate flock. To turn the current household flock into a rescue, use Flock profile and
|
||||
billing above instead.
|
||||
</p>
|
||||
<form className="form-panel" onSubmit={handleCreateWorkspace}>
|
||||
<label>
|
||||
|
||||
Reference in New Issue
Block a user