fronius.process.spec.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. "use strict";
  2. // SPDX-License-Identifier: GPL-3.0-or-later
  3. var netdata = require("../../node.d/node_modules/netdata");
  4. // remember: subject will be a singleton!
  5. var subject = require("../../node.d/fronius.node");
  6. var service = netdata.service({
  7. name: "process",
  8. module: this
  9. });
  10. var exampleResponse = {
  11. "Body": {
  12. "Data": {
  13. "Site": {
  14. "Mode": "meter",
  15. "P_Grid": -3430.729923,
  16. "P_Load": -910.270077,
  17. "P_Akku": null,
  18. "P_PV": 4341,
  19. "rel_SelfConsumption": 20.969133,
  20. "rel_Autonomy": 100,
  21. "E_Day": 57230,
  22. "E_Year": 6425915.5,
  23. "E_Total": 15388710,
  24. "Meter_Location": "grid"
  25. },
  26. "Inverters": {
  27. "1": {
  28. "DT": 123,
  29. "P": 4341,
  30. "E_Day": 57230,
  31. "E_Year": 6425915.5,
  32. "E_Total": 15388710
  33. }
  34. }
  35. }
  36. }
  37. };
  38. describe("fronius main processing", function () {
  39. beforeAll(function () {
  40. // change this to enable debug log
  41. netdata.options.DEBUG = false;
  42. });
  43. beforeEach(function () {
  44. deleteProperties(subject.charts);
  45. });
  46. it("should send parsed values to netdata", function () {
  47. netdata.send = jasmine.createSpy("send");
  48. subject.processResponse(service, exampleResponse);
  49. expect(netdata.send.calls.count()).toBe(6);
  50. // check if some parsed values were sent.
  51. var powerChart = netdata.send.calls.argsFor(5)[0];
  52. expect(powerChart).toContain("SET p_grid = -3431");
  53. expect(powerChart).toContain("SET p_pv = 4341");
  54. var inverterChart = netdata.send.calls.argsFor(0)[0];
  55. expect(inverterChart).toContain("SET 1 = 4341");
  56. var autonomyChart = netdata.send.calls.argsFor(3)[0];
  57. expect(autonomyChart).toContain("SET rel_selfconsumption = 21");
  58. });
  59. });