mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Chore: test
- add test for Role, SecuritySeverity, Text, XML
This commit is contained in:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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.');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user