-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontract-loader.spec.js
45 lines (40 loc) · 1.14 KB
/
contract-loader.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import test from 'ava'
import joi from 'joi'
import { load, dir } from './contract-loader'
test('loads contracts from file with defaults set', t => {
const contracts = load('./contracts/simple')
const expectedContract = {
name: 'simple endpoint that returns hello world',
request: {
path: '/api/simple',
method: 'GET',
headers: {},
bodySchema: joi.any()
},
response: {
body: {
hello: 'world'
},
bodySchema: joi.any(),
status: 200,
headers: {}
}
}
t.deepEqual(contracts, [expectedContract])
})
test('supports loading an array of contracts', t => {
const contracts = load('./contracts/multiple')
t.is(contracts.length, 2)
})
test('resolves contract directory for file', t => {
return dir('./contracts/simple.js')
.then(res => t.is(res, `${__dirname}/contracts`))
})
test('resolves contract directory for incomplete file', t => {
return dir('./contracts/simple')
.then(res => t.is(res, `${__dirname}/contracts`))
})
test('resolves contract directory for directory', t => {
return dir('./contracts')
.then(res => t.is(res, `${__dirname}/contracts`))
})