mirror of
https://github.com/immich-app/immich.git
synced 2025-12-25 09:14:58 +03:00
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
|
|
import { readdirSync } from 'node:fs';
|
||
|
|
import { join } from 'node:path';
|
||
|
|
import { schemaFromCode } from 'src/sql-tools/schema-from-code';
|
||
|
|
import { describe, expect, it } from 'vitest';
|
||
|
|
|
||
|
|
describe(schemaFromCode.name, () => {
|
||
|
|
it('should work', () => {
|
||
|
|
expect(schemaFromCode({ reset: true })).toEqual({
|
||
|
|
databaseName: 'postgres',
|
||
|
|
schemaName: 'public',
|
||
|
|
functions: [],
|
||
|
|
enums: [],
|
||
|
|
extensions: [],
|
||
|
|
parameters: [],
|
||
|
|
tables: [],
|
||
|
|
warnings: [],
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('test files', () => {
|
||
|
|
const errorStubs = readdirSync('test/sql-tools/errors', { withFileTypes: true });
|
||
|
|
for (const file of errorStubs) {
|
||
|
|
const filePath = join(file.parentPath, file.name);
|
||
|
|
it(filePath, async () => {
|
||
|
|
const module = await import(filePath);
|
||
|
|
expect(module.message).toBeDefined();
|
||
|
|
expect(() => schemaFromCode({ reset: true })).toThrowError(module.message);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
const stubs = readdirSync('test/sql-tools', { withFileTypes: true });
|
||
|
|
for (const file of stubs) {
|
||
|
|
if (file.isDirectory()) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
const filePath = join(file.parentPath, file.name);
|
||
|
|
it(filePath, async () => {
|
||
|
|
const module = await import(filePath);
|
||
|
|
expect(module.description).toBeDefined();
|
||
|
|
expect(module.schema).toBeDefined();
|
||
|
|
expect(schemaFromCode({ reset: true }), module.description).toEqual(module.schema);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|