summaryrefslogtreecommitdiffstats
path: root/tests/node.d/fronius.validation.spec.js
diff options
context:
space:
mode:
authorLennart Weller <lhw@ring0.de>2017-09-17 22:17:33 +0000
committerLennart Weller <lhw@ring0.de>2017-09-17 22:17:33 +0000
commit6aaf5ba7ed0980c14bdc554fc8839a2126455ed5 (patch)
tree6161925716661486e7f47c479668a9487b039d83 /tests/node.d/fronius.validation.spec.js
parentNew upstream version 1.7.0+dfsg (diff)
downloadnetdata-6aaf5ba7ed0980c14bdc554fc8839a2126455ed5.tar.xz
netdata-6aaf5ba7ed0980c14bdc554fc8839a2126455ed5.zip
New upstream version 1.8.0+dfsgupstream/1.8.0+dfsg
Diffstat (limited to 'tests/node.d/fronius.validation.spec.js')
-rw-r--r--tests/node.d/fronius.validation.spec.js154
1 files changed, 154 insertions, 0 deletions
diff --git a/tests/node.d/fronius.validation.spec.js b/tests/node.d/fronius.validation.spec.js
new file mode 100644
index 00000000..08b7e430
--- /dev/null
+++ b/tests/node.d/fronius.validation.spec.js
@@ -0,0 +1,154 @@
+"use strict";
+
+var netdata = require("../../node.d/node_modules/netdata");
+// remember: subject will be a singleton!
+var subject = require("../../node.d/fronius.node");
+
+var service = netdata.service({
+ name: "validation",
+ module: this
+});
+
+describe("fronius response validation", function () {
+
+ it("should do nothing if response is null", function () {
+ netdata.send = jasmine.createSpy("send");
+
+ subject.processResponse(service, null);
+ var result = netdata.send.calls.count();
+
+ expect(result).toBe(0);
+ });
+
+ it("should return null if response is null", function () {
+ var result = subject.convertToJson(null);
+
+ expect(result).toBeNull();
+ });
+
+ it("should return null and log error if response cannot be parsed", function () {
+ netdata.error = jasmine.createSpy("error");
+
+ // trailing commas are enough to create syntax exceptions
+ var result = subject.convertToJson("{name,}");
+
+ expect(result).toBeNull();
+ expect(netdata.error.calls.count()).toBe(1);
+ });
+
+ it("should return true if response is valid", function () {
+ var result = subject.isResponseValid({
+ "Body": {
+ "Data": {
+ "Site": {
+ "Mode": "meter"
+ },
+ "Inverters": {
+ "1": {}
+ }
+ }
+ }
+ });
+
+ expect(result).toBeTruthy();
+ });
+
+ it("should return false if response is missing data", function () {
+ var result = subject.isResponseValid({
+ "Body": {}
+ });
+
+ expect(result).toBeFalsy();
+ });
+
+ it("should return false if response is missing inverter", function () {
+ var result = subject.isResponseValid({
+ "Body": {
+ "Data": {
+ "Site": {}
+ }
+ }
+ });
+
+ expect(result).toBeFalsy();
+ });
+
+ it("should return false if response is missing inverter", function () {
+ var result = subject.isResponseValid({
+ "Body": {
+ "Data": {
+ "Inverters": {}
+ }
+ }
+ });
+
+ expect(result).toBeFalsy();
+ });
+
+});
+
+describe("fronius configuration validation", function () {
+
+ it("should return 0 if there are no servers configured", function () {
+ var result = subject.configure({});
+
+ expect(result).toBe(0);
+ });
+
+ it("should return 0 if the servers array is empty", function () {
+ var result = subject.configure({
+ "servers": []
+ });
+
+ expect(result).toBe(0);
+ });
+
+ it("should return 0 if there is one server configured incorrectly", function () {
+ var result = subject.configure({
+ "servers": [{}]
+ });
+
+ expect(result).toBe(0);
+ });
+
+ it("should return 1 if there is one server configured", function () {
+ subject.serviceExecute = jasmine.createSpy("serviceExecute");
+ var name = "solar1";
+ var result = subject.configure({
+ "servers": [{
+ "name": name,
+ "api_path": "/api/",
+ "hostname": "solar1.local"
+ }]
+ });
+
+ expect(result).toBe(1);
+ expect(subject.serviceExecute).toHaveBeenCalledWith(name, "solar1.local/api/", 5);
+ });
+
+ it("should return 2 if there are two servers configured", function () {
+ subject.serviceExecute = jasmine.createSpy("serviceExecute");
+ var name1 = "solar 1";
+ var name2 = "solar 2";
+ var result = subject.configure({
+ "servers": [
+ {
+ "name": name1,
+ "api_path": "/",
+ "hostname": "solar1.local"
+ },
+ {
+ "name": name2,
+ "api_path": "/",
+ "hostname": "solar2.local",
+ "update_every": 3
+ }
+ ]
+ });
+
+ expect(result).toBe(2);
+ expect(subject.serviceExecute).toHaveBeenCalledWith(name1, "solar1.local/", 5);
+ expect(subject.serviceExecute).toHaveBeenCalledWith(name2, "solar2.local/", 3);
+ });
+
+}); \ No newline at end of file