Socket
Book a DemoInstallSign in
Socket

@smartlyio/oats-nock-adapter

Package Overview
Dependencies
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smartlyio/oats-nock-adapter

nock server adapter for smartlyio/oats s

7.6.1
latest
Source
npmnpm
Version published
Weekly downloads
108
575%
Maintainers
1
Weekly downloads
 
Created
Source

Nock server adapter for smartlyio/oats

Nock adapter for creating mock servers from openapi definitions using oats.

To mock the request POST /item define the route as for any oats server adapter and then bind the route defining object to the nock adapter. The bound mock servers are namespaced using the OpenApi server strings as nock basepaths so that multiple nock mocks can be used simultanenously so long as the basepaths differ. All of the mocked routes are persisted so any number of requests are served.

// yarn ts-node examples/example.ts
import * as nockAdapter from '../src/nock';
import * as api from '../tmp/client.types.generated';
import * as types from '../tmp/openapi.types.generated';
import * as runtime from '@smartlyio/oats-runtime';

nockAdapter.bind(api.createRouter(), {
  '/item': {
    post: async ctx => {
      return runtime.json(
        201,
        types.typeItem
          .maker({
            id: ctx.body.value.id + ' response',
            name: ctx.body.value.name
          })
          .success()
      );
    }
  }
});

The bind call is just a constructor for a Server class that provides a mock method for adding new mocked routes or overlaying new handlers on top of already mocked routes. If the overlaying mock throws Next the previous mock for the route is called instead.

// yarn ts-node examples/server.ts
import * as nockAdapter from '../src/nock';
import * as api from '../tmp/client.types.generated';
import * as types from '../tmp/openapi.types.generated';
import * as runtime from '@smartlyio/oats-runtime';

const server = nockAdapter.bind(api.createRouter(), {
  '/item': {
    post: async ctx => {
      return runtime.json(201, types.typeItem.maker(ctx.body.value).success());
    }
  }
});

server.mock({
  '/item': {
    post: async () => {
      throw new nockAdapter.Next();
    }
  }
});

Keywords

oats

FAQs

Package last updated on 23 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.