mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-11 12:12:55 +00:00
build: update dependencies
This commit is contained in:
85
test/create-diagram.spec.ts
Normal file
85
test/create-diagram.spec.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user