Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CB-5510 update response codes for plugin success/fail callbacks
  • Loading branch information
bryanhiggins committed Nov 29, 2013
1 parent 1896d2c commit 339ea78286e930d94e3c497ede9a948d0dc985c4
Showing 2 changed files with 26 additions and 27 deletions.
@@ -91,19 +91,16 @@ module.exports = {
plugin[req.params.action](req,
function (result) {
res.send(200, encodeURIComponent(JSON.stringify({
code: 42,
data: result
code: 1,
data: result,
keepCallback: false
})));
},
function (code, error, httpCode) {
if (!httpCode) {
httpCode = 200;
}

res.send(httpCode, encodeURIComponent(JSON.stringify({
code: Math.abs(code) * -1 || -1,
data: null,
msg: error
function (error) {
res.send(200, encodeURIComponent(JSON.stringify({
code: 9,
data: error,
keepCallback: false
})));
},
req.params.args,
@@ -181,7 +181,7 @@ describe("server", function () {
);
});

it("returns the result and code 42 when success callback called", function () {
it("returns the result and code 1 when success callback called", function () {
spyOn(plugin, "exec").andCallFake(function (request, succ, fail, body) {
succ(["MyFeatureId"]);
});
@@ -191,24 +191,25 @@ describe("server", function () {

server.handle(req, res);
expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
code: 42,
data: ["MyFeatureId"]
code: 1,
data: ["MyFeatureId"],
keepCallback: false
})));
});

it("returns the result and code -1 when fail callback called", function () {
it("returns the result and code 9 when fail callback called", function () {
spyOn(plugin, "exec").andCallFake(function (request, succ, fail, body) {
fail(-1, "ErrorMessage");
fail("ErrorMessage");
});

req.params.service = "default";
req.params.action = "exec";

server.handle(req, res);
expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
code: -1,
data: null,
msg: "ErrorMessage"
code: 9,
data: "ErrorMessage",
keepCallback: false
})));
});
});
@@ -259,7 +260,7 @@ describe("server", function () {
);
});

it("returns the result and code 42 when success callback called", function () {
it("returns the result and code 1 when success callback called", function () {
var expectedResult = {"getReadOnlyFields": "Yogi bear"};

spyOn(applicationAPIServer, "getReadOnlyFields").andCallFake(function (success, fail) {
@@ -269,24 +270,25 @@ describe("server", function () {
server.handle(req, res);

expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
code: 42,
data: expectedResult
code: 1,
data: expectedResult,
keepCallback: false
})));
});

it("returns the result and code -1 when fail callback called", function () {
it("returns the result and code 9 when fail callback called", function () {
var expectedResult = "omg";

spyOn(applicationAPIServer, "getReadOnlyFields").andCallFake(function (success, fail) {
fail(-1, expectedResult);
fail(expectedResult);
});

server.handle(req, res);

expect(res.send).toHaveBeenCalledWith(200, encodeURIComponent(JSON.stringify({
code: -1,
data: null,
msg: expectedResult
code: 9,
data: expectedResult,
keepCallback: false
})));
});
});

0 comments on commit 339ea78

Please sign in to comment.