From 4a85dcfcffa27897fc065e6cedea6e514baf9f5a Mon Sep 17 00:00:00 2001 From: g-but <41178744+g-but@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:28:14 +0100 Subject: [PATCH] orangecat: add unit coverage for project/product/cause create workflows --- .../domain/entity-create-workflows.test.ts | 109 ++++++++++++++++++ ...AT_ENTITY_WORKFLOW_CHECKLIST_2026-02-18.md | 8 +- 2 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 __tests__/unit/domain/entity-create-workflows.test.ts diff --git a/__tests__/unit/domain/entity-create-workflows.test.ts b/__tests__/unit/domain/entity-create-workflows.test.ts new file mode 100644 index 000000000..d2e4015df --- /dev/null +++ b/__tests__/unit/domain/entity-create-workflows.test.ts @@ -0,0 +1,109 @@ +import { createProject } from '@/domain/projects/service'; +import { createProduct, createCause } from '@/domain/commerce/service'; + +jest.mock('@/lib/supabase/server', () => ({ + createServerClient: jest.fn(), +})); + +jest.mock('@/lib/supabase/admin', () => ({ + createAdminClient: jest.fn(), +})); + +import { createServerClient } from '@/lib/supabase/server'; +import { createAdminClient } from '@/lib/supabase/admin'; + +describe('Entity create workflows (project/product/cause)', () => { + const mockServerChain = { + insert: jest.fn().mockReturnThis(), + select: jest.fn().mockReturnThis(), + single: jest.fn(), + }; + + const mockAdminChain = { + insert: jest.fn().mockReturnThis(), + select: jest.fn().mockReturnThis(), + single: jest.fn(), + }; + + const mockServerClient = { + from: jest.fn(() => mockServerChain), + }; + + const mockAdminClient = { + from: jest.fn(() => mockAdminChain), + }; + + beforeEach(() => { + jest.clearAllMocks(); + (createServerClient as jest.Mock).mockResolvedValue(mockServerClient); + (createAdminClient as jest.Mock).mockReturnValue(mockAdminClient); + }); + + it('creates a project with draft defaults and SATS currency fallback', async () => { + const created = { id: 'proj-1', title: 'P', status: 'draft' }; + mockServerChain.single.mockResolvedValue({ data: created, error: null }); + + const result = await createProject('user-1', { + title: 'P', + description: 'project desc', + category: 'technology', + }); + + expect(mockServerClient.from).toHaveBeenCalledWith('projects'); + expect(mockServerChain.insert).toHaveBeenCalledWith( + expect.objectContaining({ + user_id: 'user-1', + title: 'P', + status: 'draft', + currency: 'SATS', + }) + ); + expect(result).toEqual(created); + }); + + it('creates a product with required defaults', async () => { + const created = { id: 'prod-1', title: 'Prod', status: 'draft' }; + mockAdminChain.single.mockResolvedValue({ data: created, error: null }); + + const result = await createProduct('user-2', { + title: 'Prod', + price: 1000, + }); + + expect(mockAdminClient.from).toHaveBeenCalledWith('user_products'); + expect(mockAdminChain.insert).toHaveBeenCalledWith( + expect.objectContaining({ + user_id: 'user-2', + title: 'Prod', + price: 1000, + status: 'draft', + currency: 'SATS', + product_type: 'physical', + }) + ); + expect(result).toEqual(created); + }); + + it('creates a cause with safe defaults', async () => { + const created = { id: 'cause-1', title: 'Cause', status: 'draft' }; + mockAdminChain.single.mockResolvedValue({ data: created, error: null }); + + const result = await createCause('user-3', { + title: 'Cause', + cause_category: 'charity', + lightning_address: '', + }); + + expect(mockAdminClient.from).toHaveBeenCalledWith('user_causes'); + expect(mockAdminChain.insert).toHaveBeenCalledWith( + expect.objectContaining({ + user_id: 'user-3', + title: 'Cause', + cause_category: 'charity', + status: 'draft', + total_raised: 0, + }) + ); + expect(result).toEqual(created); + }); +}); diff --git a/docs/development/ORANGECAT_ENTITY_WORKFLOW_CHECKLIST_2026-02-18.md b/docs/development/ORANGECAT_ENTITY_WORKFLOW_CHECKLIST_2026-02-18.md index dfa1ece85..9b6d18652 100644 --- a/docs/development/ORANGECAT_ENTITY_WORKFLOW_CHECKLIST_2026-02-18.md +++ b/docs/development/ORANGECAT_ENTITY_WORKFLOW_CHECKLIST_2026-02-18.md @@ -32,13 +32,13 @@ Pre-check completed: - ☑ Entity schema smoke suite added and passing (`__tests__/unit/api/entities.schema.smoke.test.ts`, 10/10) -- ☐ Project: create +- ◐ Project: create (unit workflow test passing in `__tests__/unit/domain/entity-create-workflows.test.ts`) - ☐ Project: edit - ☐ Project: list/detail - ☐ Project: status lifecycle transitions -- ☐ Service: create/edit/list/detail -- ☐ Product: create/edit/list/detail -- ☐ Cause: create/edit/list/detail +- ◐ Service: create/edit/list/detail (service create API/unit tests passing; edit/list still pending) +- ◐ Product: create/edit/list/detail (create workflow + schema validation passing; edit/list pending) +- ◐ Cause: create/edit/list/detail (create workflow + schema validation passing; edit/list pending) - ☐ Asset: create/edit/list/detail - ☐ Loan: create/edit/list/detail - ☐ Event: create/edit/list/detail