zenstack/tests/regression/test/issue-493.test.ts
Yiming Cao 99f68e2f7b
feat(orm): mysql support (#616)
* WIP(orm): mysql support

* WIP: more progress with fixing tests

* WIP: get all client api tests pass

* WIP: get all tests pass

* fix executor

* add MySQL to CI matrix

* fix sqlite test runs

* fix test

* fix delete readback check

* set mysql container max connections

* fix tests

* fix test

* refactor: extract duplicated mysql/pg code into base class

* address PR comments

* refactor: remove order by duplicated code

* refactor: optimize stripTableReference

* addressing PR comments

* fix tests
2026-01-24 23:21:36 +08:00

94 lines
2.4 KiB
TypeScript

import { createTestClient } from '@zenstackhq/testtools';
import { describe, expect, it } from 'vitest';
describe('Issue 493 regression tests', () => {
it('should correctly handle JSON and typed-JSON array fields for PostgreSQL', async () => {
const schema = `
type InlineButton {
id String
text String
callback_data String?
url String?
message String?
type String?
}
type BotButton {
id String
label String
action String
enabled Boolean
order_index Int
message String
inline_buttons InlineButton[]? // Nested custom type
}
model bot_settings {
id Int @id @default(autoincrement())
setting_key String @unique
menu_buttons BotButton[] @json // Array of custom type
meta Meta @json
}
type Meta {
info String
}
model Foo {
id Int @id @default(autoincrement())
data Json
}
`;
const db = await createTestClient(schema, { provider: 'postgresql' });
// plain JSON non-array
await expect(
db.foo.create({
data: {
data: { hello: 'world' },
},
}),
).resolves.toMatchObject({
data: { hello: 'world' },
});
// plain JSON array
await expect(
db.foo.create({
data: {
data: [{ hello: 'world' }],
},
}),
).resolves.toMatchObject({
data: [{ hello: 'world' }],
});
// typed-JSON array & non-array
const input = {
setting_key: 'abc',
menu_buttons: [
{
id: '1',
label: 'Button 1',
action: 'action_1',
enabled: true,
order_index: 1,
message: 'msg',
inline_buttons: [
{
id: 'ib1',
text: 'Inline 1',
},
],
},
],
meta: { info: 'some info' },
};
await expect(
db.bot_settings.create({
data: input,
}),
).resolves.toMatchObject(input);
});
});