oat

2.0.9 • Public • Published

OAT

(greatest) Open Api Test library of all times!

npm version npm downloads bundle JSDocs License

The oat package makes it very easy to test your API with an OpenAPI specification. It:

  • 🤝 validates request and response parameter
  • 🧬 generates multiple tests based on different security or parameter combinations
  • 🧩 is compatible to all JavaScript testrunner
  • 🚀 integration to Faker.js for easy payload generation
  • ⚡ supports referencing response values from other API tests

Example

The following example shows a simple API test using Vitest:

import { describe, it } from 'vitest'
import { Testplan, URLParam, APIKeyAuth, QueryParam } from 'oat'
import type { OpenAPIV3 } from 'openapi-types'

import { specification } from './openapi-specification.json' assert { type: 'json' }

const urlParam = new URLParam({ id: '39f07889-1072-48df-8ca6-9d6726b5e525' })
const apiToken = new APIKeyAuth('Authorization', 'codeless-qa-b82b312d-4d44-40a3-bb5a-02529417e2d7', 'header')
const userQuery = new QueryParam({
  /**
   * resolves to the body value with the JSON path "specification.owner" of the first 200 response of
   * request with the `operationId` "getUsers", e.g. in this example the owner of the specification
   */
  name: '#/getSpecification/200/body/specification.owner'
})

const plan = new Testplan(specification as OpenAPIV3.Document)
plan.usingServer('http://api.server.com')

describe('/api/specifications/{id}', () => {
  plan.runTest('delete', '/api/specifications/{id}')
    .withPayloads(urlParam)
    .expect(401) // fails due to missing auth
  plan.runTest('get', '/api/specifications/{id}')
    .withSecuritySchemes([apiToken])
    .withPayloads(urlParam)
    .expect(200)
  plan.runWith(it)
})

describe('/api/users/{id}', () => {
  plan.runTest('get', '/api/users')
    .withSecuritySchemes([apiToken])
    .withPayloads(userQuery)
    .expect(200)
  plan.runWith(it)
})

The Oat library is can be used with any TDD test framework, e.g. Mocha, Jasmine, Jest, Node Tap or the built-in Node.js testrunner.

Install

Install the package via:

npm i oat

Documentation

For more details on how to use Oat, check out our documentation.

License

Apache 2 License © 2024-PRESENT CodelessQA

Readme

Keywords

none

Package Sidebar

Install

npm i oat

Weekly Downloads

103

Version

2.0.9

License

Apache-2.0

Unpacked Size

1.08 MB

Total Files

17

Last publish

Collaborators

  • christian-bromann