Skip to content

Commit a07c6e5

Browse files
committed
test: add unit tests for get_resource_data datetime formatting in caller timezone
1 parent a113dec commit a07c6e5

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { AdminForthDataTypes } from '../../adminforth/index.js';
2+
import { prepareApiBasedTools } from '../../plugins/adminforth-agent/apiBasedTools.js';
3+
4+
describe('adminforth-agent apiBasedTools', () => {
5+
it('formats get_resource_data datetime columns in the caller timezone', async () => {
6+
const adminforth = {
7+
config: {
8+
baseUrl: 'http://localhost:3000',
9+
},
10+
tr: async (msg: string) => msg,
11+
setupEndpoints(server: { endpoint: (options: any) => void }) {
12+
server.endpoint({
13+
method: 'POST',
14+
path: '/get_resource',
15+
request_schema: {},
16+
response_schema: {},
17+
handler: ({ body }: { body: Record<string, unknown> }) => ({
18+
resource: {
19+
resourceId: body.resourceId,
20+
columns: [
21+
{
22+
name: 'created_at',
23+
type: AdminForthDataTypes.DATETIME,
24+
},
25+
{
26+
name: 'updated_at',
27+
type: AdminForthDataTypes.DATETIME,
28+
},
29+
{
30+
name: 'raw_iso_note',
31+
type: AdminForthDataTypes.STRING,
32+
},
33+
],
34+
},
35+
}),
36+
});
37+
38+
server.endpoint({
39+
method: 'POST',
40+
path: '/get_resource_data',
41+
request_schema: {},
42+
response_schema: {},
43+
handler: () => ({
44+
data: [
45+
{
46+
created_at: '2026-04-18T12:32:45.123Z',
47+
updated_at: '2026-04-18T23:01:02.003Z',
48+
raw_iso_note: '2026-04-18T12:32:45.123Z',
49+
},
50+
],
51+
total: 1,
52+
}),
53+
});
54+
},
55+
} as any;
56+
57+
const tools = prepareApiBasedTools(adminforth);
58+
const output = await tools.get_resource_data.call({
59+
inputs: {
60+
resourceId: 'adminuser',
61+
source: 'list',
62+
limit: 1,
63+
offset: 0,
64+
filters: [],
65+
sort: [],
66+
},
67+
userTimeZone: 'Europe/Kyiv',
68+
});
69+
70+
expect(output).toContain('18 Apr 2026, 15:32:45.123 (GMT+3)');
71+
expect(output).toContain('19 Apr 2026, 02:01:02.003 (GMT+3)');
72+
expect(output).toContain('raw_iso_note: 2026-04-18T12:32:45.123Z');
73+
expect(output).not.toContain('created_at: 2026-04-18T12:32:45.123Z');
74+
expect(output).not.toContain('updated_at: 2026-04-18T23:01:02.003Z');
75+
});
76+
});

0 commit comments

Comments
 (0)