Skip to content

Commit

Permalink
- fix: added tests for tool backend project
Browse files Browse the repository at this point in the history
  • Loading branch information
agallardol committed Aug 19, 2024
1 parent 5386845 commit 603030e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/shinkai-tool-playwright-example/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('exists definition', async () => {
expect(definition).toBeInstanceOf(Object);
});

test('run definition', async () => {
test('run', async () => {
const tool = new Tool({
chromePath: process.env?.CHROME_PATH,
});
Expand Down
4 changes: 2 additions & 2 deletions apps/shinkai-tools-backend/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
export default {
displayName: '@shinkai_protocol/shinkai-tool-download-page',
displayName: '@shinkai_protocol/shinkai-tools-backend',
preset: '../../jest.preset.js',
coverageDirectory: '../../coverage/apps/shinkai-tool-download-page'
coverageDirectory: '../../coverage/apps/shinkai-tools-backend',
};
47 changes: 47 additions & 0 deletions apps/shinkai-tools-backend/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { fastify } from './index';

test('GET /health', async () => {
const response = await fastify.inject({
method: 'GET',
url: '/health',
});
expect(response.json().status).toBe('ok');
});

test('GET /tool/definition', async () => {
const response = await fastify.inject({
method: 'POST',
url: '/tool/run',
body: {
code: `
class BaseTool {
constructor(config) {
this.config = config;
}
setConfig(value) {
this.config = value;
return this.config;
}
getConfig() {
return this.config;
}
}
class Tool extends BaseTool {
constructor(config) {
super(config);
}
async run() {
const result = await new Promise((resolve) => {
setTimeout(() => {
resolve(100);
}, 200);
});
return { data: result };
}
}
globalThis.tool = { Tool };
`,
},
});
expect(response.json().data).toBe(100);
});
2 changes: 1 addition & 1 deletion apps/shinkai-tools-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import z from 'zod';
import { BaseTool } from '@shinkai_protocol/shinkai-tools-builder';

const fastify = Fastify({
export const fastify = Fastify({
logger: true,
});

Expand Down

0 comments on commit 603030e

Please sign in to comment.