Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Dec 2, 2024
1 parent 38be909 commit 5d01372
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
23 changes: 12 additions & 11 deletions packages/plugins/openapi/tests/openapi-rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import OpenAPIParser from '@readme/openapi-parser';
import { getLiteral, getObjectLiteral } from '@zenstackhq/sdk';
import { Model, Plugin, isPlugin } from '@zenstackhq/sdk/ast';
import { loadZModelAndDmmf, normalizePath } from '@zenstackhq/testtools';
import { loadSchema, loadZModelAndDmmf, normalizePath } from '@zenstackhq/testtools';
import fs from 'fs';
import path from 'path';
import * as tmp from 'tmp';
Expand All @@ -17,11 +17,13 @@ describe('Open API Plugin RPC Tests', () => {
it('run plugin', async () => {
for (const specVersion of ['3.0.0', '3.1.0']) {
for (const omitInputDetails of [true, false]) {
const { model, dmmf, modelFile } = await loadZModelAndDmmf(`
const { projectDir } = await loadSchema(
`
plugin openapi {
provider = '${normalizePath(path.resolve(__dirname, '../dist'))}'
specVersion = '${specVersion}'
omitInputDetails = ${omitInputDetails}
output = '$projectRoot/openapi.yaml'
}
enum role {
Expand Down Expand Up @@ -89,18 +91,17 @@ model Bar {
id String @id
@@ignore
}
`);

const { name: output } = tmp.fileSync({ postfix: '.yaml' });

const options = buildOptions(model, modelFile, output);
await generate(model, options, dmmf);
`,
{ provider: 'postgresql', pushDb: false }
);

console.log(
`OpenAPI specification generated for ${specVersion}${omitInputDetails ? ' - omit' : ''}: ${output}`
`OpenAPI specification generated for ${specVersion}${
omitInputDetails ? ' - omit' : ''
}: ${projectDir}/openapi.yaml`
);

const parsed = YAML.parse(fs.readFileSync(output, 'utf-8'));
const parsed = YAML.parse(fs.readFileSync(path.join(projectDir, 'openapi.yaml'), 'utf-8'));
expect(parsed.openapi).toBe(specVersion);
const baseline = YAML.parse(
fs.readFileSync(
Expand All @@ -110,7 +111,7 @@ model Bar {
);
expect(parsed).toMatchObject(baseline);

const api = await OpenAPIParser.validate(output);
const api = await OpenAPIParser.validate(path.join(projectDir, 'openapi.yaml'));

expect(api.tags).toEqual(
expect.arrayContaining([
Expand Down
5 changes: 3 additions & 2 deletions packages/plugins/trpc/tests/projects/t3-trpc-v10/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"start": "next start"
},
"dependencies": {
"@prisma/client": "^5.13.0",
"@prisma/client": "6.0.x",
"@t3-oss/env-nextjs": "^0.7.1",
"@tanstack/react-query": "^4.36.1",
"@trpc/client": "^10.43.6",
Expand All @@ -24,6 +24,7 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"superjson": "^2.2.1",
"zenstack": "file:../../../../../../.build/zenstack-2.9.4.tgz",
"zod": "^3.22.4"
},
"devDependencies": {
Expand All @@ -35,7 +36,7 @@
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^8.54.0",
"eslint-config-next": "^14.0.4",
"prisma": "^5.13.0",
"prisma": "6.0.x",
"typescript": "^5.5.4"
},
"ct3aMetadata": {
Expand Down
12 changes: 6 additions & 6 deletions packages/server/tests/api/rest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2701,7 +2701,7 @@ describe('REST server tests', () => {
float: 1.23,
decimal: decimalValue1,
boolean: true,
bytes: Buffer.from([1, 2, 3, 4]),
bytes: new Uint8Array([1, 2, 3, 4]),
};

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

const updateAttrs = {
bigInt: BigInt(1534543543534),
date: new Date(),
decimal: decimalValue2,
bytes: Buffer.from([5, 2, 3, 4]),
bytes: new Uint8Array([5, 2, 3, 4]),
};
const { json: updatePayload, meta: updateMeta } = SuperJSON.serialize({
data: {
Expand Down Expand Up @@ -2776,7 +2776,7 @@ describe('REST server tests', () => {
expect(data.bigInt).toEqual(updateAttrs.bigInt);
expect(data.date).toEqual(updateAttrs.date);
expect(data.decimal.equals(updateAttrs.decimal)).toBeTruthy();
expect(data.bytes.toString('base64')).toEqual(updateAttrs.bytes.toString('base64'));
expect(data.bytes.toString()).toEqual(updateAttrs.bytes.toString());

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

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

Expand Down
16 changes: 8 additions & 8 deletions packages/server/tests/api/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ describe('RPC API Handler Tests', () => {
const decimalValue = new Decimal('0.046875');
const bigIntValue = BigInt(534543543534);
const dateValue = new Date();
const bufferValue = Buffer.from([1, 2, 3, 4]);
const barBufferValue = Buffer.from([7, 8, 9]);
const bytesValue = new Uint8Array([1, 2, 3, 4]);
const barBytesValue = new Uint8Array([7, 8, 9]);

const createData = {
string: 'string',
Expand All @@ -315,9 +315,9 @@ describe('RPC API Handler Tests', () => {
float: 1.23,
decimal: decimalValue,
boolean: true,
bytes: bufferValue,
bytes: bytesValue,
bars: {
create: { bytes: barBufferValue },
create: { bytes: barBytesValue },
},
};

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

// find with filter not found
const serializedQ = SuperJSON.serialize({
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('RPC API Handler Tests', () => {
where: {
bars: {
some: {
bytes: barBufferValue,
bytes: barBytesValue,
},
},
},
Expand All @@ -418,7 +418,7 @@ describe('RPC API Handler Tests', () => {
where: {
bars: {
none: {
bytes: barBufferValue,
bytes: barBytesValue,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/tests/e2e/type-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Type Coverage Tests', () => {
Float: 1.23,
Decimal: new Decimal(1.2345),
Boolean: true,
Bytes: Buffer.from('hello'),
Bytes: new Uint8Array([1, 2, 3, 4]),
};

await db.foo.create({
Expand Down

0 comments on commit 5d01372

Please sign in to comment.