-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
88 lines (79 loc) · 3.37 KB
/
test.js
File metadata and controls
88 lines (79 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"use strict";
var chai = require('chai');
chai.use(require("chai-as-promised"));
var expect = chai.expect;
var mockery = require('mockery');
var propertiesReaders = require('./test/PropertiesReaderTestMock');
var TestOpsviewAPIServerV3 = require('./test/TestOpsviewAPIServerV3');
var Opsview = require('./index').Opsview;
var Exceptions = require('./exceptions');
var util = require('util');
var NON_IMPLEMENTED_VERSION = 999;
var IMPLEMENTED_VERSION = 3;
describe('Opsview JS Library', function () {
describe('General', function () {
describe('Creation',function(){
it('should protest if the user tries to instantiate a non implemented version', function () {
let nonImplementedInstantiation = function(){new Opsview(NON_IMPLEMENTED_VERSION);};
expect(nonImplementedInstantiation).to.throw(Exceptions.OpsviewVersionNotSupportedError);
});
it('should instantiate correctly the latest implemented version',function(){
let latestVersionInstantiation = function(){new Opsview();};
expect(latestVersionInstantiation).to.not.throw(Exceptions.OpsviewVersionNotSupportedError);
expect(latestVersionInstantiation).to.not.throw(Exceptions.OpsviewPropertiesFileNotFoundError);
});
it('should instantiate correctly the implemented version 3',function(){
let latestVersionInstantiation = function(){new Opsview(IMPLEMENTED_VERSION);};
expect(latestVersionInstantiation).to.not.throw(Exceptions.OpsviewVersionNotSupportedError);
expect(latestVersionInstantiation).to.not.throw(Exceptions.OpsviewPropertiesFileNotFoundError);
});
});
});
describe('Usage',function(){
describe('Downtimes',function(){
describe('Version 3',function(){
//Setup
let testServer = new TestOpsviewAPIServerV3();
before(function(done){
//Initialize the TestOpsviewAPIServer V3.
testServer.start(done);
});
beforeEach(function(){
//Initialize the mock system
mockery.enable({useCleanCache: true,warnOnUnregistered: false});
mockery.resetCache();
});
after(function(){
testServer.stop();
});
afterEach(function(){
mockery.disable();
});
//Tests
it('Should fail the request if valid credentials are not provided',function(done){
//Modify the properties reader so that it retrieves our test server with invalid credentials
mockery.registerMock('properties-reader',propertiesReaders.InvalidPropertiesReaderMock);
let opsview = new Opsview(IMPLEMENTED_VERSION);
opsview.setDowntime()
.then(function(){
done("The call shouldn't have succeeded, but returned instead.");
})
.catch(Error,function(error){
if(error.constructor.name !== 'OpsviewAuthenticationError'){
done(`The call generated an unexpected error: ${error.message}`);
} else {
done();
}
})
});
/*it('Should set downtimes correctly given the right arguments and authentication',function(){
//Modify the properties reader so that it retrieves our test server with invalid credentials
mockery.registerMock('properties-reader',propertiesReaders.ValidPropertiesReaderMock);
let opsview = new Opsview(IMPLEMENTED_VERSION);
opsview.setDowntime(new Date(), new Date(), "test comment", "test-host", "test-check:"
.should.eventually.equal("");
});*/
});
});
});
});