Skip to content

Commit e65e059

Browse files
Copilothotlong
andcommitted
Add getDriver() and stop() methods to ObjectKernel mocks
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent a75f243 commit e65e059

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

  • packages/protocols
    • graphql/test/__mocks__/@objectstack
    • json-rpc/test/__mocks__/@objectstack
    • odata-v4/test/__mocks__/@objectstack
    • rest/test/__mocks__/@objectstack

packages/protocols/graphql/test/__mocks__/@objectstack/core.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ export class ObjectKernel {
114114
}
115115
}
116116

117+
async stop(): Promise<void> {
118+
// Mock implementation that calls plugin lifecycle methods
119+
for (const plugin of this.plugins) {
120+
if (plugin.onStop) {
121+
await plugin.onStop({ engine: this });
122+
}
123+
}
124+
}
125+
126+
getDriver(): any {
127+
// Return the first driver-like plugin (typically MemoryDriver, SQLDriver, etc.)
128+
// Drivers usually don't have an 'install' method or have specific driver methods
129+
const driver = this.plugins.find(p =>
130+
p.constructor.name?.includes('Driver') ||
131+
(typeof p.find === 'function' && typeof p.create === 'function')
132+
);
133+
return driver || this.driver;
134+
}
135+
117136
async seed(): Promise<void> {
118137
// Mock implementation
119138
}

packages/protocols/json-rpc/test/__mocks__/@objectstack/core.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ export class ObjectKernel {
114114
}
115115
}
116116

117+
async stop(): Promise<void> {
118+
// Mock implementation that calls plugin lifecycle methods
119+
for (const plugin of this.plugins) {
120+
if (plugin.onStop) {
121+
await plugin.onStop({ engine: this });
122+
}
123+
}
124+
}
125+
126+
getDriver(): any {
127+
// Return the first driver-like plugin (typically MemoryDriver, SQLDriver, etc.)
128+
// Drivers usually don't have an 'install' method or have specific driver methods
129+
const driver = this.plugins.find(p =>
130+
p.constructor.name?.includes('Driver') ||
131+
(typeof p.find === 'function' && typeof p.create === 'function')
132+
);
133+
return driver || this.driver;
134+
}
135+
117136
async seed(): Promise<void> {
118137
// Mock implementation
119138
}

packages/protocols/odata-v4/test/__mocks__/@objectstack/core.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ export class ObjectKernel {
114114
}
115115
}
116116

117+
async stop(): Promise<void> {
118+
// Mock implementation that calls plugin lifecycle methods
119+
for (const plugin of this.plugins) {
120+
if (plugin.onStop) {
121+
await plugin.onStop({ engine: this });
122+
}
123+
}
124+
}
125+
126+
getDriver(): any {
127+
// Return the first driver-like plugin (typically MemoryDriver, SQLDriver, etc.)
128+
// Drivers usually don't have an 'install' method or have specific driver methods
129+
const driver = this.plugins.find(p =>
130+
p.constructor.name?.includes('Driver') ||
131+
(typeof p.find === 'function' && typeof p.create === 'function')
132+
);
133+
return driver || this.driver;
134+
}
135+
117136
async seed(): Promise<void> {
118137
// Mock implementation
119138
}

packages/protocols/rest/test/__mocks__/@objectstack/runtime.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ export class ObjectKernel {
123123
}
124124
}
125125

126+
getDriver(): any {
127+
// Return the first driver-like plugin (typically MemoryDriver, SQLDriver, etc.)
128+
// Drivers usually don't have an 'install' method or have specific driver methods
129+
const driver = this.plugins.find(p =>
130+
p.constructor.name?.includes('Driver') ||
131+
(typeof p.find === 'function' && typeof p.create === 'function')
132+
);
133+
return driver || this.driver;
134+
}
135+
126136
async seed(): Promise<void> {
127137
// Mock implementation
128138
}

0 commit comments

Comments
 (0)