From 6f3c0245ad9c9595cad0dc2bbd2b02e670c9f870 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Wed, 9 Mar 2016 15:51:13 -0500 Subject: [PATCH] Add test for graph.createEmbed --- test/api/graph.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/api/graph.js diff --git a/test/api/graph.js b/test/api/graph.js new file mode 100644 index 0000000..f3ea9cf --- /dev/null +++ b/test/api/graph.js @@ -0,0 +1,47 @@ +var assert = require("assert"); +var client = require("../../lib/client"); +var extend = require("extend"); +var graph = require("../../lib/api/graph"); +var sinon = require("sinon"); + +describe("api/graph", function(){ + var stub_request; + beforeEach(function(){ + // Setup `client.request` as a stub + stub_request = sinon.stub(client, "request"); + }); + afterEach(function(){ + // Reset the original `client.request` + stub_request.restore(); + stub_request = null; + }); + describe("#creaetEmbed", function(){ + it("should make a valid api call", function(){ + var graphJSON = { + viz: "timeseries", + requests: [ + { + q: "system.cpu.idle{*}" + } + ] + }; + + // Make our api call + graph.createEmbed(graphJSON, "1_hour", "large", "yes", "test graph embed"); + + // Assert we properly called `client.request` + assert(stub_request.calledOnce); + var call_args = stub_request.getCall(0).args; + // Method and endpoint are correct + assert.equal(call_args[0], "POST"); + assert.equal(call_args[1], "/graph/embed"); + + // Properly formatted body and content-type + var params = call_args[2]; + var expectedBody = "graph_json=" + JSON.stringify(graphJSON) + + "&timeframe=1_hour&size=large&legend=yes&title=test graph embed"; + assert.equal(params.body, expectedBody); + assert(params.contentType, "application/x-form-urlencoded"); + }); + }); +});