How to use the @stoplight/prism-core/src/__tests__/utils.assertLeft function in @stoplight/prism-core

To help you get started, we’ve selected a few @stoplight/prism-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / prism / packages / http / src / utils / __tests__ / serializeBody.spec.ts View on Github external
it('fails with proper message', () => {
      const body = { x: {} };
      body.x = { y: body };

      assertLeft(serializeBody(body));
    })
  });
github stoplightio / prism / packages / http / src / mocker / __tests__ / functional.spec.ts View on Github external
test('and that content type does not exist should return a 406 error', () => {
        const mockResult = mock({
          resource: httpOperations[0],
          input: httpRequests[0],
          config: {
            dynamic: false,
            mediaTypes: ['text/funky'],
          },
        })(logger);

        assertLeft(mockResult, e => expect(e).toHaveProperty('status', 406));
      });
    });
github stoplightio / prism / packages / http / src / validator / validators / __tests__ / body.spec.ts View on Github external
it('returns validation errors', () => {
        assertLeft(
          httpBodyValidator.validate(
            encodeURI('key[a][ab]=str'),
            [
              {
                mediaType: 'application/x-www-form-urlencoded',
                encodings: [{ property: 'key', style: HttpParamStyles.DeepObject }],
                schema: {
                  type: 'object',
                  properties: {
                    key: {
                      type: 'object',
                      properties: {
                        a: {
                          type: 'object',
                          properties: { aa: { type: 'string' } },
                          required: ['aa'],
github stoplightio / prism / packages / http / src / validator / __tests__ / functional.spec.ts View on Github external
it('returns only query validation errors', () => {
        assertLeft(
          validateInput({
            resource: httpOperations[2],
            element: BAD_INPUT,
          }),
          error =>
            expect(error).toContainEqual({
              code: 'pattern',
              message: 'should match pattern "^(yes|no)$"',
              path: ['query', 'overwrite'],
              severity: DiagnosticSeverity.Error,
            })
        );
      });
    });
github stoplightio / prism / packages / http / src / mocker / __tests__ / functional.spec.ts View on Github external
test('given that status code is not defined should throw an error', () => {
        const rejection = mock({
          resource: httpOperations[0],
          input: httpRequests[0],
          config: {
            dynamic: false,
            code: '205',
          },
        })(logger);

        assertLeft(rejection, e => expect(e).toHaveProperty('message', 'The server cannot find the requested content'));
      });
github stoplightio / prism / packages / http / src / mocker / negotiator / __tests__ / NegotiatorHelpers.spec.ts View on Github external
it('and example not exist should throw an error', () => {
      const exampleKey = chance.string();
      const partialOptions = {
        code: '200',
        exampleKey,
        dynamic: chance.bool(),
      };
      const httpContent: IMediaTypeContent = {
        mediaType: chance.string(),
        examples: [],
        encodings: [],
      };

      const negotiationResult = helpers.negotiateByPartialOptionsAndHttpContent(partialOptions, httpContent);
      assertLeft(negotiationResult, e => {
        expect(e.message).toBe('The server cannot find the requested content');
      });
    });
  });
github stoplightio / prism / packages / http / src / validator / validators / __tests__ / headers.spec.ts View on Github external
it('returns deprecation warning', () => {
            assertLeft(
              httpHeadersValidator.validate({ 'x-test-header': 'abc' }, [
                {
                  name: 'x-test-header',
                  deprecated: true,
                  style: HttpParamStyles.Simple,
                },
              ]),
              error => expect(error).toContainEqual(expect.objectContaining({ severity: DiagnosticSeverity.Warning }))
            );
          });
        });
github stoplightio / prism / packages / http / src / mocker / negotiator / __tests__ / NegotiatorHelpers.spec.ts View on Github external
it('given no 2xx response should throw exception', () => {
      const desiredOptions = { dynamic: false };
      jest.spyOn(helpers, 'negotiateOptionsBySpecificResponse');

      const negotiationResult = helpers.negotiateOptionsForDefaultCode(httpOperation, desiredOptions)(logger);
      assertLeft(negotiationResult, e => {
        expect(e.message).toBe('No 2** response defined, cannot mock');
      });
    });
  });
github stoplightio / prism / packages / http / src / validator / __tests__ / index.spec.ts View on Github external
const validationResult = validator.validateInput({
    resource: Object.assign(
      {
        method: 'get',
        path: '/',
        id: '1',
        request: {},
        responses: [{ code: '200' }],
      },
      resourceExtension
    ),
    element: Object.assign({ method: 'get', url: { path: '/', query: {} } }, inputExtension),
  });
  length === 0
    ? assertRight(validationResult)
    : assertLeft(validationResult, error => expect(error).toHaveLength(length));
};
github stoplightio / prism / packages / http / src / mocker / negotiator / __tests__ / NegotiatorHelpers.spec.ts View on Github external
const httpResponseSchema: IHttpOperationResponse = {
            code: '200',
            contents: [
              {
                mediaType: 'text/plain',
              },
            ],
          };

          const actualResponse = helpers.negotiateOptionsBySpecificResponse(
            { ...httpOperation, responses: [{ code: '200', contents: [{ mediaType: 'text/plain ' }] }] },
            desiredOptions,
            httpResponseSchema
          )(logger);

          assertLeft(actualResponse, e =>
            expect(e.message).toBe('The server cannot produce a representation for your accept header')
          );
        });
      });