Add test for the alerts

This commit is contained in:
Sostene Munezero Bagira
2023-02-07 09:54:07 +02:00
parent 168878789c
commit ea4e09740d
13 changed files with 116 additions and 18 deletions

View File

@@ -3,7 +3,7 @@ describe('ErrorResponse', () => {
test('should return a valid error response object', () => {
const errorResponseObject: ErrorResponse = new ErrorResponse(500, {
error: 'Internal Server Error',
});
},{});
expect(errorResponseObject.statusCode).toBe(500);
expect(errorResponseObject.data).toEqual({
error: 'Internal Server Error',

View File

@@ -5,12 +5,12 @@ describe('Response()', () => {
test('should return a valid response object', () => {
const responseObject: Response<JSONObject> = new Response(200, {
welcome: 'here',
});
},{});
expect(responseObject.statusCode).toBe(200);
expect(responseObject.data).toEqual({ welcome: 'here' });
const responseObjectArray: Response<Array<JSONObject>> = new Response<
Array<JSONObject>
>(200, [{ welcome: 'here' }]);
>(200, [{ welcome: 'here' }], {});
expect(responseObjectArray.statusCode).toBe(200);
expect(responseObjectArray.data).toEqual([{ welcome: 'here' }]);
});

View File

@@ -0,0 +1,37 @@
import AlertEventType from '../../../Types/Alerts/AlertEventType';
describe('AlertEventType', () => {
test('AlertEventType.Identified to be Identified', () => {
expect(AlertEventType.Identified).toBe('Identified');
});
test('AlertEventType.Acknowledged to Acknowledged', () => {
expect(AlertEventType.Acknowledged).toBe('Acknowledged');
});
test('AlertEventType.Resolved to Resolved', () => {
expect(AlertEventType.Resolved).toBe('Resolved');
});
test('AlertEventType.InvestigationNoteCreated to Investigation note created', () => {
expect(AlertEventType.InvestigationNoteCreated).toBe('Investigation note created');
});
test('AlertEventType.InvestigationNoteUpdated to Investigation note updated', () => {
expect(AlertEventType.InvestigationNoteUpdated).toBe('Investigation note updated');
});
test('AlertEventType.ScheduledMaintenanceCreated to Scheduled maintenance created', () => {
expect(AlertEventType.ScheduledMaintenanceCreated).toBe('Scheduled maintenance created');
});
test('AlertEventType.ScheduledMaintenanceNoteCreated to Scheduled maintenance note Created', () => {
expect(AlertEventType.ScheduledMaintenanceNoteCreated).toBe('Scheduled maintenance note created');
});
test('AlertEventType.ScheduledMaintenanceResolved to sheduled mantainance resolved', () => {
expect(AlertEventType.ScheduledMaintenanceResolved).toBe('Scheduled maintenance resolved');
});
test('AlertEventType.Acknowledged to Scheduled maintenance cancelled', () => {
expect(AlertEventType.ScheduledMaintenanceCancelled).toBe('Scheduled maintenance cancelled');
});
test('AlertEventType.AnnouncementNotificationCreated to Announcement notification created', () => {
expect(AlertEventType.AnnouncementNotificationCreated).toBe('Announcement notification created');
});
});

View File

@@ -0,0 +1,23 @@
import AlertType from '../../../Types/Alerts/AlertType';
describe('AlertType', () => {
test('AlertType.Email to be Email', () => {
expect(AlertType.Webhook).toBe('Webhook');
});
test('AlertType.Acknowledged to Acknowledged', () => {
expect(AlertType.Email).toBe('Email');
});
test('AlertType.SMS to SMS', () => {
expect(AlertType.SMS).toBe('SMS');
});
test('AlertType.Call to Call', () => {
expect(AlertType.Call).toBe('Call');
});
test('AlertType.PushNotification to PushNotification', () => {
expect(AlertType.PushNotification).toBe('PushNotification');
});
});

View File

@@ -0,0 +1,16 @@
import ApplicationLogType from '../../../Types/ApplicationLog/ApplicationLogType';
describe('ApplicationLogType', () => {
test('ApplicationLogType.Info to be Info', () => {
expect(ApplicationLogType.Info).toBe('Info');
});
test('ApplicationLogType.Error to Error', () => {
expect(ApplicationLogType.Error).toBe('Error');
});
test('ApplicationLogType.Warning to Warning', () => {
expect(ApplicationLogType.Warning).toBe('Warning');
});
});

View File

@@ -0,0 +1,16 @@
import ApplicationLogType from '../../../Types/ApplicationLog/ApplicationLogType';
describe('ApplicationLogType', () => {
test('ApplicationLogType.Info to be Info', () => {
expect(ApplicationLogType.Info).toBe('Info');
});
test('ApplicationLogType.Error to Error', () => {
expect(ApplicationLogType.Error).toBe('Error');
});
test('ApplicationLogType.Warning to Warning', () => {
expect(ApplicationLogType.Warning).toBe('Warning');
});
});

View File

@@ -1,19 +1,20 @@
import LIMIT_MAX, { LIMIT_PER_PROJECT } from '../../../Types/Database/LimitMax';
describe('LIMIT_MAX', () => {
test('it should ', () => {
expect(LIMIT_MAX).toEqual(1000);
test('it should be number', () => {
expect(typeof LIMIT_MAX).toBe("number")
});
});
describe('LIMIT_MAX', () => {
test('it should have a value', () => {
expect(LIMIT_MAX).toEqual(1000);
test('it be positive', () => {
expect(LIMIT_MAX).toBeGreaterThan(0);
});
});
describe('LIMIT_PER_PROJECT', () => {
test('it should have a value ', () => {
expect(LIMIT_PER_PROJECT).toEqual(100);
test('should be positive number', () => {
expect(typeof LIMIT_PER_PROJECT).toBe("number")
expect(LIMIT_PER_PROJECT).toBeGreaterThan(0)
});
});

View File

@@ -6,9 +6,10 @@ describe('Email()', () => {
});
test('should not create an email with invalid credentials', () => {
let invalidEmail='invalid email address'
expect(() => {
new Email('invalid email address');
}).toThrow('Email is not in valid format.');
new Email(invalidEmail);
}).toThrow(`Email ${invalidEmail} is not in valid format.`);
});
test('should be a business email', () => {

View File

@@ -23,13 +23,16 @@ describe('Testing Class Phone', () => {
});
test('try to mutating Phone.phone with invalid value should throw an BadDataExcepection', () => {
const value: Phone = new Phone('+251912974103');
let valid='+251912974103'
let invalid='278@$90> '
const value: Phone = new Phone(valid);
expect(() => {
value.phone = '567';
value.phone = invalid;
}).toThrowError(BadDataException);
expect(() => {
value.phone = '278@$90> ';
}).toThrow('Phone is not in valid format.');
}).toThrow('Phone is not in valid format: 278@$90>');
expect(value.phone).toBe(valid)
expect(() => {
value.phone = 'hgjuit879';
}).toThrowError(BadDataException);

View File

@@ -9,10 +9,10 @@ describe('Testing class port', () => {
expect(new Port('6000').port.positiveNumber).toEqual(6000);
});
test('should throw exception "Port should be in the range from 0 to 65535"', () => {
test('should throw exception "Port is not in valid format."', () => {
expect(() => {
new Port(67000);
}).toThrow('Port should be in the range from 0 to 65535');
}).toThrow('Port is not in valid format.');
});
test('Port.port should be mutatable', () => {

View File

@@ -6,7 +6,7 @@ enum AlertEventType {
InvestigationNoteUpdated = 'Investigation note updated',
ScheduledMaintenanceCreated = 'Scheduled maintenance created',
ScheduledMaintenanceNoteCreated = 'Scheduled maintenance note created',
ScheduledMaintenanceEesolved = 'Scheduled maintenance resolved',
ScheduledMaintenanceResolved = 'Scheduled maintenance resolved',
ScheduledMaintenanceCancelled = 'Scheduled maintenance cancelled',
AnnouncementNotificationCreated = 'Announcement notification created',
}

View File

@@ -1,6 +1,6 @@
enum ApplicationLogType {
Info = 'Info',
Erorr = 'Error',
Error = 'Error',
Warning = 'Warning',
}

View File

@@ -2,6 +2,7 @@ enum CodeType {
JavaScript = 'JavaScript',
CSS = 'CSS',
HTML = 'HTML',
// TODO add more mime types.
}