Skip to content

Commit f9ccf48

Browse files
committed
Add Jest tests and configs for drivers and express
Introduces Jest configuration and basic test suites for driver-knex, driver-mongo, and express packages. Updates package.json test scripts to use Jest. Also updates documentation to reference objectql.config.js instead of .objectqlrc.js for connection configuration.
1 parent 5c15b69 commit f9ccf48

File tree

10 files changed

+68
-5
lines changed

10 files changed

+68
-5
lines changed

docs/METADATA.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The system uses a **"Directory-as-Datasource"** convention to map objects to dat
2929
│ └── users.object.yml # [Datasource: default] (Root level = default)
3030
3131
├── /roles # RBAC Definitions
32-
└── .objectqlrc.js # Connection config (Environment specific)
32+
└── objectql.config.js # Connection config (Environment specific)
3333
```
3434

3535
### 2.2 Resolution Priority
@@ -38,7 +38,7 @@ The system uses a **"Directory-as-Datasource"** convention to map objects to dat
3838
2. **Implicit:** Subdirectory name under `/objects/`.
3939
3. **Fallback:** `default` connection.
4040

41-
### 2.3 Connection Configuration (`.objectqlrc.js`)
41+
### 2.3 Connection Configuration (`objectql.config.js`)
4242

4343
This file exports the configuration for all valid datasources. The `default` datasource is required.
4444

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testMatch: ['**/test/**/*.test.ts'],
5+
};

packages/driver-knex/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index.d.ts",
66
"scripts": {
77
"build": "tsc",
8-
"test": "echo \"No tests specified\" && exit 0"
8+
"test": "jest"
99
},
1010
"dependencies": {
1111
"@objectql/core": "^0.1.0",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { KnexDriver } from '../src';
2+
import knex from 'knex';
3+
4+
jest.mock('knex', () => {
5+
return jest.fn(() => ({
6+
// Mock knex instance methods if needed
7+
}));
8+
});
9+
10+
describe('KnexDriver', () => {
11+
it('should be instantiable', () => {
12+
const driver = new KnexDriver({ client: 'sqlite3' });
13+
expect(driver).toBeDefined();
14+
expect(driver).toBeInstanceOf(KnexDriver);
15+
});
16+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testMatch: ['**/test/**/*.test.ts'],
5+
};

packages/driver-mongo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index.d.ts",
66
"scripts": {
77
"build": "tsc",
8-
"test": "echo \"No tests specified\" && exit 0"
8+
"test": "jest"
99
},
1010
"dependencies": {
1111
"@objectql/core": "^0.1.0",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { MongoDriver } from '../src';
2+
import { MongoClient } from 'mongodb';
3+
4+
jest.mock('mongodb', () => {
5+
return {
6+
MongoClient: jest.fn().mockImplementation(() => ({
7+
connect: jest.fn().mockResolvedValue(undefined),
8+
db: jest.fn().mockReturnValue({}),
9+
})),
10+
};
11+
});
12+
13+
describe('MongoDriver', () => {
14+
it('should be instantiable', () => {
15+
const driver = new MongoDriver({ url: 'mongodb://localhost:27017' });
16+
expect(driver).toBeDefined();
17+
expect(driver).toBeInstanceOf(MongoDriver);
18+
});
19+
});

packages/express/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
testMatch: ['**/test/**/*.test.ts'],
5+
};

packages/express/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"types": "dist/index.d.ts",
66
"scripts": {
77
"build": "tsc",
8-
"test": "echo \"No tests specified\" && exit 0"
8+
"test": "jest"
99
},
1010
"dependencies": {
1111
"@objectql/core": "^0.1.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createObjectQLRouter } from '../src';
2+
import { IObjectQL } from '@objectql/core';
3+
import express from 'express';
4+
5+
describe('createObjectQLRouter', () => {
6+
it('should create a router', () => {
7+
const mockObjectQL = {} as IObjectQL;
8+
const router = createObjectQLRouter({ objectql: mockObjectQL });
9+
expect(router).toBeDefined();
10+
// Router is a function in Express
11+
expect(typeof router).toBe('function');
12+
});
13+
});

0 commit comments

Comments
 (0)