84 lines
3 KiB
JavaScript
84 lines
3 KiB
JavaScript
|
const assert = require('assert').strict
|
||
|
const loader = require('../src/loader')
|
||
|
const logging = require('../src/logging')
|
||
|
const expect = require('chai').expect
|
||
|
const fs = require('fs')
|
||
|
const path = require('path')
|
||
|
|
||
|
logging.init(-1)
|
||
|
const commands = loader.load()
|
||
|
|
||
|
|
||
|
describe("gen command", () => {
|
||
|
|
||
|
const test_spec = {
|
||
|
name: 'test-service',
|
||
|
description: 'Description for service.',
|
||
|
baseurl: 'https://nclazz.de',
|
||
|
namespace: 'de.nclazz' ,
|
||
|
quiet: true
|
||
|
}
|
||
|
|
||
|
it('throws an error on missing name', () => {
|
||
|
expect(() => commands.gen.run({ quiet: true })).to.throw('Name must not be empty!')
|
||
|
})
|
||
|
it('throws an error on missing description', () => {
|
||
|
expect(() => commands.gen.run({ name: 'testename', quiet: true })).to.throw('Description must not be empty!')
|
||
|
})
|
||
|
it('generates a spec', () => {
|
||
|
let spec = commands.gen.run(test_spec);
|
||
|
expect(spec).to.not.equal(null)
|
||
|
expect(spec).to.not.equal(undefined)
|
||
|
expect(spec).to.not.equal({})
|
||
|
})
|
||
|
it('includes [name, description, base_url, namespace] as top level properties', () => {
|
||
|
let spec = commands.gen.run(test_spec);
|
||
|
expect(spec).to.have.ownProperty('name')
|
||
|
expect(spec).to.have.ownProperty('description')
|
||
|
expect(spec).to.have.ownProperty('base_url')
|
||
|
expect(spec).to.have.ownProperty('namespace')
|
||
|
})
|
||
|
it('correctly propagates [name, description, base_url, namespace] to spec', () => {
|
||
|
let spec = commands.gen.run(test_spec);
|
||
|
expect(spec.name).to.equal('test-service')
|
||
|
expect(spec.description).to.equal('Description for service.')
|
||
|
expect(spec.base_url).to.equal('https://nclazz.de')
|
||
|
expect(spec.namespace).to.equal('de.nclazz')
|
||
|
})
|
||
|
it('does not creates a file in quiet mode', () => {
|
||
|
let spec = commands.gen.run({
|
||
|
...test_spec,
|
||
|
out: './test-spec.json'
|
||
|
});
|
||
|
expect(fs.existsSync('./test-spec.json')).to.equal(false)
|
||
|
})
|
||
|
it('creates a file with valid json spec', () => {
|
||
|
let spec_path = path.join(__dirname, 'test-spec.json')
|
||
|
commands.gen.run({
|
||
|
...test_spec,
|
||
|
out: spec_path,
|
||
|
quiet: false
|
||
|
});
|
||
|
expect(fs.existsSync(spec_path)).to.equal(true)
|
||
|
let spec_json = require(spec_path)
|
||
|
expect(spec_json).to.have.ownProperty('name')
|
||
|
expect(spec_json).to.have.ownProperty('description')
|
||
|
expect(spec_json).to.have.ownProperty('base_url')
|
||
|
expect(spec_json).to.have.ownProperty('namespace')
|
||
|
fs.unlinkSync(spec_path)
|
||
|
})
|
||
|
it('fails on invalid linting properties', () => {
|
||
|
expect(() => commands.gen.run({
|
||
|
...test_spec,
|
||
|
name: 'Test'
|
||
|
})).to.throw()
|
||
|
})
|
||
|
it('does not fail on invalid linting properties when lintin disabled', () => {
|
||
|
expect(() => commands.gen.run({
|
||
|
...test_spec,
|
||
|
name: 'Test',
|
||
|
'skip-linting': true
|
||
|
})).to.not.throw()
|
||
|
})
|
||
|
|
||
|
})
|