Files
wehub-resource-sync 3a28426bf4
Lint and Format Check / lint-and-format (push) Failing after 0s
Check Migrations / Check for duplicate migration numbers (push) Failing after 1s
CI Pre-merge Check / CI Pre-merge Check (push) Failing after 2m17s
chore: import upstream snapshot with attribution
2026-07-13 12:23:40 +08:00

51 lines
1.4 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
const { poolQueryMock } = vi.hoisted(() => ({
poolQueryMock: vi.fn(),
}));
vi.mock('../../src/infra/database/database.manager', () => ({
DatabaseManager: {
getInstance: vi.fn(() => ({
getPool: vi.fn(() => ({
query: poolQueryMock,
})),
})),
},
}));
import { DatabaseService } from '../../src/services/database/database.service';
describe('DatabaseService', () => {
beforeEach(() => {
vi.clearAllMocks();
});
it('derives dashboard schema protection from project_admin CREATE privilege', async () => {
poolQueryMock.mockResolvedValue({
rows: [
{ name: 'public', isProtected: false },
{ name: 'analytics', isProtected: false },
{ name: 'auth', isProtected: true },
],
});
const service = DatabaseService.getInstance();
const result = await service.getSchemas();
expect(result).toEqual({
schemas: [
{ name: 'public', isProtected: false },
{ name: 'analytics', isProtected: false },
{ name: 'auth', isProtected: true },
],
});
expect(poolQueryMock).toHaveBeenCalledWith(expect.any(String), ['public']);
const sql = poolQueryMock.mock.calls[0]?.[0] as string;
expect(sql).toContain("has_schema_privilege(to_regrole('project_admin'), n.oid, 'CREATE')");
expect(sql).not.toContain('ANY($1::text[])');
});
});