mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-05 13:02:54 +00:00
86 lines
2.9 KiB
TypeScript
86 lines
2.9 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(e.message).to.equal(new Error('getaddrinfo ENOTFOUND plantuml plantuml:8080').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();
|
|
}
|
|
}
|