mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-04 20:28:04 +01:00
orangecat: add unit coverage for project/product/cause create workflows
This commit is contained in:
1 parent
0f92cca42b
commit
4a85dcfcff
2 files changed
+113
-4
No files matched your search
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user