Chore: test

- add test for Role, SecuritySeverity, Text, XML
This commit is contained in:
Sostene MUNEZERO BAGIRA
2022-05-25 00:30:37 +02:00
parent d6a5b92de7
commit 08ca6c68f6
6 changed files with 87 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
import Role from '../../Types/Role';
describe('Role', () => {
test('Role.Owner should be Owner', () => {
expect(Role.Owner).toBe('Owner');
});
test('Role.Administrator should be Administrator', () => {
expect(Role.Administrator).toBe('Administrator');
});
test('Role.Member should be Member', () => {
expect(Role.Member).toBe('Member');
});
test('Role.Viewer should be Viewer', () => {
expect(Role.Viewer).toBe('Viewer');
});
test('Role.Public should be Public', () => {
expect(Role.Public).toBe('Public');
});
});

View File

@@ -0,0 +1,16 @@
import SecuritySeverity from '../../Types/SecuritySeverity';
describe('enum SecuritySeverity', () => {
test('SecuritySeverity.Critical should be Critcal', () => {
expect(SecuritySeverity.Critical).toEqual('Critical');
});
test('SecuritySeverity.High should be High', () => {
expect(SecuritySeverity.High).toEqual('High');
});
test('SecuritySeverity.Medium should be Medium', () => {
expect(SecuritySeverity.Medium).toEqual('Medium');
});
test('SecuritySeverity.Low should be Low', () => {
expect(SecuritySeverity.Low).toEqual('Low');
});
});

View File

@@ -0,0 +1,10 @@
import Text from '../../Types/Text';
describe('class Text', () => {
test('Text.uppercaseFirstLetter should make string frist letter Uppercase', () => {
expect(Text.uppercaseFirstLetter('text')).toEqual('Text');
expect(Text.uppercaseFirstLetter('another test')).toEqual(
'Another test'
);
});
});

View File

@@ -0,0 +1,36 @@
import BadDataException from '../../Types/Exception/BadDataException';
import XML from '../../Types/XML';
describe('class XML', () => {
test('new XML should return valid object if it is valid', () => {
const xmlString: string = '<test> <info>Test</info></test>';
const xml: XML = new XML(xmlString);
expect(xml.toString()).toEqual(xmlString);
expect(xml.xml).toEqual(xmlString);
});
test('XML.xml should be mutable', () => {
const xmlNewString: string = '<new> <info>Test</info></new>';
const xml: XML = new XML('<test> <info>Test</info></test>');
xml.xml = xmlNewString;
expect(xml.toString()).toEqual(xmlNewString);
expect(xml.xml).toEqual(xmlNewString);
});
test('mutating XML.xml with empty string should throw BadDataException', () => {
const xml: XML = new XML('<test> <info>Test</info></test>');
expect(() => {
xml.xml = '';
}).toThrowError(BadDataException);
expect(() => {
xml.xml = '';
}).toThrow('XML is not in valid format.');
});
test('new should throw BadDataException if empty string is given', () => {
expect(() => {
new XML('');
}).toThrowError(BadDataException);
expect(() => {
new XML('');
}).toThrow('XML is not in valid format.');
});
});

View File

@@ -1,5 +1,5 @@
export default class Text {
public uppercaseFirstLetter(word: string): string {
public static uppercaseFirstLetter(word: string): string {
if (word.length > 0) {
return word.charAt(0).toUpperCase() + word.slice(1);
}

View File

@@ -1,9 +1,13 @@
import BadDataException from './Exception/BadDataException';
export default class XML {
private _xml: string = '';
public get xml(): string {
return this._xml;
}
public set xml(v: string) {
if (!v) {
throw new BadDataException('XML is not in valid format.');
}
this._xml = v;
}