@ehuelsmann/jest-openapi 0.16.3 → 0.17.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.
package/dist/index.js CHANGED
@@ -120,10 +120,7 @@ function getExpectReceivedToSatisfyApiSpecMsg(actualResponse, openApiSpec, valid
120
120
  );
121
121
  }
122
122
  if (validationError.code === import_openapi_validator.ErrorCode.StatusNotFound) {
123
- const expectedResponseOperation = (
124
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
- openApiSpec.findExpectedResponseOperation(req)
126
- );
123
+ const expectedResponseOperation = openApiSpec.findExpectedResponseOperation(req);
127
124
  const expectedResponseStatuses = Object.keys(
128
125
  expectedResponseOperation.responses
129
126
  ).join(", ");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/matchers/toSatisfyApiSpec.ts","../src/utils.ts","../src/matchers/toSatisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport toSatisfyApiSpec from './matchers/toSatisfyApiSpec';\nimport toSatisfySchemaInApiSpec from './matchers/toSatisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R> {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n toSatisfyApiSpec(): R;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n toSatisfySchemaInApiSpec(schemaName: string): R;\n }\n }\n}\n\nexport default function (filepathOrObject: string | OpenAPISpecObject): void {\n const openApiSpec = makeApiSpec(filepathOrObject);\n\n const jestMatchers: jest.ExpectExtendMap = {\n toSatisfyApiSpec(received: unknown) {\n return toSatisfyApiSpec.call(this, received, openApiSpec);\n },\n toSatisfySchemaInApiSpec(received: unknown, schemaName: string) {\n return toSatisfySchemaInApiSpec.call(\n this,\n received,\n schemaName,\n openApiSpec,\n );\n },\n };\n\n const jestExpect = (global as { expect?: jest.Expect }).expect;\n\n /* istanbul ignore next */\n if (jestExpect !== undefined) {\n jestExpect.extend(jestMatchers);\n } else {\n // eslint-disable-next-line no-console\n console.error(\n [\n \"Unable to find Jest's global expect.\",\n 'Please check you have configured jest-openapi correctly.',\n 'See https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#usage for help.',\n ].join('\\n'),\n );\n }\n /* istanbul ignore next */\n}\n","import {\n EXPECTED_COLOR,\n matcherHint,\n MatcherHintOptions,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n RawResponse,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const actualResponse = makeResponse(received as RawResponse);\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a response defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfyApiSpec',\n undefined,\n '',\n matcherHintOptions,\n );\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching servers`,\n `Servers found in API spec: ${EXPECTED_COLOR((openApiSpec as OpenApi3Spec).getServerUrls().join(', '))}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has basePath ${EXPECTED_COLOR((openApiSpec as OpenApi2Spec).spec.basePath)}`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n // prettier-ignore\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching path`,\n `Paths found in API spec: ${EXPECTED_COLOR(openApiSpec.paths().join(', '))}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n // prettier-ignore\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request method ${RECEIVED_COLOR(method)}, but your API spec has no ${RECEIVED_COLOR(method)} operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${EXPECTED_COLOR(expectedRequestOperations)}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had status ${RECEIVED_COLOR(status)}, but your API spec has no ${RECEIVED_COLOR(status)} response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(expectedResponseStatuses)}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import {\n EXPECTED_COLOR,\n matcherErrorMessage,\n matcherHint,\n MatcherHintOptions,\n printExpected,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n schemaName: string,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a schema defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfySchemaInApiSpec',\n undefined,\n 'schemaName',\n matcherHintOptions,\n );\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n throw new Error(\n matcherErrorMessage(\n hint,\n `${EXPECTED_COLOR('schemaName')} must match a schema in your API spec`,\n printWithType('schemaName', schemaName, printExpected),\n ),\n );\n }\n\n const validationError = openApiSpec.validateObject(received, schema);\n const pass = !validationError;\n\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4BAA+C;;;ACA/C,gCAKO;AACP,+BASO;;;ACfP,kBAAwB;AAEjB,IAAM,YAAY,CAAC,YACxB,qBAAQ,KAAK,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C;AAAA,EAC9E;AACF;AAEA,SAAS,gDACP,UACA,YACA,QACA,MACQ;AAER,SAAO;AAAA,IACL;AAAA,IACA,gBAAY,2CAAe,UAAU,CAAC,wBAAwB,UAAU;AAAA,IACxE,OAAG,2CAAe,UAAU,CAAC,aAAS,2CAAe,UAAU,QAAQ,CAAC,CAAC;AAAA,IACzE,QAAQ,UAAU,6BAAyB,2CAAe,UAAU,MAAM,CAAC,CAAC;AAAA,EAC9E;AACF;;;AH7Ee,SAAR,cAAkB,kBAAoD;AAC3E,QAAM,kBAAc,uCAAY,gBAAgB;AAEhD,QAAM,eAAqC;AAAA,IACzC,iBAAiB,UAAmB;AAClC,aAAO,yBAAiB,KAAK,MAAM,UAAU,WAAW;AAAA,IAC1D;AAAA,IACA,yBAAyB,UAAmB,YAAoB;AAC9D,aAAO,iCAAyB;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAc,OAAoC;AAGxD,MAAI,eAAe,QAAW;AAC5B,eAAW,OAAO,YAAY;AAAA,EAChC,OAAO;AAEL,YAAQ;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF,EAAE,KAAK,IAAI;AAAA,IACb;AAAA,EACF;AAEF;","names":["import_openapi_validator","import_jest_matcher_utils"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/matchers/toSatisfyApiSpec.ts","../src/utils.ts","../src/matchers/toSatisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport toSatisfyApiSpec from './matchers/toSatisfyApiSpec';\nimport toSatisfySchemaInApiSpec from './matchers/toSatisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R> {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n toSatisfyApiSpec(): R;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n toSatisfySchemaInApiSpec(schemaName: string): R;\n }\n }\n}\n\nexport default function (filepathOrObject: string | OpenAPISpecObject): void {\n const openApiSpec = makeApiSpec(filepathOrObject);\n\n const jestMatchers: jest.ExpectExtendMap = {\n toSatisfyApiSpec(received: unknown) {\n return toSatisfyApiSpec.call(this, received, openApiSpec);\n },\n toSatisfySchemaInApiSpec(received: unknown, schemaName: string) {\n return toSatisfySchemaInApiSpec.call(\n this,\n received,\n schemaName,\n openApiSpec,\n );\n },\n };\n\n const jestExpect = (global as { expect?: jest.Expect }).expect;\n\n /* istanbul ignore next */\n if (jestExpect !== undefined) {\n jestExpect.extend(jestMatchers);\n } else {\n // eslint-disable-next-line no-console\n console.error(\n [\n \"Unable to find Jest's global expect.\",\n 'Please check you have configured jest-openapi correctly.',\n 'See https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#usage for help.',\n ].join('\\n'),\n );\n }\n /* istanbul ignore next */\n}\n","import {\n EXPECTED_COLOR,\n matcherHint,\n MatcherHintOptions,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n RawResponse,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const actualResponse = makeResponse(received as RawResponse);\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a response defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfyApiSpec',\n undefined,\n '',\n matcherHintOptions,\n );\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching servers`,\n `Servers found in API spec: ${EXPECTED_COLOR((openApiSpec as OpenApi3Spec).getServerUrls().join(', '))}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has basePath ${EXPECTED_COLOR((openApiSpec as OpenApi2Spec).spec.basePath)}`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n // prettier-ignore\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching path`,\n `Paths found in API spec: ${EXPECTED_COLOR(openApiSpec.paths().join(', '))}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n // prettier-ignore\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request method ${RECEIVED_COLOR(method)}, but your API spec has no ${RECEIVED_COLOR(method)} operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${EXPECTED_COLOR(expectedRequestOperations)}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n \n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had status ${RECEIVED_COLOR(status)}, but your API spec has no ${RECEIVED_COLOR(status)} response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(expectedResponseStatuses)}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import {\n EXPECTED_COLOR,\n matcherErrorMessage,\n matcherHint,\n MatcherHintOptions,\n printExpected,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n schemaName: string,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a schema defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfySchemaInApiSpec',\n undefined,\n 'schemaName',\n matcherHintOptions,\n );\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n throw new Error(\n matcherErrorMessage(\n hint,\n `${EXPECTED_COLOR('schemaName')} must match a schema in your API spec`,\n printWithType('schemaName', schemaName, printExpected),\n ),\n );\n }\n\n const validationError = openApiSpec.validateObject(received, schema);\n const pass = !validationError;\n\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4BAA+C;;;ACA/C,gCAKO;AACP,+BASO;;;ACfP,kBAAwB;AAEjB,IAAM,YAAY,CAAC,YACxB,qBAAQ,KAAK,EAAE,YAAY,OAAO,OAAO,KAAK,CAAC;AAE1C,IAAM,mBAAmB,IAAI,UAClC,MAAM,KAAK,MAAM;;;ADYJ,SAAR,yBAEL,UACA,aAC0B;AAC1B,QAAM,qBAAiB,uCAAa,QAAuB;AAE3D,QAAM,kBAAkB,YAAY,iBAAiB,cAAc;AACnE,QAAM,OAAO,CAAC;AAEd,QAAM,qBAAyC;AAAA,IAC7C,SACE;AAAA,IACF,GAAI,KAAK,UAAU,UAAa,EAAE,OAAO,KAAK,MAAM;AAAA,IACpD,GAAI,KAAK,YAAY,UAAa,EAAE,SAAS,KAAK,QAAQ;AAAA,EAC5D;AACA,QAAM,WAAO;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,UAAU,OACZ,MACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,EACF,IACF,MACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEN,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,qCACP,gBACA,aACA,iBACA,MACQ;AACR,QAAM,EAAE,QAAQ,IAAI,IAAI;AACxB,QAAM,EAAE,QAAQ,MAAM,YAAY,IAAI;AACtC,QAAM,oBAAoB,GAAG,MAAM,IAAI,WAAW;AAElD,MAAI,gBAAgB,SAAS,mCAAU,gBAAgB;AAErD,WAAO;AAAA,MACL;AAAA,MACA,gBAAY,0CAAe,UAAU,CAAC,kBAAkB,MAAM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,QACA,iBACA,MACQ;AAER,SAAO;AAAA,IACL;AAAA,IACA,gBAAY,2CAAe,UAAU,CAAC,oBAAoB,UAAU;AAAA,IACpE,OAAG,2CAAe,UAAU,CAAC,gCAAgC,eAAe;AAAA,IAC5E,OAAG,2CAAe,UAAU,CAAC,aAAS,2CAAe,UAAU,QAAQ,CAAC,CAAC;AAAA,IACzE,QAAQ,UAAU,6BAAyB,2CAAe,UAAU,MAAM,CAAC,CAAC;AAAA,EAC9E;AACF;AAEA,SAAS,gDACP,UACA,YACA,QACA,MACQ;AAER,SAAO;AAAA,IACL;AAAA,IACA,gBAAY,2CAAe,UAAU,CAAC,wBAAwB,UAAU;AAAA,IACxE,OAAG,2CAAe,UAAU,CAAC,aAAS,2CAAe,UAAU,QAAQ,CAAC,CAAC;AAAA,IACzE,QAAQ,UAAU,6BAAyB,2CAAe,UAAU,MAAM,CAAC,CAAC;AAAA,EAC9E;AACF;;;AH7Ee,SAAR,cAAkB,kBAAoD;AAC3E,QAAM,kBAAc,uCAAY,gBAAgB;AAEhD,QAAM,eAAqC;AAAA,IACzC,iBAAiB,UAAmB;AAClC,aAAO,yBAAiB,KAAK,MAAM,UAAU,WAAW;AAAA,IAC1D;AAAA,IACA,yBAAyB,UAAmB,YAAoB;AAC9D,aAAO,iCAAyB;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAc,OAAoC;AAGxD,MAAI,eAAe,QAAW;AAC5B,eAAW,OAAO,YAAY;AAAA,EAChC,OAAO;AAEL,YAAQ;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF,EAAE,KAAK,IAAI;AAAA,IACb;AAAA,EACF;AAEF;","names":["import_openapi_validator","import_jest_matcher_utils"]}
package/dist/index.mjs CHANGED
@@ -103,10 +103,7 @@ function getExpectReceivedToSatisfyApiSpecMsg(actualResponse, openApiSpec, valid
103
103
  );
104
104
  }
