2021-07-07 20:13:15 +02:00
|
|
|
const assert = require('assert').strict
|
|
|
|
const loader = require('../src/loader')
|
|
|
|
const logging = require('../src/logging')
|
|
|
|
const expect = require('chai').expect
|
2021-07-07 20:34:08 +02:00
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
2021-07-07 20:13:15 +02:00
|
|
|
|
|
|
|
logging.init(-1)
|
|
|
|
const commands = loader.load()
|
|
|
|
|
|
|
|
|
|
|
|
describe("gen command", () => {
|
2021-07-07 20:34:08 +02:00
|
|
|
|
|
|
|
const test_spec = {
|
|
|
|
name: 'test-service',
|
|
|
|
description: 'Description for service.',
|
|
|
|
baseurl: 'https://nclazz.de',
|
|
|
|
namespace: 'de.nclazz' ,
|
|
|
|
quiet: true
|
|
|
|
}
|
|
|
|
|
2021-07-07 20:13:15 +02:00
|
|
|
it('throws an error on missing name', () => {
|
2021-07-07 20:34:08 +02:00
|
|
|
expect(() => commands.gen.run({ quiet: true })).to.throw('Name must not be empty!')
|
2021-07-07 20:13:15 +02:00
|
|
|
})
|
|
|
|
it('throws an error on missing description', () => {
|
2021-07-07 20:34:08 +02:00
|
|
|
expect(() => commands.gen.run({ name: 'testename', quiet: true })).to.throw('Description must not be empty!')
|
2021-07-07 20:13:15 +02:00
|
|
|
})
|
|
|
|
it('generates a spec', () => {
|
2021-07-07 20:34:08 +02:00
|
|
|
let spec = commands.gen.run(test_spec);
|
2021-07-07 20:13:15 +02:00
|
|
|
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', () => {
|
2021-07-07 20:34:08 +02:00
|
|
|
let spec = commands.gen.run(test_spec);
|
2021-07-07 20:13:15 +02:00
|
|
|
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', () => {
|
2021-07-07 20:34:08 +02:00
|
|
|
let spec = commands.gen.run(test_spec);
|
2021-07-07 20:13:15 +02:00
|
|
|
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')
|
|
|
|
})
|
2021-07-07 20:34:08 +02:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
2021-07-07 20:13:15 +02:00
|
|
|
})
|