Viewing File: /usr/local/cpanel/base/frontend/jupiter/site-monitor/models/monitor.spec.js
/*
# site-monitor/models/monitor.spec.js Copyright 2021 cPanel, L.L.C.
# All rights reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
*/
/* global define: false, describe: false, it: false, beforeEach: false, expect: false */
define([
"app/models/monitor",
"app/models/monitor-type.enum"
],
function(Monitor, MonitorType) {
"use strict";
describe("new Monitor", function() {
describe("with only required properties", function() {
it("should be constructed property", function() {
var monitor = new Monitor({
name: 'a',
domain: 'a.com',
});
expect(monitor).toBeInstanceOf(Monitor);
expect(monitor).toEqual(jasmine.objectContaining({
name: 'a',
domain: 'a.com',
protocol: MonitorType.HTTPS,
port: 443,
path: '',
interval: Monitor.DEFAULT_CHECK_INTERVAL,
enabled: true,
data: [],
contact: undefined,
}));
});
});
describe("check default ports", function() {
var raw;
beforeEach(function() {
raw = {
name: 'a',
domain: 'a.com',
};
});
it("should map HTTP to port 80", function() {
var monitor = new Monitor({
...raw,
protocol: MonitorType.HTTP,
});
expect(monitor).toEqual(jasmine.objectContaining({
name: 'a',
domain: 'a.com',
protocol: MonitorType.HTTP,
port: 80,
}));
});
it("should map HTTPS to port 443", function() {
raw.protocol = MonitorType.HTTPS;
var monitor = new Monitor(raw);
expect(monitor).toEqual(jasmine.objectContaining({
name: 'a',
domain: 'a.com',
protocol: MonitorType.HTTPS,
port: 443,
}));
});
it("should map TCP to port 23", function() {
raw.protocol = MonitorType.TCP
var monitor = new Monitor(raw);
expect(monitor).toEqual(jasmine.objectContaining({
name: 'a',
domain: 'a.com',
protocol: MonitorType.TCP,
port: 23,
}));
});
it("should map ICMP to no port", function() {
raw.protocol = MonitorType.ICMP
var monitor = new Monitor(raw);
expect(monitor).toEqual(jasmine.objectContaining({
name: 'a',
domain: 'a.com',
protocol: MonitorType.ICMP,
port: undefined,
}));
});
});
});
describe("Monitor.parseListItem", function() {
it("should convert the get_all_site_monitors API response item to a Monitor class", function() {
var unixTimestamp = 1637609251;
var monitor = Monitor.parseListItem({
id: "5a3c8d76-2d43-45ea-ad80-e5e12f6bbcd9",
name: "a",
url: "domain.com:1443/a/b/c?q=yes",
type: MonitorType.HTTPS,
port: 1443,
first_update: unixTimestamp,
last_update: unixTimestamp + 10,
monitor: {
name: 'Chicago/USA'
},
});
expect(monitor).toBeInstanceOf(Monitor);
expect(monitor).toEqual(jasmine.objectContaining({
id: "5a3c8d76-2d43-45ea-ad80-e5e12f6bbcd9",
name: "a",
domain: "domain.com",
protocol: MonitorType.HTTPS,
port: 1443,
path: "a/b/c",
search: "q=yes",
// UNIX timestamps are in sec, javascript timestamps are in ms
firstUpdate: new Date(unixTimestamp * 1000),
lastUpdate: new Date((unixTimestamp + 10) * 1000),
fromLocation: 'Chicago/USA',
}));
});
});
describe("Monitor.parseItem", function() {
it("should convert the get_site_monitor API response item to a Monitor class", function() {
var unixTimestamp = 1637609251;
var monitor = Monitor.parseItem({
id: "5a3c8d76-2d43-45ea-ad80-e5e12f6bbcd9",
name: "The Virtual Muppet Show",
url: "https://muppets.com/a/b/c?q=yes",
type: MonitorType.HTTPS,
interval: 2000,
first_update: unixTimestamp,
last_update: unixTimestamp + 10,
monitor: {
name: 'Chicago/USA'
},
// TODO: Handle contacts
// contacts: {
// "6c66d58f-039b-41a5-a161-19b9e2ab87c0": {
// "kermit@muppets.com": {
// delay: 10,
// }
// }
// }
});
expect(monitor).toBeInstanceOf(Monitor);
expect(monitor).toEqual(jasmine.objectContaining({
id: "5a3c8d76-2d43-45ea-ad80-e5e12f6bbcd9",
name: "The Virtual Muppet Show",
domain: 'muppets.com',
protocol: MonitorType.HTTPS,
port: 443,
path: 'a/b/c',
search: 'q=yes',
interval: 2000,
// UNIX timestamps are in sec, javascript timestamps are in ms
firstUpdate: new Date(unixTimestamp * 1000),
lastUpdate: new Date((unixTimestamp + 10) * 1000),
fromLocation: 'Chicago/USA',
}));
});
});
});
Back to Directory
File Manager