transit-kit 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,6 @@
1
1
  import z from "zod";
2
2
  import { hasValue } from "../server/utils/typeGuards";
3
3
  import { isJsonResponseSchema } from "../server/handlers/api/responses/jsonResponse";
4
- function prepareForJsonSchema(schema) {
5
- // 1. Handle Dates (The Core Issue)
6
- if (schema instanceof z.ZodDate) {
7
- return z.string().datetime().describe("ISO 8601 date-time string");
8
- }
9
- // 2. Handle Objects
10
- if (schema instanceof z.ZodObject) {
11
- const newShape = {};
12
- for (const key in schema.shape) {
13
- newShape[key] = prepareForJsonSchema(schema.shape[key]);
14
- }
15
- return z.object(newShape);
16
- }
17
- // 3. Handle Arrays
18
- if (schema instanceof z.ZodArray) {
19
- return z.array(prepareForJsonSchema(schema.element));
20
- }
21
- // 4. Handle Optionals
22
- if (schema instanceof z.ZodOptional) {
23
- return prepareForJsonSchema(schema.unwrap()).optional();
24
- }
25
- // 5. Handle Nullables
26
- if (schema instanceof z.ZodNullable) {
27
- return prepareForJsonSchema(schema.unwrap()).nullable();
28
- }
29
- // 7. Handle Unions
30
- if (schema instanceof z.ZodUnion) {
31
- return z.union(schema.options.map((option) => prepareForJsonSchema(option)));
32
- }
33
- // Return as-is if no transformation is needed
34
- return schema;
35
- }
36
4
  function extractPathAndParameters(path) {
37
5
  const parameters = path.match(/:([a-zA-Z0-9_]+)/g)?.map((param) => {
38
6
  return {
@@ -49,7 +17,7 @@ function extractPathAndParameters(path) {
49
17
  return { openApiPath, parameters };
50
18
  }
51
19
  function extractQueryParameters(querySchema) {
52
- const querySchemaObject = z.toJSONSchema(prepareForJsonSchema(querySchema));
20
+ const querySchemaObject = z.toJSONSchema(querySchema, { io: "input" });
53
21
  if (querySchemaObject.properties) {
54
22
  return Object.entries(querySchemaObject.properties).map(([name, schema]) => ({
55
23
  name: name,
@@ -95,7 +63,9 @@ function translateToOpenAPIPathItem(definition) {
95
63
  required: true,
96
64
  content: {
97
65
  "application/json": {
98
- schema: z.toJSONSchema(prepareForJsonSchema(requestBodySchema)), // Type assertion
66
+ schema: z.toJSONSchema(requestBodySchema, {
67
+ io: "input",
68
+ }), // Type assertion
99
69
  },
100
70
  },
101
71
  },
@@ -105,13 +75,13 @@ function translateToOpenAPIPathItem(definition) {
105
75
  const responses = Object.entries(responseSchemas)
106
76
  .map(([statusCode, responseDef]) => {
107
77
  if (isJsonResponseSchema(responseDef)) {
108
- const zodSchema = responseDef.dataSchema;
109
- const responseSchema = z.toJSONSchema(prepareForJsonSchema(zodSchema));
78
+ const zodSchema = responseDef.schema;
79
+ const responseSchema = z.toJSONSchema(zodSchema, { io: "input" });
110
80
  return {
111
81
  [statusCode]: {
112
82
  description: `Response for status code ${statusCode}`,
113
83
  content: {
114
- [responseDef.dataType]: {
84
+ ["application/json"]: {
115
85
  schema: responseSchema,
116
86
  },
117
87
  },
@@ -119,11 +89,7 @@ function translateToOpenAPIPathItem(definition) {
119
89
  };
120
90
  }
121
91
  else {
122
- return {
123
- [statusCode]: {
124
- description: `Response for status code ${statusCode}`,
125
- },
126
- };
92
+ throw new Error(`Unsupported response schema type: ${responseDef}`);
127
93
  }
128
94
  })
129
95
  .reduce((acc, resp) => {
@@ -16,15 +16,14 @@ describe("translateToOpenAPIPathItem", () => {
16
16
  securitySchemes: [],
17
17
  responseSchemas: {
18
18
  200: {
19
- dataType: "application/json",
20
- dataSchema: z.string(),
19
+ type: "json",
20
+ schema: z.string(),
21
21
  },
22
22
  },
23
23
  }, async ({ request }) => {
24
24
  return {
25
25
  code: 200,
26
- dataType: "application/json",
27
- json: request.params.id,
26
+ data: request.params.id,
28
27
  };
29
28
  });
30
29
  const [path, pathItem] = translateToOpenAPIPathItem(definition);
@@ -1,13 +1,11 @@
1
1
  import { Request, Response } from "express";
2
- import { HttpStatusCodes } from "../../constants/HttpStatusCodes";
3
- import { GenericResponse } from "./responses";
4
- export type ApiEndpointHandler<PathParams extends Record<string, string> = {}, RequestBody = unknown, Query = unknown, Responses extends GenericResponse = never, Caller = unknown> = (typedRequestData: {
2
+ import { HttpStatusCode } from "../../constants/HttpStatusCodes";
3
+ import { HandlerResponse } from "./responses";
4
+ export type ApiEndpointHandler<Responses extends HandlerResponse<HttpStatusCode, unknown>, PathParams extends Record<string, string> = {}, RequestBody = unknown, Query = unknown, Caller = unknown> = (typedRequestData: {
5
5
  request: Request<PathParams, unknown, RequestBody, Query, Record<string, unknown>>;
6
6
  response: Response<unknown>;
7
7
  parameters: PathParams;
8
8
  query: Query;
9
9
  body: RequestBody;
10
10
  caller: Caller;
11
- }) => Promise<Responses | {
12
- code: (typeof HttpStatusCodes)["InternalServerError_500"];
13
- }>;
11
+ }) => Promise<Responses>;
@@ -4,9 +4,7 @@ import { SecurityScheme } from "../../security/SecuritySchema";
4
4
  import { Prettify } from "../../utils/types";
5
5
  import { ApiEndpointHandler } from "./EndpointHandler";
6
6
  import { ExtractPathParams } from "./PathParameters";
7
- import { EmptyResponse, EmptyResponseSchema } from "./responses/emptyResponse";
8
- import { GenericResponse, GenericResponseSchemaMap } from "./responses/index";
9
- import { JsonResponseSchema, JsonResponseSchemaToResponseType } from "./responses/jsonResponse";
10
- export type HandlerForDefinition<Path extends string, RequestBody extends z.ZodType | undefined, Query extends z.ZodType | undefined, ResponsesMap extends GenericResponseSchemaMap, SecuritySchemas extends SecurityScheme<unknown>[] = []> = ApiEndpointHandler<ExtractPathParams<Path>, RequestBody extends undefined ? undefined : z.infer<RequestBody>, Query extends undefined ? undefined : z.infer<Query>, Exclude<Prettify<{
11
- [K in keyof ResponsesMap]: K extends HttpStatusCode ? ResponsesMap[K] extends JsonResponseSchema ? JsonResponseSchemaToResponseType<K, ResponsesMap[K]> : ResponsesMap[K] extends EmptyResponseSchema ? EmptyResponse<K> : ResponsesMap[K] extends undefined ? never : GenericResponse : never;
12
- }[keyof ResponsesMap]>, undefined>, SecuritySchemas extends SecurityScheme<infer Caller>[] ? Caller : unknown>;
7
+ import { GenericResponseSchema, GenericResponseSchemaMap, InferResponseFromSchema } from "./responses/index";
8
+ export type HandlerForDefinition<Path extends string, RequestBody extends z.ZodType | undefined, Query extends z.ZodType | undefined, ResponsesMap extends GenericResponseSchemaMap, SecuritySchemas extends SecurityScheme<unknown>[] = []> = ApiEndpointHandler<Exclude<Prettify<{
9
+ [K in keyof ResponsesMap]: K extends HttpStatusCode ? InferResponseFromSchema<K, ResponsesMap[K] extends GenericResponseSchema ? ResponsesMap[K] : never> : never;
10
+ }[keyof ResponsesMap]>, undefined>, ExtractPathParams<Path>, RequestBody extends undefined ? undefined : z.infer<RequestBody>, Query extends undefined ? undefined : z.infer<Query>, SecuritySchemas extends SecurityScheme<infer Caller>[] ? Caller : unknown>;
@@ -1,19 +1,9 @@
1
1
  import { describe, expectTypeOf, it } from "vitest";
2
- import z from "zod";
3
2
  describe("HandlerFromDefinition", () => {
4
- it("can infer handler responses correctly (Empty)", () => {
5
- expectTypeOf().toEqualTypeOf();
6
- });
7
3
  it("can infer handler responses correctly (Json)", () => {
8
- const _data = z.object({
9
- a: z.number(),
10
- });
11
4
  expectTypeOf().toEqualTypeOf();
12
5
  });
13
- it("can infer handler responses correctly (Multiple)", () => {
14
- const _data = z.object({
15
- a: z.number(),
16
- });
6
+ it("can infer handler responses correctly (headers)", () => {
17
7
  expectTypeOf().toEqualTypeOf();
18
8
  });
19
9
  it("can infer caller from auth schema (Basic)", () => {
@@ -1,11 +1,12 @@
1
1
  import z from "zod";
2
2
  import { HttpMethod } from "../../constants/HttpMethods";
3
+ import { HttpStatusCode } from "../../constants/HttpStatusCodes";
3
4
  import { SecurityScheme } from "../../security/SecuritySchema";
4
5
  import { Prettify } from "../../utils/types";
5
6
  import { ApiEndpointDefinition } from "./EndpointDefinition";
6
7
  import { ApiEndpointHandler } from "./EndpointHandler";
7
8
  import { HandlerForDefinition } from "./HandlerFromDefinition";
8
- import { GenericResponse, GenericResponseSchemaMap } from "./responses";
9
+ import { GenericResponseSchemaMap, HandlerResponse } from "./responses";
9
10
  export declare function createApiEndpointHandler<const ResponsesMap extends GenericResponseSchemaMap, const Path extends string, const Method extends HttpMethod, const RequestBody extends z.ZodType | undefined = undefined, const Query extends z.ZodType | undefined = undefined, const SecuritySchemas extends SecurityScheme<unknown>[] = []>(definition: Prettify<ApiEndpointDefinition<Path, Method, RequestBody, Query, ResponsesMap, SecuritySchemas>>, handler: HandlerForDefinition<Path, RequestBody, Query, ResponsesMap, SecuritySchemas>): {
10
11
  definition: {
11
12
  meta: import("./EndpointDefinition").ApiEndpointMeta;
@@ -18,4 +19,8 @@ export declare function createApiEndpointHandler<const ResponsesMap extends Gene
18
19
  };
19
20
  handler: HandlerForDefinition<Path, RequestBody, Query, ResponsesMap, SecuritySchemas>;
20
21
  };
21
- export declare function buildApiEndpointHandler<Handler extends ApiEndpointHandler<Record<string, string>, unknown, unknown, GenericResponse, unknown>>(handler: Handler): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
22
+ export declare function buildApiEndpointHandler<Handler extends ApiEndpointHandler<HandlerResponse<HttpStatusCode, unknown> & {
23
+ headers?: {
24
+ [key: string]: string;
25
+ };
26
+ }, Record<string, string>, unknown, unknown, unknown>>(handler: Handler): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
@@ -1,5 +1,4 @@
1
1
  import expressAsyncHandler from "express-async-handler";
2
- import { isJsonResponse } from "./responses/jsonResponse";
3
2
  export function createApiEndpointHandler(definition, handler) {
4
3
  return {
5
4
  definition,
@@ -16,11 +15,9 @@ export function buildApiEndpointHandler(handler) {
16
15
  body: request.body,
17
16
  caller: response.locals.caller,
18
17
  });
19
- if (isJsonResponse(result)) {
20
- response.status(result.code).json(result.json);
21
- }
22
- else {
23
- response.status(result.code).send();
24
- }
18
+ response
19
+ .status(result.code)
20
+ .set(result.headers ?? {})
21
+ .send(result.data);
25
22
  });
26
23
  }
@@ -6,12 +6,12 @@ export declare const testEndpointBase: {
6
6
  group: string;
7
7
  };
8
8
  method: "get";
9
- requestBodySchema: z.ZodObject<{
10
- name: z.ZodString;
11
- }, z.core.$strip>;
12
9
  path: string;
13
10
  securitySchemes: never[];
14
11
  responseSchemas: {
15
- 200: {};
12
+ 200: {
13
+ type: "json";
14
+ schema: z.ZodString;
15
+ };
16
16
  };
17
17
  };
@@ -1,4 +1,4 @@
1
- import { describe, it } from "vitest";
1
+ import { describe, expect, it } from "vitest";
2
2
  import { createServer } from "../../server";
3
3
  import { createApiEndpointHandler } from "./createApiHandler";
4
4
  import testRequest from "supertest";
@@ -11,22 +11,23 @@ export const testEndpointBase = {
11
11
  group: "test",
12
12
  },
13
13
  method: HttpMethods.get,
14
- requestBodySchema: z.object({
15
- name: z.string(),
16
- }),
17
14
  path: "/test",
18
15
  securitySchemes: [],
19
16
  responseSchemas: {
20
- 200: {},
17
+ 200: {
18
+ type: "json",
19
+ schema: z.string(),
20
+ },
21
21
  },
22
22
  };
23
23
  describe("createApiHandler", () => {
24
- it("can create an API handler", () => {
24
+ it("can create an API handler that responds correctly (json)", async () => {
25
25
  const endpoint = createApiEndpointHandler({
26
26
  ...testEndpointBase,
27
27
  }, async () => {
28
28
  return {
29
29
  code: 200,
30
+ data: "test",
30
31
  };
31
32
  });
32
33
  const server = createServer({
@@ -35,6 +36,38 @@ describe("createApiHandler", () => {
35
36
  logger: false,
36
37
  });
37
38
  server.registerApiEndpoint(endpoint);
38
- testRequest(server.expressApp).get("/test").expect(200);
39
+ const response = await testRequest(server.expressApp).get("/test");
40
+ expect(response.status).toBe(200);
41
+ expect(response.text).toBe("test");
42
+ });
43
+ it("can create an API handler that responds with custom headers", async () => {
44
+ const endpoint = createApiEndpointHandler({
45
+ ...testEndpointBase,
46
+ responseSchemas: {
47
+ 200: {
48
+ type: "json",
49
+ schema: z.string(),
50
+ headers: ["X-Custom-Header"],
51
+ },
52
+ },
53
+ }, async () => {
54
+ return {
55
+ code: 200,
56
+ data: "test",
57
+ headers: {
58
+ "X-Custom-Header": "CustomValue",
59
+ },
60
+ };
61
+ });
62
+ const server = createServer({
63
+ inDevMode: true,
64
+ port: 3000,
65
+ logger: false,
66
+ });
67
+ server.registerApiEndpoint(endpoint);
68
+ const response = await testRequest(server.expressApp).get("/test");
69
+ expect(response.status).toBe(200);
70
+ expect(response.text).toBe("test");
71
+ expect(response.headers["x-custom-header"]).toBe("CustomValue");
39
72
  });
40
73
  });
@@ -1,7 +1,23 @@
1
- import { ClientErrorStatusCode, SuccessStatusCode } from "../../../constants/HttpStatusCodes";
2
- import { EmptyResponse, EmptyResponseSchema } from "./emptyResponse";
3
- import { JsonResponse, JsonResponseSchema } from "./jsonResponse";
1
+ import z from "zod";
2
+ import { HttpStatusCode } from "../../../constants/HttpStatusCodes";
3
+ import { JsonResponseSchema } from "./jsonResponse";
4
+ export type AbstractResponseSchema<Headers extends string[] | undefined = string[] | undefined> = {
5
+ type: string;
6
+ headers?: Headers;
7
+ };
8
+ export type HandlerResponse<Code extends HttpStatusCode, Data> = {
9
+ code: Code;
10
+ data: Data;
11
+ };
12
+ export type GenericResponseSchema = JsonResponseSchema;
4
13
  export type GenericResponseSchemaMap = {
5
- [K in SuccessStatusCode | ClientErrorStatusCode]?: EmptyResponseSchema | JsonResponseSchema | undefined;
14
+ [key in HttpStatusCode]?: GenericResponseSchema;
6
15
  };
7
- export type GenericResponse = EmptyResponse | JsonResponse;
16
+ export type InferHeadersFromSchema<Schema extends AbstractResponseSchema> = Schema extends {
17
+ headers: infer Headers;
18
+ } ? Headers extends string[] ? {
19
+ headers: {
20
+ [K in Headers[number]]: string;
21
+ };
22
+ } : {} : {};
23
+ export type InferResponseFromSchema<Code extends HttpStatusCode, Schema extends GenericResponseSchema> = Schema extends JsonResponseSchema<infer DataSchema> ? HandlerResponse<Code, z.infer<DataSchema>> & InferHeadersFromSchema<Schema> : never;
@@ -1,14 +1,7 @@
1
1
  import z from "zod";
2
- import { HttpStatusCode } from "../../../constants/HttpStatusCodes";
3
- export interface JsonResponseSchema<DataSchema extends z.ZodType = z.ZodType> {
4
- dataType: "application/json";
5
- dataSchema: DataSchema;
2
+ import { AbstractResponseSchema } from ".";
3
+ export interface JsonResponseSchema<DataSchema extends z.ZodType = z.ZodType, Headers extends string[] | undefined = string[] | undefined> extends AbstractResponseSchema<Headers> {
4
+ type: "json";
5
+ schema: DataSchema;
6
6
  }
7
- export interface JsonResponse<Code extends HttpStatusCode = HttpStatusCode, Data = unknown> {
8
- code: Code;
9
- dataType: "application/json";
10
- json: Data;
11
- }
12
- export type JsonResponseSchemaToResponseType<Code extends HttpStatusCode, Schema extends JsonResponseSchema> = Schema extends JsonResponseSchema<infer DataSchema> ? JsonResponse<Code, z.infer<DataSchema>> : never;
13
- export declare function isJsonResponseSchema(value: unknown): value is JsonResponseSchema;
14
- export declare function isJsonResponse(value: unknown): value is JsonResponse;
7
+ export declare function isJsonResponseSchema(value: AbstractResponseSchema): value is JsonResponseSchema;
@@ -1,13 +1,3 @@
1
- import { hasValue } from "../../../utils/typeGuards";
2
1
  export function isJsonResponseSchema(value) {
3
- return (typeof value === "object" &&
4
- hasValue(value) &&
5
- "dataType" in value &&
6
- value.dataType === "application/json");
7
- }
8
- export function isJsonResponse(value) {
9
- return (typeof value === "object" &&
10
- value !== null &&
11
- "dataType" in value &&
12
- value.dataType === "application/json");
2
+ return value.type === "json";
13
3
  }
@@ -13,7 +13,7 @@ export function buildRequestLogger(logger, isInDevMode) {
13
13
  export function buildResponseLogger(logger, isInDevMode) {
14
14
  return (req, res, next) => {
15
15
  const originalSend = res.send;
16
- res.json = function (body) {
16
+ res.send = function (body) {
17
17
  logger.info(`[Response] ${colors.cyan(req.method)} - ${colors.cyan(req.path)} - Status: ${res.statusCode > 299 && res.statusCode < 599 ? colors.red(res.statusCode.toString()) : colors.green(res.statusCode.toString())}`);
18
18
  if (isInDevMode) {
19
19
  logger.info(`[Response - Dev] Body: ${JSON.stringify(body)}`);
@@ -16,6 +16,7 @@ export function buildBasicAuthenticator(scheme) {
16
16
  const base64Credentials = authHeader.slice("Basic ".length);
17
17
  const credentials = Buffer.from(base64Credentials, "base64").toString("utf-8");
18
18
  const [username, password] = credentials.split(":", 2);
19
+ console.log("Decoded credentials:", { username, password });
19
20
  return scheme.validateCaller(username, password);
20
21
  };
21
22
  }
@@ -1,5 +1,5 @@
1
1
  import testRequest from "supertest";
2
- import { describe, it } from "vitest";
2
+ import { describe, expect, it } from "vitest";
3
3
  import { HttpStatusCodes } from "../constants/HttpStatusCodes";
4
4
  import { createApiEndpointHandler } from "../handlers/api/createApiHandler";
5
5
  import { testEndpointBase } from "../handlers/api/createApiHandler.spec";
@@ -8,6 +8,7 @@ import { createBasicAuthSchema } from "./basicAuth";
8
8
  describe("basic auth schema", () => {
9
9
  const testUsername = "Test";
10
10
  const testPassword = "TestPW";
11
+ const encodedCredentials = Buffer.from(`${testUsername}:${testPassword}`).toString("base64");
11
12
  const authScheme = createBasicAuthSchema("TestAuth", async (name, password) => {
12
13
  if (name === testUsername && password === testPassword) {
13
14
  return {
@@ -22,7 +23,7 @@ describe("basic auth schema", () => {
22
23
  ...testEndpointBase,
23
24
  securitySchemes: [authScheme],
24
25
  }, async () => {
25
- return { code: HttpStatusCodes.Ok_200 };
26
+ return { code: HttpStatusCodes.Ok_200, data: "test" };
26
27
  });
27
28
  const server = createServer({
28
29
  port: 3000,
@@ -30,16 +31,16 @@ describe("basic auth schema", () => {
30
31
  logger: false,
31
32
  });
32
33
  server.registerApiEndpoint(endpoint);
33
- it("accepts valid credentials", () => {
34
- testRequest(server.expressApp)
34
+ it("accepts valid credentials", async () => {
35
+ const response = await testRequest(server.expressApp)
35
36
  .get("/test")
36
- .set("Authorization", `Basic ${testUsername}:${testPassword}`)
37
- .expect(HttpStatusCodes.Ok_200);
37
+ .set("Authorization", `Basic ${encodedCredentials}`);
38
+ expect(response.status).toBe(HttpStatusCodes.Ok_200);
38
39
  });
39
- it("rejectes invalid credentials", () => {
40
- testRequest(server.expressApp)
40
+ it("rejects invalid credentials", async () => {
41
+ const response = await testRequest(server.expressApp)
41
42
  .get("/test")
42
- .set("Authorization", `Basic invalid:invalid`)
43
- .expect(HttpStatusCodes.Unauthorized_401);
43
+ .set("Authorization", `Basic INVALID:INVALID`);
44
+ expect(response.status).toBe(HttpStatusCodes.Unauthorized_401);
44
45
  });
45
46
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "transit-kit",
3
- "version": "0.6.2",
3
+ "version": "0.7.0",
4
4
  "description": "A declarative TypeScript framework for building type-safe Express.js APIs with automatic OpenAPI generation",
5
5
  "keywords": [
6
6
  "express",
@@ -1,7 +0,0 @@
1
- import { HttpStatusCode } from "../../../constants/HttpStatusCodes";
2
- export interface EmptyResponseSchema {
3
- }
4
- export interface EmptyResponse<Code extends HttpStatusCode = HttpStatusCode> {
5
- code: Code;
6
- }
7
- export type EmptyResponseSchemaToResponseType<Code extends HttpStatusCode, _ extends EmptyResponseSchema> = EmptyResponse<Code>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import { describe, expectTypeOf, it } from "vitest";
2
- describe("empty response", () => {
3
- it("can correctly infer the response type from schema", () => {
4
- expectTypeOf().toEqualTypeOf();
5
- });
6
- it("can correctly identify a literal with the type", () => {
7
- expectTypeOf().toEqualTypeOf();
8
- });
9
- });
@@ -1,39 +0,0 @@
1
- import { describe, expect, expectTypeOf, it } from "vitest";
2
- import z from "zod";
3
- import { isJsonResponse, isJsonResponseSchema, } from "./jsonResponse";
4
- describe("empty response", () => {
5
- it("can correctly infer the response type from schema", () => {
6
- expectTypeOf().toEqualTypeOf();
7
- });
8
- it("can correctly identify a literal with the type", () => {
9
- expectTypeOf().toEqualTypeOf();
10
- });
11
- it("can correctly validate if a response is of type", () => {
12
- const res = {
13
- dataType: "application/json",
14
- json: "string",
15
- };
16
- expect(isJsonResponse(res)).toBe(true);
17
- });
18
- it("can correctly validate if a response is not of type", () => {
19
- const res = {
20
- dataType: "application/data", //<=== Wrong
21
- json: "string",
22
- };
23
- expect(isJsonResponse(res)).toBe(false);
24
- });
25
- it("can correctly validate if a response schema is of type", () => {
26
- const res = {
27
- dataType: "application/json",
28
- dataSchema: z.string(),
29
- };
30
- expect(isJsonResponseSchema(res)).toBe(true);
31
- });
32
- it("can correctly validate if a response schema is not of type", () => {
33
- const res = {
34
- dataType: "application/data", // <=== Wrong
35
- dataSchema: z.string(),
36
- };
37
- expect(isJsonResponseSchema(res)).toBe(false);
38
- });
39
- });