rivet
Version:
Suite of utilities for working with the Rivet consumer-driven API contacts testing model.
51 lines (46 loc) • 1.26 kB
text/typescript
import { compileHandler } from '../../src/bin/handlers';
import * as fs from 'fs-extra';
jest.mock('fs-extra');
describe('compile', () => {
it('compiles file to location specified', () => {
const contracts = compileHandler({
clean: '',
out: 'example/consumer/contracts/',
cwd: 'example/consumer/contracts/',
});
expect(contracts[0].path).toContain('contracts/json/example.contract.json');
expect(contracts[1].path).toContain('contracts/json/subfolder/nested.contract.json');
expect(JSON.parse(contracts[0].data)).toEqual({
title: 'Example Contract',
required: [
'name',
'token',
'description',
'updated_at'
],
properties: {
name: {
type: 'string'
},
token: {
id: 'types.jwt',
type: 'string',
pattern: '^[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*$'
},
description: {
type: 'string'
},
updated_at: {
type: 'string'
}
}
});
expect(JSON.parse(contracts[1].data)).toEqual({
title: 'Nested Contract',
required: [ 'name' ],
properties: {
name: { type: 'string' },
}
});
});
});