Skip to content

Commit

Permalink
Fix for unit tests of oslo-generator-webuniversum
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofVDB1 committed Nov 6, 2024
1 parent 00cb717 commit a689554
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 93 deletions.
23 changes: 0 additions & 23 deletions packages/oslo-generator-json-webuniversum/config.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
{
"baseURI": "http://example.org/ns/domain#",
"entities": [
{
"id": "http://example.org/id/class/1",
"vocabularyLabel": {
"en": "VocTestClass"
},
"applicationProfileLabel": {
"en": "ApTestClass"
},
"vocabularyDefinition": {
"en": "VocDefinition"
},
"applicationProfileDefinition": {
"en": "ApDefinition"
},
"vocabularyUsageNote": {
"en": "VocUsageNote"
},
"applicationProfileUsageNote": {
"en": "ApUsageNote"
}
}
],
"classes": [
{
"id": "http://example.org/id/class/1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class JsonWebuniversumGenerationServiceConfiguration
private _specificationType: SpecificationType | undefined;

public async createFromCli(params: YargsParams): Promise<void> {
console.log(params);
this._input = <string>params.input;
this._output = <string>params.output;
this._language = <string>params.language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,6 @@ describe('JsonWebuniversumGenerationServiceConfiguration', () => {
JSON.stringify(
{
baseURI: 'http://example.org/ns/domain#',
entities: [
{
id: 'http://example.org/id/class/1',
vocabularyLabel: {
en: 'VocTestClass',
},
applicationProfileLabel: {
en: 'ApTestClass',
},
vocabularyDefinition: {
en: 'VocDefinition',
},
applicationProfileDefinition: {
en: 'ApDefinition',
},
vocabularyUsageNote: {
en: 'VocUsageNote',
},
applicationProfileUsageNote: {
en: 'ApUsageNote',
},
},
],
classes: [
{
id: 'http://example.org/id/class/1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,58 @@
* @group unit
*/
import 'reflect-metadata';
import { JsonWebuniversumGenerationServiceConfiguration }
from '../lib/config/JsonWebuniversumGenerationServiceConfiguration';
import {
JsonWebuniversumGenerationServiceConfiguration,
} from '../lib/config/JsonWebuniversumGenerationServiceConfiguration';

describe('JsonWebuniversumGenerationServiceConfiguration', () => {
let params: any;

beforeEach(() => {
params = {
input: 'test.jsonld',
output: 'config.json',
language: 'en',
apTemplateMetadata: 'ap-markdown.md',
vocTemplateMetadata: 'voc-markdown.md',
};
});

it('should set its variables using the parameters received from the CLI', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();
await config.createFromCli(params);

expect((<any>config)._input).toBeDefined();
expect((<any>config)._output).toBeDefined();
expect((<any>config)._language).toBeDefined();
});

it('should throw an error when "input" is undefined or otherwise return its value', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();

expect(() => config.input).toThrow(new Error('Trying to access "input" before it was set.'));
await config.createFromCli(params);
expect(config.input).toBe('test.jsonld');
});

it('should throw an error when "output" is undefined or otherwise return its value', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();

expect(() => config.output).toThrow(new Error('Trying to access "output" before it was set.'));
await config.createFromCli(params);
expect(config.output).toBe('config.json');
});

it('should throw an error when "language" is undefined or otherwise return its value', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();

expect(() => config.language).toThrow(new Error('Trying to access "language" before it was set.'));
await config.createFromCli(params);
expect(config.language).toBe('en');
});
})
let params: any;

beforeEach(() => {
params = {
input: 'test.jsonld',
output: 'config.json',
language: 'en',
specificationType: 'Vocabulary',
};
});

it('should set its variables using the parameters received from the CLI', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();
await config.createFromCli(params);

expect((<any>config)._input).toBeDefined();
expect((<any>config)._output).toBeDefined();
expect((<any>config)._language).toBeDefined();
});

it('should throw an error when "input" is undefined or otherwise return its value', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();

expect(() => config.input).toThrow(
new Error('Trying to access "input" before it was set.'),
);
await config.createFromCli(params);
expect(config.input).toBe('test.jsonld');
});

it('should throw an error when "output" is undefined or otherwise return its value', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();

expect(() => config.output).toThrow(
new Error('Trying to access "output" before it was set.'),
);
await config.createFromCli(params);
expect(config.output).toBe('config.json');
});

it('should throw an error when "language" is undefined or otherwise return its value', async () => {
const config = new JsonWebuniversumGenerationServiceConfiguration();

expect(() => config.language).toThrow(
new Error('Trying to access "language" before it was set.'),
);
await config.createFromCli(params);
expect(config.language).toBe('en');
});
});

0 comments on commit a689554

Please sign in to comment.