Skip to content

Commit ab9a10c

Browse files
fix post parameters
1 parent 1d05710 commit ab9a10c

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

lib/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ TestingBot.prototype.request = function(req_data, callback) {
148148
}
149149
};
150150

151-
if (req_data.method !== 'GET' && req_data.data) {
152-
requestOptions.json = req_data.data;
151+
if (req_data.method !== 'GET') {
152+
requestOptions.form = req_data.data;
153153
}
154154

155155
request(requestOptions, function(error, response) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "TestingBot <[email protected]> (testingbot.com)",
33
"name": "testingbot-api",
44
"description": "A wrapper around TestingBot's REST API",
5-
"version": "1.0.3",
5+
"version": "1.0.4",
66
"scripts": {
77
"lint": "eslint .",
88
"test": "make test"

test/api_test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,55 @@ describe('Api Tests', function() {
6565
});
6666
});
6767
});
68+
69+
it('should update a test by specifying legacy data', function(done) {
70+
var that = this;
71+
this.api.getTests(function(err, response) {
72+
assert.equal(response.data && response.data.length > 0, true);
73+
var singleTest = response.data[0];
74+
that.api.getTestDetails(singleTest.id, function(err, response) {
75+
assert.notEqual(response, null);
76+
var payload = { "test[success]" : "1", "test[status_message]" : "test" };
77+
that.api.updateTest(payload, singleTest.id, function(err) {
78+
that.api.getTestDetails(singleTest.id, function(err, response) {
79+
assert.equal(response.status_message, "test");
80+
done();
81+
});
82+
});
83+
});
84+
});
85+
});
86+
87+
it('should update a test by specifying object data', function(done) {
88+
var that = this;
89+
this.api.getTests(function(err, response) {
90+
assert.equal(response.data && response.data.length > 0, true);
91+
var singleTest = response.data[0];
92+
that.api.getTestDetails(singleTest.id, function(err, response) {
93+
assert.notEqual(response, null);
94+
var payload = { test: { success: 1, status_message: "test2" } };
95+
that.api.updateTest(payload, singleTest.id, function(err) {
96+
that.api.getTestDetails(singleTest.id, function(err, response) {
97+
assert.equal(response.status_message, "test2");
98+
done();
99+
});
100+
});
101+
});
102+
});
103+
});
104+
105+
it('should be possible to delete a test', function(done) {
106+
var that = this;
107+
this.api.getTests(function(err, response) {
108+
assert.equal(response.data && response.data.length > 0, true);
109+
var singleTest = response.data[0];
110+
that.api.deleteTest(singleTest.id, function(err, response) {
111+
that.api.getTestDetails(singleTest.id, function(err, response) {
112+
assert.equal(response, null);
113+
assert.notEqual(err, null);
114+
done();
115+
});
116+
});
117+
});
118+
});
68119
});

0 commit comments

Comments
 (0)