feat: tests

This commit is contained in:
2023-04-21 12:08:35 +02:00
parent 8cb9285462
commit d8c79256c9
140 changed files with 2100 additions and 2693 deletions

View File

@@ -14,36 +14,32 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {expect} from 'chai';
import {existsSync, unlinkSync} from 'fs';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {createDiagram, createDiagramFromString} from '../src/uml/create-diagram.js';
import {UMLConfig} from '../src/uml/uml-config.js';
import {LightweightDefinition, lightweightDefinitionsFromPath} from '@openstapps/easy-ast';
import {unlink} from 'fs/promises';
import {createDiagram, createDiagramFromString} from '../src/index.js';
import {UMLConfig} from '../src/index.js';
import {lightweightDefinitionsFromPath} from '@openstapps/easy-ast';
import nock = require('nock');
import path from 'path';
import {existsSync} from 'fs';
import {fileURLToPath} from 'url';
@suite(timeout(15_000), slow(5000))
export class CreateDiagramSpec {
plantUmlConfig: UMLConfig;
describe('CreateDiagram', function () {
this.timeout(15_000);
this.slow(5000);
definitions: LightweightDefinition[];
const plantUmlConfig: UMLConfig = {
definitions: [],
showAssociations: true,
showEnumValues: true,
showInheritance: true,
showInheritedProperties: true,
showOptionalProperties: true,
showProperties: true,
};
constructor() {
this.plantUmlConfig = {
definitions: [],
showAssociations: true,
showEnumValues: true,
showInheritance: true,
showInheritedProperties: true,
showOptionalProperties: true,
showProperties: true,
};
const definitions = lightweightDefinitionsFromPath('./test/model');
this.definitions = lightweightDefinitionsFromPath('./test/model');
}
@test
async shouldRefuseRequest() {
it('should refuse request', async function () {
const testPlantUmlCode = 'class Test{\n}';
try {
await createDiagramFromString(testPlantUmlCode, 'http://plantuml:8080');
@@ -54,7 +50,7 @@ export class CreateDiagramSpec {
new Error('getaddrinfo ENOTFOUND plantuml').message,
]).to.include((error as NodeJS.ErrnoException).message);
}
}
});
/**
* This test will only test the functionality of the method
@@ -63,26 +59,25 @@ export class CreateDiagramSpec {
* - Writing the response to a file
* This test will not check the file content
*/
@test
async shouldCreateDiagrams() {
it('should create diagrams', async function () {
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 = path.resolve(__dirname, '..', fileName);
expect(await existsSync(filePath)).to.equal(true);
let fileName = await createDiagram(definitions, plantUmlConfig, 'http://plantuml:8080');
let filePath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', fileName);
expect(existsSync(filePath)).to.be.true;
await unlinkSync(fileName);
this.plantUmlConfig.showAssociations = false;
await unlink(fileName);
plantUmlConfig.showAssociations = false;
this.plantUmlConfig.showInheritance = false;
fileName = await createDiagram(this.definitions, this.plantUmlConfig, 'http://plantuml:8080');
filePath = path.resolve(__dirname, '..', fileName);
expect(await existsSync(filePath)).to.equal(true);
await unlinkSync(fileName);
plantUmlConfig.showInheritance = false;
fileName = await createDiagram(definitions, plantUmlConfig, 'http://plantuml:8080');
filePath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', fileName);
expect(existsSync(filePath)).to.be.true;
await unlink(fileName);
nock.cleanAll();
}
}
});
});