mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-04 20:42:52 +00:00
Upgraded JSON Schema from version 6 to version 7 Upgraded TypeDoc version to latest Replaced 'jsonschema' with 'json-schema' package to better comply with 'ts-json-schema-generator' Replace JSON Schema validation with AJV in areas where it wasn't used previously Removed commander help output as it causes strange issues
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
/*
|
|
* Copyright (C) 2018-2019 StApps
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation, version 3.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
import {expect} from 'chai';
|
|
import {resolve} from 'path';
|
|
import {existsSync, unlinkSync} from 'fs';
|
|
import {slow, suite, test, timeout} from 'mocha-typescript';
|
|
import {getProjectReflection} from '../src/common';
|
|
import {createDiagram, createDiagramFromString} from '../src/uml/create-diagram';
|
|
import {UMLConfig} from '../src/uml/uml-config';
|
|
import {readDefinitions} from '../src/uml/read-definitions';
|
|
import {LightweightDefinition} from '../src/uml/model/lightweight-definition';
|
|
import nock = require('nock');
|
|
|
|
@suite(timeout(15000), slow(5000))
|
|
export class CreateDiagramSpec {
|
|
plantUmlConfig: UMLConfig;
|
|
definitions: LightweightDefinition[];
|
|
|
|
constructor() {
|
|
this.plantUmlConfig = {
|
|
definitions: [],
|
|
showAssociations: true,
|
|
showEnumValues: true,
|
|
showInheritance: true,
|
|
showInheritedProperties: true,
|
|
showOptionalProperties: true,
|
|
showProperties: true,
|
|
};
|
|
|
|
const projectReflection = getProjectReflection('./test/model', true);
|
|
this.definitions = readDefinitions(projectReflection);
|
|
}
|
|
|
|
@test
|
|
async shouldRefuseRequest() {
|
|
const testPlantUmlCode: string = 'class Test{\n}';
|
|
try {
|
|
await createDiagramFromString(testPlantUmlCode, "http://plantuml:8080");
|
|
} catch (e) {
|
|
expect([
|
|
new Error('getaddrinfo ENOTFOUND plantuml plantuml:8080').message,
|
|
new Error('getaddrinfo EAI_AGAIN plantuml plantuml:8080').message,
|
|
]).to.include(e.message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This test will only test the functionality of the method
|
|
* - Converting the definitions to plantuml code
|
|
* - Sending the code to a server
|
|
* - Writing the response to a file
|
|
* This test will not check the file content
|
|
*/
|
|
@test
|
|
async shouldCreateDiagrams() {
|
|
nock('http://plantuml:8080')
|
|
.persist()
|
|
.get(() => true)
|
|
.reply(200, 'This will be the file content')
|
|
|
|
let fileName = await createDiagram(this.definitions, this.plantUmlConfig, "http://plantuml:8080");
|
|
let filePath = resolve(__dirname, '..', fileName);
|
|
expect(await existsSync(filePath)).to.equal(true);
|
|
|
|
await unlinkSync(fileName);
|
|
this.plantUmlConfig.showAssociations = false;
|
|
|
|
this.plantUmlConfig.showInheritance = false;
|
|
fileName = await createDiagram(this.definitions, this.plantUmlConfig, "http://plantuml:8080");
|
|
filePath = resolve(__dirname, '..', fileName);
|
|
expect(await existsSync(filePath)).to.equal(true);
|
|
await unlinkSync(fileName);
|
|
|
|
nock.cleanAll();
|
|
}
|
|
}
|