diff options
author | BrainDoctor <github.account@chrigel.net> | 2017-07-17 15:25:11 +0200 |
---|---|---|
committer | BrainDoctor <github.account@chrigel.net> | 2017-07-17 18:04:59 +0200 |
commit | 1fe557fe3d06f79f2f1c2db1684eeedccf2dc8d8 (patch) | |
tree | 368dff21b7604fd09a67b945284ae95c0b0b47fb /tests/node.d | |
parent | 4b4355e4c1f45f2d049d1c90d78b6c452213e5db (diff) |
Setup and docs for unit testing javascript in browser and node.js
Diffstat (limited to 'tests/node.d')
-rw-r--r-- | tests/node.d/fronius.spec.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/node.d/fronius.spec.js b/tests/node.d/fronius.spec.js new file mode 100644 index 0000000000..204f7f6fe4 --- /dev/null +++ b/tests/node.d/fronius.spec.js @@ -0,0 +1,58 @@ +"use strict"; +// delete these comments if not needed anymore. + +var netdata = require("../../node.d/node_modules/netdata"); +var fronius = require("../../node.d/fronius.node"); + +describe("fronius chart creation", function () { + + beforeEach(function () { + netdata.options.DEBUG = true; + }); + + it("should return a basic chart definition", function () { + // act + var result = fronius.createBasicDimension("id", "name", 2); + // assert + expect(result.divisor).toBe(2); + expect(result.id).toBe("id"); + expect(result.algorithm).toEqual("absolute"); + expect(result.multiplier).toBe(1); + }); + + it("will fail", function () { + netdata.debug("test"); + + throw new Error("expected failure to test unit test runner"); + }); + +}); + +describe("fronius data parsing", function () { + + var service = netdata.service({ + name: "fronius", + module: this + }); + + beforeEach(function () { + // change this to enable debug log + netdata.options.DEBUG = false; + }); + + it("should return a parsed value", function () { + // arrange + netdata.send = jasmine.createSpy("send"); + // act + fronius.processResponse(service, createFakeResponse()); + var result = netdata.send.calls[0].args[0]; + // assert + expect(result).toContain("SET p_grid = -3431"); + }); + + function createFakeResponse() { + // this is a faked JSON response from the server. + // Used with freeformatter.com/json-escape.html to escape the json and turn it into a string. + return "{\r\n\t\"Head\" : {\r\n\t\t\"RequestArguments\" : {},\r\n\t\t\"Status\" : {\r\n\t\t\t\"Code\" : 0,\r\n\t\t\t\"Reason\" : \"\",\r\n\t\t\t\"UserMessage\" : \"\"\r\n\t\t},\r\n\t\t\"Timestamp\" : \"2017-07-17T16:01:04+02:00\"\r\n\t},\r\n\t\"Body\" : {\r\n\t\t\"Data\" : {\r\n\t\t\t\"Site\" : {\r\n\t\t\t\t\"Mode\" : \"meter\",\r\n\t\t\t\t\"P_Grid\" : -3430.729923,\r\n\t\t\t\t\"P_Load\" : -910.270077,\r\n\t\t\t\t\"P_Akku\" : null,\r\n\t\t\t\t\"P_PV\" : 4341,\r\n\t\t\t\t\"rel_SelfConsumption\" : 20.969133,\r\n\t\t\t\t\"rel_Autonomy\" : 100,\r\n\t\t\t\t\"E_Day\" : 57230,\r\n\t\t\t\t\"E_Year\" : 6425915.5,\r\n\t\t\t\t\"E_Total\" : 15388710,\r\n\t\t\t\t\"Meter_Location\" : \"grid\"\r\n\t\t\t},\r\n\t\t\t\"Inverters\" : {\r\n\t\t\t\t\"1\" : {\r\n\t\t\t\t\t\"DT\" : 123,\r\n\t\t\t\t\t\"P\" : 4341,\r\n\t\t\t\t\t\"E_Day\" : 57230,\r\n\t\t\t\t\t\"E_Year\" : 6425915.5,\r\n\t\t\t\t\t\"E_Total\" : 15388710\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}" + } +}); |