From 7111724851cd17e2980feb509d2c1ea0e31e8c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 23 Oct 2017 12:32:38 +0300 Subject: [PATCH] Fix REST API monitor relationship test The test did not properly move the relationships from the old monitor to the new one. The test to passed as the relationship modification was not really tested. --- server/core/test/rest-api/test/monitor.js | 53 ++++++++++++----------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/server/core/test/rest-api/test/monitor.js b/server/core/test/rest-api/test/monitor.js index 89b7a006f..ace99007c 100644 --- a/server/core/test/rest-api/test/monitor.js +++ b/server/core/test/rest-api/test/monitor.js @@ -52,24 +52,26 @@ describe("Monitor Relationships", function() { relationships: { servers: null }}} - return request.patch(base_url + "/monitors/MySQL-Monitor", {body: mon}) + return request.patch(base_url + "/monitors/MySQL-Monitor", {json: mon}) .then(() => request.get(base_url + "/monitors/MySQL-Monitor", { json: true })) .then((res) => { - res.data.relationships.servers.should.be.undefined + res.data.relationships.should.not.have.keys("servers") }) }); it("add relationships to new monitor", function() { var mon = { data: { relationships: { - servers: [ - {id: "server1", type: "servers"}, - {id: "server2", type: "servers"}, - {id: "server3", type: "servers"}, - {id: "server4", type: "servers"}, - ] + servers: { + data:[ + {id: "server1", type: "servers"}, + {id: "server2", type: "servers"}, + {id: "server3", type: "servers"}, + {id: "server4", type: "servers"}, + ] + } }}} - return request.patch(base_url + "/monitors/" + monitor.data.id, {body: mon}) + return request.patch(base_url + "/monitors/" + monitor.data.id, {json: mon}) .then(() => request.get(base_url + "/monitors/" + monitor.data.id, { json: true })) .then((res) => { res.data.relationships.servers.data.should.have.lengthOf(4) @@ -77,27 +79,26 @@ describe("Monitor Relationships", function() { }); it("move relationships back to old monitor", function() { - - return request.get(base_url + "/monitors/" + monitor.data.id) - .then(function(resp) { - var mon = JSON.parse(resp) - delete mon.data.relationships.servers - return request.patch(base_url + "/monitors/" + monitor.data.id, {json: mon}) + var mon = {data: {relationships: {servers: null}}} + return request.patch(base_url + "/monitors/" + monitor.data.id, {json: mon}) + .then(() => request.get(base_url + "/monitors/" + monitor.data.id, { json: true })) + .then((res) => { + res.data.relationships.should.not.have.keys("servers") }) .then(function() { - return request.get(base_url + "/monitors/MySQL-Monitor") - }) - .then(function(resp) { - var mon = JSON.parse(resp) - mon.data.relationships.servers = [ - {id: "server1", type: "servers"}, - {id: "server2", type: "servers"}, - {id: "server3", type: "servers"}, - {id: "server4", type: "servers"}, - ] + mon.data.relationships.servers = { + data: [ + {id: "server1", type: "servers"}, + {id: "server2", type: "servers"}, + {id: "server3", type: "servers"}, + {id: "server4", type: "servers"}, + ]} return request.patch(base_url + "/monitors/MySQL-Monitor", {json: mon}) }) - .should.be.fulfilled + .then(() => request.get(base_url + "/monitors/MySQL-Monitor", { json: true })) + .then((res) => { + res.data.relationships.servers.data.should.have.lengthOf(4) + }) }); it("destroy created monitor", function() {