Skip to content

Commit 5d01372

Browse files
committed
fix tests
1 parent 38be909 commit 5d01372

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

packages/plugins/openapi/tests/openapi-rpc.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import OpenAPIParser from '@readme/openapi-parser';
55
import { getLiteral, getObjectLiteral } from '@zenstackhq/sdk';
66
import { Model, Plugin, isPlugin } from '@zenstackhq/sdk/ast';
7-
import { loadZModelAndDmmf, normalizePath } from '@zenstackhq/testtools';
7+
import { loadSchema, loadZModelAndDmmf, normalizePath } from '@zenstackhq/testtools';
88
import fs from 'fs';
99
import path from 'path';
1010
import * as tmp from 'tmp';
@@ -17,11 +17,13 @@ describe('Open API Plugin RPC Tests', () => {
1717
it('run plugin', async () => {
1818
for (const specVersion of ['3.0.0', '3.1.0']) {
1919
for (const omitInputDetails of [true, false]) {
20-
const { model, dmmf, modelFile } = await loadZModelAndDmmf(`
20+
const { projectDir } = await loadSchema(
21+
`
2122
plugin openapi {
2223
provider = '${normalizePath(path.resolve(__dirname, '../dist'))}'
2324
specVersion = '${specVersion}'
2425
omitInputDetails = ${omitInputDetails}
26+
output = '$projectRoot/openapi.yaml'
2527
}
2628
2729
enum role {
@@ -89,18 +91,17 @@ model Bar {
8991
id String @id
9092
@@ignore
9193
}
92-
`);
93-
94-
const { name: output } = tmp.fileSync({ postfix: '.yaml' });
95-
96-
const options = buildOptions(model, modelFile, output);
97-
await generate(model, options, dmmf);
94+
`,
95+
{ provider: 'postgresql', pushDb: false }
96+
);
9897

9998
console.log(
100-
`OpenAPI specification generated for ${specVersion}${omitInputDetails ? ' - omit' : ''}: ${output}`
99+
`OpenAPI specification generated for ${specVersion}${
100+
omitInputDetails ? ' - omit' : ''
101+
}: ${projectDir}/openapi.yaml`
101102
);
102103

103-
const parsed = YAML.parse(fs.readFileSync(output, 'utf-8'));
104+
const parsed = YAML.parse(fs.readFileSync(path.join(projectDir, 'openapi.yaml'), 'utf-8'));
104105
expect(parsed.openapi).toBe(specVersion);
105106
const baseline = YAML.parse(
106107
fs.readFileSync(
@@ -110,7 +111,7 @@ model Bar {
110111
);
111112
expect(parsed).toMatchObject(baseline);
112113

113-
const api = await OpenAPIParser.validate(output);
114+
const api = await OpenAPIParser.validate(path.join(projectDir, 'openapi.yaml'));
114115

115116
expect(api.tags).toEqual(
116117
expect.arrayContaining([

packages/plugins/trpc/tests/projects/t3-trpc-v10/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"start": "next start"
1414
},
1515
"dependencies": {
16-
"@prisma/client": "^5.13.0",
16+
"@prisma/client": "6.0.x",
1717
"@t3-oss/env-nextjs": "^0.7.1",
1818
"@tanstack/react-query": "^4.36.1",
1919
"@trpc/client": "^10.43.6",
@@ -24,6 +24,7 @@
2424
"react": "18.2.0",
2525
"react-dom": "18.2.0",
2626
"superjson": "^2.2.1",
27+
"zenstack": "file:../../../../../../.build/zenstack-2.9.4.tgz",
2728
"zod": "^3.22.4"
2829
},
2930
"devDependencies": {
@@ -35,7 +36,7 @@
3536
"@typescript-eslint/parser": "^6.11.0",
3637
"eslint": "^8.54.0",
3738
"eslint-config-next": "^14.0.4",
38-
"prisma": "^5.13.0",
39+
"prisma": "6.0.x",
3940
"typescript": "^5.5.4"
4041
},
4142
"ct3aMetadata": {

packages/server/tests/api/rest.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,7 @@ describe('REST server tests', () => {
27012701
float: 1.23,
27022702
decimal: decimalValue1,
27032703
boolean: true,
2704-
bytes: Buffer.from([1, 2, 3, 4]),
2704+
bytes: new Uint8Array([1, 2, 3, 4]),
27052705
};
27062706

27072707
const { json: createPayload, meta: createMeta } = SuperJSON.serialize({
@@ -2736,15 +2736,15 @@ describe('REST server tests', () => {
27362736
let deserialized: any = SuperJSON.deserialize({ json: r.body, meta: serializationMeta });
27372737
let data = deserialized.data.attributes;
27382738
expect(typeof data.bigInt).toBe('bigint');
2739-
expect(Buffer.isBuffer(data.bytes)).toBeTruthy();
2739+
expect(data.bytes).toBeInstanceOf(Uint8Array);
27402740
expect(data.date instanceof Date).toBeTruthy();
27412741
expect(Decimal.isDecimal(data.decimal)).toBeTruthy();
27422742

27432743
const updateAttrs = {
27442744
bigInt: BigInt(1534543543534),
27452745
date: new Date(),
27462746
decimal: decimalValue2,
2747-
bytes: Buffer.from([5, 2, 3, 4]),
2747+
bytes: new Uint8Array([5, 2, 3, 4]),
27482748
};
27492749
const { json: updatePayload, meta: updateMeta } = SuperJSON.serialize({
27502750
data: {
@@ -2776,7 +2776,7 @@ describe('REST server tests', () => {
27762776
expect(data.bigInt).toEqual(updateAttrs.bigInt);
27772777
expect(data.date).toEqual(updateAttrs.date);
27782778
expect(data.decimal.equals(updateAttrs.decimal)).toBeTruthy();
2779-
expect(data.bytes.toString('base64')).toEqual(updateAttrs.bytes.toString('base64'));
2779+
expect(data.bytes.toString()).toEqual(updateAttrs.bytes.toString());
27802780

27812781
r = await handler({
27822782
method: 'get',
@@ -2791,7 +2791,7 @@ describe('REST server tests', () => {
27912791
deserialized = SuperJSON.deserialize({ json: r.body, meta: serializationMeta });
27922792
data = deserialized.data.attributes;
27932793
expect(typeof data.bigInt).toBe('bigint');
2794-
expect(Buffer.isBuffer(data.bytes)).toBeTruthy();
2794+
expect(data.bytes).toBeInstanceOf(Uint8Array);
27952795
expect(data.date instanceof Date).toBeTruthy();
27962796
expect(Decimal.isDecimal(data.decimal)).toBeTruthy();
27972797

@@ -2807,7 +2807,7 @@ describe('REST server tests', () => {
28072807
expect(serializationMeta).toBeTruthy();
28082808
deserialized = SuperJSON.deserialize({ json: r.body, meta: serializationMeta });
28092809
const included = deserialized.included[0];
2810-
expect(Buffer.isBuffer(included.attributes.bytes)).toBeTruthy();
2810+
expect(included.attributes.bytes).toBeInstanceOf(Uint8Array);
28112811
});
28122812
});
28132813

packages/server/tests/api/rpc.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ describe('RPC API Handler Tests', () => {
304304
const decimalValue = new Decimal('0.046875');
305305
const bigIntValue = BigInt(534543543534);
306306
const dateValue = new Date();
307-
const bufferValue = Buffer.from([1, 2, 3, 4]);
308-
const barBufferValue = Buffer.from([7, 8, 9]);
307+
const bytesValue = new Uint8Array([1, 2, 3, 4]);
308+
const barBytesValue = new Uint8Array([7, 8, 9]);
309309

310310
const createData = {
311311
string: 'string',
@@ -315,9 +315,9 @@ describe('RPC API Handler Tests', () => {
315315
float: 1.23,
316316
decimal: decimalValue,
317317
boolean: true,
318-
bytes: bufferValue,
318+
bytes: bytesValue,
319319
bars: {
320-
create: { bytes: barBufferValue },
320+
create: { bytes: barBytesValue },
321321
},
322322
};
323323

@@ -342,10 +342,10 @@ describe('RPC API Handler Tests', () => {
342342
expect(r.meta).toBeTruthy();
343343
const data: any = SuperJSON.deserialize({ json: r.data, meta: r.meta.serialization });
344344
expect(typeof data.bigInt).toBe('bigint');
345-
expect(Buffer.isBuffer(data.bytes)).toBeTruthy();
345+
expect(data.bytes).toBeInstanceOf(Uint8Array);
346346
expect(data.date instanceof Date).toBeTruthy();
347347
expect(Decimal.isDecimal(data.decimal)).toBeTruthy();
348-
expect(Buffer.isBuffer(data.bars[0].bytes)).toBeTruthy();
348+
expect(data.bars[0].bytes).toBeInstanceOf(Uint8Array);
349349

350350
// find with filter not found
351351
const serializedQ = SuperJSON.serialize({
@@ -394,7 +394,7 @@ describe('RPC API Handler Tests', () => {
394394
where: {
395395
bars: {
396396
some: {
397-
bytes: barBufferValue,
397+
bytes: barBytesValue,
398398
},
399399
},
400400
},
@@ -418,7 +418,7 @@ describe('RPC API Handler Tests', () => {
418418
where: {
419419
bars: {
420420
none: {
421-
bytes: barBufferValue,
421+
bytes: barBytesValue,
422422
},
423423
},
424424
},

tests/integration/tests/e2e/type-coverage.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Type Coverage Tests', () => {
4848
Float: 1.23,
4949
Decimal: new Decimal(1.2345),
5050
Boolean: true,
51-
Bytes: Buffer.from('hello'),
51+
Bytes: new Uint8Array([1, 2, 3, 4]),
5252
};
5353

5454
await db.foo.create({

0 commit comments

Comments
 (0)