mirror of https://github.com/Seich/Beau.git
Update some old tests.
Added missing cases and tests. Most of these are kind useless but I hope I won't have to touch them again.
This commit is contained in:
parent
9444b9ca61
commit
4036a63b2c
|
|
@ -0,0 +1,14 @@
|
|||
const fs = jest.genMockFromModule('fs');
|
||||
|
||||
fs.existsSync = filename => filename === 'beau.yml';
|
||||
fs.readFileSync = () => `
|
||||
version: 1
|
||||
endpoint: https://example.org/
|
||||
|
||||
GET /anything:
|
||||
alias: anything
|
||||
payload:
|
||||
name: $env.params.name
|
||||
`;
|
||||
|
||||
module.exports = fs;
|
||||
|
|
@ -26,8 +26,14 @@ utils.loadConfig = function() {
|
|||
return new Beau(config, {});
|
||||
};
|
||||
|
||||
utils.openConfigFile = function() {
|
||||
utils.openConfigFile = function(filename) {
|
||||
if (filename === 'beau.yml') {
|
||||
return config;
|
||||
}
|
||||
|
||||
if (filename === 'invalid-conf.yml') {
|
||||
return { plugins: [{ hello: 1, world: 2 }] };
|
||||
}
|
||||
};
|
||||
|
||||
utils.baseFlags = original.baseFlags;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`utils loadConfig should load load the config onto Beau 1`] = `
|
||||
Config {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "https://example.org/",
|
||||
"ENVIRONMENT": Object {
|
||||
"_": Object {},
|
||||
},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Plugins {
|
||||
"context": Object {
|
||||
"createReadStream": [Function],
|
||||
},
|
||||
"registry": Object {
|
||||
"dynamicValues": Array [
|
||||
Object {
|
||||
"fn": [Function],
|
||||
"name": "createReadStream",
|
||||
},
|
||||
],
|
||||
"postRequestModifiers": Array [],
|
||||
"preRequestModifiers": Array [],
|
||||
},
|
||||
},
|
||||
"REQUESTS": Array [
|
||||
Object {
|
||||
"ALIAS": "anything",
|
||||
"COOKIEJAR": false,
|
||||
"ENDPOINT": "https://example.org/",
|
||||
"PAYLOAD": Object {
|
||||
"name": "$env.params.name",
|
||||
},
|
||||
"REQUEST": "GET /anything",
|
||||
},
|
||||
],
|
||||
"VERSION": 1,
|
||||
"configKeys": Array [
|
||||
"VERSION",
|
||||
"ENDPOINT",
|
||||
"PLUGINS",
|
||||
"DEFAULTS",
|
||||
"ENVIRONMENT",
|
||||
"HOSTS",
|
||||
"COOKIEJAR",
|
||||
],
|
||||
"defaultConfigValues": Object {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "",
|
||||
"ENVIRONMENT": Object {},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Array [],
|
||||
"VERSION": 1,
|
||||
},
|
||||
"doc": Object {
|
||||
"GET /anything": Object {
|
||||
"alias": "anything",
|
||||
"payload": Object {
|
||||
"name": "$env.params.name",
|
||||
},
|
||||
},
|
||||
"endpoint": "https://example.org/",
|
||||
"version": 1,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`utils loadConfig should load params onto the environment 1`] = `
|
||||
Object {
|
||||
"_": Object {
|
||||
"BYE": "MARS",
|
||||
"HELLO": "WORLD",
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`utils openConfigFile should read and parse the given configuration file. 1`] = `
|
||||
Object {
|
||||
"GET /anything": Object {
|
||||
"alias": "anything",
|
||||
"payload": Object {
|
||||
"name": "$env.params.name",
|
||||
},
|
||||
},
|
||||
"endpoint": "https://example.org/",
|
||||
"version": 1,
|
||||
}
|
||||
`;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Validate Command Validate the configuration file 1`] = `
|
||||
exports[`Validate Command should validate the configuration file 1`] = `
|
||||
Array [
|
||||
"beau.yml is valid.
|
||||
",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
const utils = require('../utils.js');
|
||||
|
||||
jest.mock('fs');
|
||||
|
||||
describe('utils', () => {
|
||||
describe('openConfigFile', () => {
|
||||
it('should read and parse the given configuration file.', () => {
|
||||
expect(utils.openConfigFile('beau.yml')).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should thrown if given not given a file', () => {
|
||||
expect(() => utils.openConfigFile('not-a-file.yml')).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadConfig', () => {
|
||||
it('should load load the config onto Beau', () => {
|
||||
let beau = utils.loadConfig('beau.yml');
|
||||
expect(beau.config).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should load params onto the environment', () => {
|
||||
let beau = utils.loadConfig('beau.yml', [
|
||||
'HELLO=WORLD',
|
||||
'BYE=MARS'
|
||||
]);
|
||||
expect(beau.config.ENVIRONMENT).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -16,8 +16,14 @@ describe('Validate Command', () => {
|
|||
|
||||
afterEach(() => jest.restoreAllMocks());
|
||||
|
||||
it('Validate the configuration file', async () => {
|
||||
it('should validate the configuration file', async () => {
|
||||
await ValidateCommand.run([]);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('should show schema errors', async () => {
|
||||
await expect(
|
||||
ValidateCommand.run(['invalid-conf.yml'])
|
||||
).rejects.toThrow();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const yaml = require('js-yaml');
|
||||
const Plugins = require('../plugins');
|
||||
const Request = require('../request');
|
||||
const RequestCache = require('../requestCache');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
const Request = require('../request');
|
||||
const RequestCache = require('../requestCache');
|
||||
const RequestList = require('../requestList');
|
||||
const requestPromiseNativeMock = require('request-promise-native');
|
||||
|
||||
describe('Request', () => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
const schema = require('../schema');
|
||||
|
||||
describe('Schema', () => {
|
||||
it(`should validate an object against the schema`, async () => {
|
||||
await expect(
|
||||
schema.validate({ endpoint: 'http://example.com' })
|
||||
).resolves.toHaveProperty('valid', true);
|
||||
});
|
||||
|
||||
it(`should indicate the error when an schema is invalid`, async () => {
|
||||
await expect(
|
||||
schema.validate({ plugins: [{ hello: 1, world: 2 }] })
|
||||
).resolves.toHaveProperty('valid', false);
|
||||
});
|
||||
});
|
||||
|
|
@ -62,9 +62,7 @@ const schema = Joi.object()
|
|||
|
||||
const validate = async function(config) {
|
||||
try {
|
||||
let results = await Joi.validate(config, schema, {
|
||||
allowUnknown: true
|
||||
});
|
||||
await Joi.validate(config, schema, { allowUnknown: true });
|
||||
return { valid: true };
|
||||
} catch ({ name, details }) {
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue