Skip to content

Commit

Permalink
add schema checking testing
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Oct 13, 2024
1 parent 5af395d commit 31aa178
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/connections/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,45 @@ describe('Database Connection', () => {
.query();
});

test('Check the schema', async () => {
if (db.fetchDatabaseSchema) {
const schemas = await db.fetchDatabaseSchema();

// Column names are sorted for easier comparison
const expectedSchema = {
[DEFAULT_SCHEMA]: {
persons: {
columns: ['age', 'id', 'name'],
},
},
};

// We only care about the columns for this test
const actualSchema = Object.entries(schemas).reduce(
(a, [schemaName, schemaTables]) => {
a[schemaName] = Object.entries(schemaTables).reduce(
(b, [tableName, table]) => {
b[tableName] = {
columns: table.columns
.map((column) => column.name)
.sort(),
};
return b;
},
{} as Record<string, { columns: string[] }>
);

return a;
},
{} as Record<string, Record<string, { columns: string[] }>>
);

expect(actualSchema).toEqual(expectedSchema);
}

expect(true).toBe(true);
});

test('Insert data', async () => {
// Insert data
await qb
Expand Down

0 comments on commit 31aa178

Please sign in to comment.