-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetadata-loading.test.ts
More file actions
144 lines (125 loc) · 4.68 KB
/
metadata-loading.test.ts
File metadata and controls
144 lines (125 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* ObjectQL
* Copyright (c) 2026-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Metadata Loading Tests for Express API Starter
*
* Tests that metadata files are correctly loaded and registered
*/
import { ObjectQL } from '@objectql/core';
import { SqlDriver } from '@objectql/driver-sql';
import { ObjectLoader } from '@objectql/platform-node';
import * as path from 'path';
describe('Metadata Loading', () => {
let app: ObjectQL;
beforeAll(async () => {
// Initialize ObjectQL
app = new ObjectQL({
datasources: {
default: new SqlDriver({
client: 'sqlite3',
connection: {
filename: ':memory:'
},
useNullAsDefault: true
})
}
});
// Load metadata from src directory
const srcDir = path.resolve(__dirname, '../src');
const loader = new ObjectLoader(app.metadata);
loader.load(srcDir);
await app.init();
});
afterAll(async () => {
if (app && (app as any).datasources?.default) {
const driver = (app as any).datasources.default;
if (driver.knex) {
await driver.knex.destroy();
}
}
});
describe('Object Metadata', () => {
it('should load User object metadata', () => {
const userConfig = app.getObject('user');
expect(userConfig).toBeDefined();
expect(userConfig.name).toBe('user');
expect(userConfig.label).toBe('Users');
});
it('should load Task object metadata', () => {
const taskConfig = app.getObject('task');
expect(taskConfig).toBeDefined();
expect(taskConfig.name).toBe('task');
expect(taskConfig.label).toBe('Tasks');
});
it('should load User fields correctly', () => {
const userConfig = app.getObject('user');
expect(userConfig.fields).toBeDefined();
expect(userConfig.fields.name).toEqual(expect.objectContaining({
type: 'string',
label: 'Full Name',
required: true
}));
expect(userConfig.fields.email).toEqual(expect.objectContaining({
type: 'string',
label: 'Email Address',
required: true
}));
expect(userConfig.fields.status).toEqual(expect.objectContaining({
type: 'string',
label: 'Status',
defaultValue: 'active'
}));
expect(userConfig.fields.age).toEqual(expect.objectContaining({
type: 'number',
label: 'Age'
}));
});
it('should load Task fields correctly', () => {
const taskConfig = app.getObject('task');
expect(taskConfig.fields).toBeDefined();
expect(taskConfig.fields.title).toEqual(expect.objectContaining({
type: 'string',
label: 'Title',
required: true
}));
expect(taskConfig.fields.description).toEqual(expect.objectContaining({
type: 'text',
label: 'Description'
}));
expect(taskConfig.fields.status).toEqual(expect.objectContaining({
type: 'string',
label: 'Status',
defaultValue: 'pending'
}));
expect(taskConfig.fields.priority).toEqual(expect.objectContaining({
type: 'string',
label: 'Priority',
defaultValue: 'medium'
}));
expect(taskConfig.fields.completed).toEqual(expect.objectContaining({
type: 'boolean',
label: 'Completed',
defaultValue: false
}));
});
});
describe('Metadata Registry', () => {
it('should return list of loaded objects', () => {
const configs = app.getConfigs();
const objectNames = Object.keys(configs);
expect(objectNames).toContain('user');
expect(objectNames).toContain('task');
expect(objectNames.length).toBeGreaterThanOrEqual(2);
});
it('should support metadata.get for objects', () => {
const userMetadata = app.metadata.get('object', 'user');
expect(userMetadata).toBeDefined();
expect(userMetadata.name).toBe('user');
});
});
});