105
105
  if (validationError.code === ErrorCode.StatusNotFound) {
106
- const expectedResponseOperation = (
107
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
108
- openApiSpec.findExpectedResponseOperation(req)
109
- );
106
+ const expectedResponseOperation = openApiSpec.findExpectedResponseOperation(req);
110
107
  const expectedResponseStatuses = Object.keys(
111
108
  expectedResponseOperation.responses
112
109
  ).join(", ");
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/matchers/toSatisfyApiSpec.ts","../src/utils.ts","../src/matchers/toSatisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport toSatisfyApiSpec from './matchers/toSatisfyApiSpec';\nimport toSatisfySchemaInApiSpec from './matchers/toSatisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R> {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n toSatisfyApiSpec(): R;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n toSatisfySchemaInApiSpec(schemaName: string): R;\n }\n }\n}\n\nexport default function (filepathOrObject: string | OpenAPISpecObject): void {\n const openApiSpec = makeApiSpec(filepathOrObject);\n\n const jestMatchers: jest.ExpectExtendMap = {\n toSatisfyApiSpec(received: unknown) {\n return toSatisfyApiSpec.call(this, received, openApiSpec);\n },\n toSatisfySchemaInApiSpec(received: unknown, schemaName: string) {\n return toSatisfySchemaInApiSpec.call(\n this,\n received,\n schemaName,\n openApiSpec,\n );\n },\n };\n\n const jestExpect = (global as { expect?: jest.Expect }).expect;\n\n /* istanbul ignore next */\n if (jestExpect !== undefined) {\n jestExpect.extend(jestMatchers);\n } else {\n // eslint-disable-next-line no-console\n console.error(\n [\n \"Unable to find Jest's global expect.\",\n 'Please check you have configured jest-openapi correctly.',\n 'See https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#usage for help.',\n ].join('\\n'),\n );\n }\n /* istanbul ignore next */\n}\n","import {\n EXPECTED_COLOR,\n matcherHint,\n MatcherHintOptions,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n RawResponse,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const actualResponse = makeResponse(received as RawResponse);\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a response defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfyApiSpec',\n undefined,\n '',\n matcherHintOptions,\n );\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching servers`,\n `Servers found in API spec: ${EXPECTED_COLOR((openApiSpec as OpenApi3Spec).getServerUrls().join(', '))}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has basePath ${EXPECTED_COLOR((openApiSpec as OpenApi2Spec).spec.basePath)}`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n // prettier-ignore\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching path`,\n `Paths found in API spec: ${EXPECTED_COLOR(openApiSpec.paths().join(', '))}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n // prettier-ignore\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request method ${RECEIVED_COLOR(method)}, but your API spec has no ${RECEIVED_COLOR(method)} operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${EXPECTED_COLOR(expectedRequestOperations)}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had status ${RECEIVED_COLOR(status)}, but your API spec has no ${RECEIVED_COLOR(status)} response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(expectedResponseStatuses)}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import {\n EXPECTED_COLOR,\n matcherErrorMessage,\n matcherHint,\n MatcherHintOptions,\n printExpected,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n schemaName: string,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a schema defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfySchemaInApiSpec',\n undefined,\n 'schemaName',\n matcherHintOptions,\n );\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n throw new Error(\n matcherErrorMessage(\n hint,\n `${EXPECTED_COLOR('schemaName')} must match a schema in your API spec`,\n printWithType('schemaName', schemaName, printExpected),\n ),\n );\n }\n\n const validationError = openApiSpec.validateObject(received, schema);\n const pass = !validationError;\n\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n"],"mappings":";AAAA,SAAS,mBAAsC;;;ACA/C;AAAA,EACE;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OAMK;;;ACfP,SAAS,eAAe;AAEjB,IAAM,YAAY,CAAC,QACxB,QAAQ,KAAK,EAAE,YAAY,OAAO,OAAO,KAAK,CAAC;AAE1C,IAAM,mBAAmB,IAAI,UAClC,MAAM,KAAK,MAAM;;;ADYJ,SAAR,yBAEL,UACA,aAC0B;AAC1B,QAAM,iBAAiB,aAAa,QAAuB;AAE3D,QAAM,kBAAkB,YAAY,iBAAiB,cAAc;AACnE,QAAM,OAAO,CAAC;AAEd,QAAM,qBAAy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;AAAA,IACzE,QAAQ,UAAU,yBAAyBD,gBAAe,UAAU,MAAM,CAAC,CAAC;AAAA,EAC9E;AACF;;;AH7Ee,SAAR,cAAkB,kBAAoD;AAC3E,QAAM,cAAc,YAAY,gBAAgB;AAEhD,QAAM,eAAqC;AAAA,IACzC,iBAAiB,UAAmB;AAClC,aAAO,yBAAiB,KAAK,MAAM,UAAU,WAAW;AAAA,IAC1D;AAAA,IACA,yBAAyB,UAAmB,YAAoB;AAC9D,aAAO,iCAAyB;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAc,OAAoC;AAGxD,MAAI,eAAe,QAAW;AAC5B,eAAW,OAAO,YAAY;AAAA,EAChC,OAAO;AAEL,YAAQ;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF,EAAE,KAAK,IAAI;AAAA,IACb;AAAA,EACF;AAEF;","names":["EXPECTED_COLOR","matcherHint","RECEIVED_COLOR","matcherHint","EXPECTED_COLOR","RECEIVED_COLOR"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/matchers/toSatisfyApiSpec.ts","../src/utils.ts","../src/matchers/toSatisfySchemaInApiSpec.ts"],"sourcesContent":["import { makeApiSpec, OpenAPISpecObject } from '@ehuelsmann/openapi-validator';\nimport toSatisfyApiSpec from './matchers/toSatisfyApiSpec';\nimport toSatisfySchemaInApiSpec from './matchers/toSatisfySchemaInApiSpec';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R> {\n /**\n * Check the HTTP response object satisfies a response defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-api-tests-validate-the-status-and-body-of-http-responses-against-your-openapi-spec)\n */\n toSatisfyApiSpec(): R;\n /**\n * Check the object satisfies a schema defined in your OpenAPI spec.\n * [See usage example](https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#in-unit-tests-validate-objects-against-schemas-defined-in-your-openapi-spec)\n */\n toSatisfySchemaInApiSpec(schemaName: string): R;\n }\n }\n}\n\nexport default function (filepathOrObject: string | OpenAPISpecObject): void {\n const openApiSpec = makeApiSpec(filepathOrObject);\n\n const jestMatchers: jest.ExpectExtendMap = {\n toSatisfyApiSpec(received: unknown) {\n return toSatisfyApiSpec.call(this, received, openApiSpec);\n },\n toSatisfySchemaInApiSpec(received: unknown, schemaName: string) {\n return toSatisfySchemaInApiSpec.call(\n this,\n received,\n schemaName,\n openApiSpec,\n );\n },\n };\n\n const jestExpect = (global as { expect?: jest.Expect }).expect;\n\n /* istanbul ignore next */\n if (jestExpect !== undefined) {\n jestExpect.extend(jestMatchers);\n } else {\n // eslint-disable-next-line no-console\n console.error(\n [\n \"Unable to find Jest's global expect.\",\n 'Please check you have configured jest-openapi correctly.',\n 'See https://github.com/openapi-library/OpenAPIValidators/tree/master/packages/jest-openapi#usage for help.',\n ].join('\\n'),\n );\n }\n /* istanbul ignore next */\n}\n","import {\n EXPECTED_COLOR,\n matcherHint,\n MatcherHintOptions,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport {\n ActualResponse,\n ErrorCode,\n makeResponse,\n OpenApi2Spec,\n OpenApi3Spec,\n OpenApiSpec,\n RawResponse,\n ValidationError,\n} from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const actualResponse = makeResponse(received as RawResponse);\n\n const validationError = openApiSpec.validateResponse(actualResponse);\n const pass = !validationError;\n\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a response defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfyApiSpec',\n undefined,\n '',\n matcherHintOptions,\n );\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse,\n openApiSpec,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n validationError: ValidationError,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const { method, path: requestPath } = req;\n const unmatchedEndpoint = `${method} ${requestPath}`;\n\n if (validationError.code === ErrorCode.ServerNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching servers`,\n `Servers found in API spec: ${EXPECTED_COLOR((openApiSpec as OpenApi3Spec).getServerUrls().join(', '))}`,\n );\n }\n\n if (validationError.code === ErrorCode.BasePathNotFound) {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has basePath ${EXPECTED_COLOR((openApiSpec as OpenApi2Spec).spec.basePath)}`,\n );\n }\n\n if (validationError.code === ErrorCode.PathNotFound) {\n // prettier-ignore\n const pathNotFoundErrorMessage = joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${unmatchedEndpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request path ${RECEIVED_COLOR(requestPath)}, but your API spec has no matching path`,\n `Paths found in API spec: ${EXPECTED_COLOR(openApiSpec.paths().join(', '))}`,\n );\n\n if (\n 'didUserDefineBasePath' in openApiSpec &&\n openApiSpec.didUserDefineBasePath\n ) {\n // prettier-ignore\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches basePath \\`${openApiSpec.spec.basePath}\\` but no <basePath/endpointPath> combinations`,\n );\n }\n\n if (\n 'didUserDefineServers' in openApiSpec &&\n openApiSpec.didUserDefineServers\n ) {\n return joinWithNewLines(\n pathNotFoundErrorMessage,\n `'${requestPath}' matches servers ${stringify(\n openApiSpec.getMatchingServerUrls(requestPath),\n )} but no <server/endpointPath> combinations`,\n );\n }\n return pathNotFoundErrorMessage;\n }\n\n const path = openApiSpec.findOpenApiPathMatchingRequest(req);\n const endpoint = `${method} ${path}`;\n\n if (validationError.code === ErrorCode.MethodNotFound) {\n const expectedPathItem = openApiSpec.findExpectedPathItem(req);\n const expectedRequestOperations = Object.keys(expectedPathItem)\n .map((operation) => operation.toUpperCase())\n .join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had request method ${RECEIVED_COLOR(method)}, but your API spec has no ${RECEIVED_COLOR(method)} operation defined for path '${path}'`,\n `Request operations found for path '${path}' in API spec: ${EXPECTED_COLOR(expectedRequestOperations)}`,\n );\n }\n\n if (validationError.code === ErrorCode.StatusNotFound) {\n const expectedResponseOperation =\n \n openApiSpec.findExpectedResponseOperation(req)!;\n const expectedResponseStatuses = Object.keys(\n expectedResponseOperation.responses,\n ).join(', ');\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy a '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} had status ${RECEIVED_COLOR(status)}, but your API spec has no ${RECEIVED_COLOR(status)} response defined for endpoint '${endpoint}'`,\n `Response statuses found for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(expectedResponseStatuses)}`,\n );\n }\n\n // validationError.code === ErrorCode.InvalidBody\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfyApiSpecMsg(\n actualResponse: ActualResponse,\n openApiSpec: OpenApiSpec,\n hint: string,\n): string {\n const { status, req } = actualResponse;\n const responseDefinition = openApiSpec.findExpectedResponse(actualResponse);\n const endpoint = `${req.method} ${openApiSpec.findOpenApiPathMatchingRequest(\n req,\n )}`;\n\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${status}' response defined for endpoint '${endpoint}' in your API spec`,\n `${RECEIVED_COLOR('received')} contained: ${RECEIVED_COLOR(actualResponse.toString())}`,\n `The '${status}' response defined for endpoint '${endpoint}' in API spec: ${EXPECTED_COLOR(stringify(responseDefinition))}`,\n );\n}\n","import { inspect } from 'util';\n\nexport const stringify = (obj: unknown): string =>\n inspect(obj, { showHidden: false, depth: null });\n\nexport const joinWithNewLines = (...lines: string[]): string =>\n lines.join('\\n\\n');\n","import {\n EXPECTED_COLOR,\n matcherErrorMessage,\n matcherHint,\n MatcherHintOptions,\n printExpected,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport type { OpenApiSpec, Schema, ValidationError } from '@ehuelsmann/openapi-validator';\nimport { joinWithNewLines, stringify } from '../utils';\n\nexport default function (\n this: jest.MatcherContext,\n received: unknown,\n schemaName: string,\n openApiSpec: OpenApiSpec,\n): jest.CustomMatcherResult {\n const matcherHintOptions: MatcherHintOptions = {\n comment:\n \"Matches 'received' to a schema defined in your API spec, then validates 'received' against it\",\n ...(this.isNot !== undefined && { isNot: this.isNot }),\n ...(this.promise !== undefined && { promise: this.promise }),\n };\n const hint = matcherHint(\n 'toSatisfySchemaInApiSpec',\n undefined,\n 'schemaName',\n matcherHintOptions,\n );\n\n const schema = openApiSpec.getSchemaObject(schemaName);\n if (!schema) {\n // alert users they are misusing this assertion\n throw new Error(\n matcherErrorMessage(\n hint,\n `${EXPECTED_COLOR('schemaName')} must match a schema in your API spec`,\n printWithType('schemaName', schemaName, printExpected),\n ),\n );\n }\n\n const validationError = openApiSpec.validateObject(received, schema);\n const pass = !validationError;\n\n const message = pass\n ? () =>\n getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n hint,\n )\n : () =>\n getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received,\n schemaName,\n schema,\n validationError,\n hint,\n );\n\n return {\n pass,\n message,\n };\n}\n\nfunction getExpectReceivedToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n validationError: ValidationError,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} did not satisfy it because: ${validationError}`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n\nfunction getExpectReceivedNotToSatisfySchemaInApiSpecMsg(\n received: unknown,\n schemaName: string,\n schema: Schema,\n hint: string,\n): string {\n // prettier-ignore\n return joinWithNewLines(\n hint,\n `expected ${RECEIVED_COLOR('received')} not to satisfy the '${schemaName}' schema defined in your API spec`,\n `${RECEIVED_COLOR('received')} was: ${RECEIVED_COLOR(stringify(received))}`,\n `The '${schemaName}' schema in API spec: ${EXPECTED_COLOR(stringify(schema))}`,\n );\n}\n"],"mappings":";AAAA,SAAS,mBAAsC;;;ACA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,UAAU,CAAC,gCAAgC,eAAe;AAAA,IAC5E,GAAGA,gBAAe,UAAU,CAAC,SAASA,gBAAe,UAAU,QAAQ,CAAC,CAAC;AAAA,IACzE,QAAQ,UAAU,yBAAyBD,gBAAe,UAAU,MAAM,CAAC,CAAC;AAAA,EAC9E;AACF;AAEA,SAAS,gDACP,UACA,YACA,QACA,MACQ;AAER,SAAO;AAAA,IACL;AAAA,IACA,YAAYC,gBAAe,UAAU,CAAC,wBAAwB,UAAU;AAAA,IACxE,GAAGA,gBAAe,UAAU,CAAC,SAASA,gBAAe,UAAU,QAAQ,CAAC,CAAC;AAAA,IACzE,QAAQ,UAAU,yBAAyBD,gBAAe,UAAU,MAAM,CAAC,CAAC;AAAA,EAC9E;AACF;;;AH7Ee,SAAR,cAAkB,kBAAoD;AAC3E,QAAM,cAAc,YAAY,gBAAgB;AAEhD,QAAM,eAAqC;AAAA,IACzC,iBAAiB,UAAmB;AAClC,aAAO,yBAAiB,KAAK,MAAM,UAAU,WAAW;AAAA,IAC1D;AAAA,IACA,yBAAyB,UAAmB,YAAoB;AAC9D,aAAO,iCAAyB;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,aAAc,OAAoC;AAGxD,MAAI,eAAe,QAAW;AAC5B,eAAW,OAAO,YAAY;AAAA,EAChC,OAAO;AAEL,YAAQ;AAAA,MACN;AAAA,QACE;AAAA,QACA;AAAA,QACA;AAAA,MACF,EAAE,KAAK,IAAI;AAAA,IACb;AAAA,EACF;AAEF;","names":["EXPECTED_COLOR","matcherHint","RECEIVED_COLOR","matcherHint","EXPECTED_COLOR","RECEIVED_COLOR"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ehuelsmann/jest-openapi",
3
- "version": "0.16.3",
3
+ "version": "0.17.0",
4
4
  "description": "Jest matchers for asserting that HTTP responses satisfy an OpenAPI spec",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -63,8 +63,8 @@
63
63
  "@types/jest": "^30.0.0",
64
64
  "@types/supertest": "^7.2.0",
65
65
  "axios": "^1.15.2",
66
- "eslint": "^7.11.0",
67
- "eslint-plugin-jest": "^27.9.0",
66
+ "eslint": "^10.0.0",
67
+ "eslint-plugin-jest": "^29.0.0",
68
68
  "express": "^5.2.1",
69
69
  "fs-extra": "^9.0.1",
70
70
  "jest": "^30.3.0",
@@ -74,7 +74,7 @@
74
74
  "tsup": "^8.5.1"
75
75
  },
76
76
  "dependencies": {
77
- "@ehuelsmann/openapi-validator": "^0.16.3",
78
- "jest-matcher-utils": "^29.0.0"
77
+ "@ehuelsmann/openapi-validator": "^0.17.0",
78
+ "jest-matcher-utils": "^30.0.0"
79
79
  }
80
80
  }