2.0.12 • Published 4 months ago
oat v2.0.12
OAT
(greatest) Open Api Test library of all times!
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' with { type: 'json' }
const urlParam = new URLParam({ id: '39f07889-1072-48df-8ca6-9d6726b5e525' })
const apiToken = new APIKeyAuth('Authorization', 'vollq-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
2.0.5
7 months ago
2.0.11
4 months ago
2.0.7
7 months ago
2.0.12
4 months ago
2.0.6
7 months ago
2.0.9
5 months ago
2.0.10
4 months ago
2.0.8
6 months ago
2.0.4
8 months ago
2.0.3
8 months ago
2.0.2
9 months ago
2.0.1
9 months ago
2.0.0
9 months ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago
0.0.3
9 years ago
0.0.2
9 years ago
0.0.1
9 years ago