Skip to content

Commit adec6b1

Browse files
committed
various updates
1 parent e935d88 commit adec6b1

File tree

6 files changed

+194
-47
lines changed

6 files changed

+194
-47
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ clean:
99
lint:
1010
eslint lib/
1111
test: clean lint
12-
mocha -t 6000 --reporter spec test/ $(MOCHAFLAGS)
12+
mocha -t 6000 --reporter spec test/ $(MOCHAFLAGS)

README.md

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Wrapper around the TestingBot REST API for [Node.js](http://nodejs.org/).
1414
npm install testingbot-api
1515
```
1616

17+
## Credentials
18+
You can use environment variables `TESTINGBOT_KEY` and `TESTINGBOT_SECRET` to pass your TestingBot key and secret to the API client.
19+
The key and secret can be obtained from [TestingBot](https://testingbot.com/members/user/edit) .
20+
1721
## Using the wrapper
1822

1923
```javascript
@@ -23,10 +27,100 @@ var tb = new TestingBot({
2327
api_key: "your-tb-key",
2428
api_secret: "your-tb-secret"
2529
});
30+
```
2631

27-
tb.getUserInfo(function(err, data) {
28-
console.log(data);
29-
});
32+
### getBrowsers
33+
Gets a list of browsers you can test on
34+
35+
```javascript
36+
api.getBrowsers(function(error, browsers) {});
37+
```
38+
39+
40+
### getUserInfo
41+
Gets your user information
42+
43+
```javascript
44+
api.getUserInfo(function(error, userInfo) {});
45+
```
46+
47+
### getTests
48+
Gets list of your latest tests
49+
50+
```javascript
51+
api.getTests(function(error, tests) {}, offset, limit);
52+
```
53+
54+
### getTestDetails
55+
Gets details for a single test, pass the WebDriver's SessionID
56+
57+
```javascript
58+
api.getTestDetails(sessionId, function(error, testDetails) {});
59+
```
60+
61+
### updateTest
62+
Updates a single test. For example, update the `passed` state of a test (whether it was successful or not).
63+
64+
```javascript
65+
var testData = { "test[success]" : "1", "test[status_message]" : "test" };
66+
api.updateTest(testData, sessionId, function(error, testDetails) {});
67+
```
68+
69+
### deleteTest
70+
Deletes a single test, pass the WebDriver's SessionID
71+
72+
```javascript
73+
api.deleteTest(sessionId, function(error, success) {});
74+
```
75+
76+
### stopTest
77+
Stops a single test, pass the WebDriver's SessionID
78+
79+
```javascript
80+
api.stopTest(sessionId, function(error, success) {});
81+
```
82+
83+
### getTunnelList
84+
Gets list of active tunnels
85+
86+
```javascript
87+
api.getTunnelList(function(error, tunnelList) {});
88+
```
89+
90+
### deleteTunnel
91+
Deletes a single Tunnel
92+
93+
```javascript
94+
api.deleteTunnel(tunnelId, function(error, success) {});
95+
```
96+
97+
### getBuilds
98+
Retrieves the latest builds
99+
100+
```javascript
101+
api.getBuilds(function(error, builds) {}, offset, limit);
102+
```
103+
104+
### getTestsForBuild
105+
Retrieves the tests for a single build
106+
107+
```javascript
108+
api.getTestsForBuild(buildId, function(error, tests) {});
109+
```
110+
111+
### deleteBuild
112+
Deletes a single build
113+
114+
```javascript
115+
api.deleteBuild(buildId, function(error, success) {});
116+
```
117+
118+
### getAuthenticationHashForSharing
119+
Calculates the authentication hash for sharing, pass the WebDriver's SessionID.
120+
This is used to [share a test's detail page on TestingBot](https://testingbot.com/support/other/sharing)
121+
122+
```javascript
123+
api.getAuthenticationHashForSharing(sessionId);
30124
```
31125

32126
## Tests
@@ -41,7 +135,7 @@ Check out the [TestingBot REST API](https://testingbot.com/support/api) for more
41135

42136
The MIT License (MIT)
43137

44-
Copyright (c) 2017 TestingBot.com
138+
Copyright (c) TestingBot.com
45139

46140
Permission is hereby granted, free of charge, to any person obtaining a copy
47141
of this software and associated documentation files (the "Software"), to deal

lib/api.js

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var querystring = require('qs');
44
var fs = require('fs');
55
var path = require('path');
66
var request = require('request');
7+
var crypto = require('crypto');
78

89
function TestingBot(options) {
910
this.options = options || {};
@@ -27,13 +28,6 @@ function TestingBot(options) {
2728
}
2829
}
2930

30-
TestingBot.prototype.getTestDetails = function(testID, callback) {
31-
this.request({
32-
method: 'GET',
33-
url: '/tests/' + testID
34-
}, callback);
35-
};
36-
3731
TestingBot.prototype.getBrowsers = function(callback, type) {
3832
var data = {};
3933
if (type) {
@@ -46,24 +40,18 @@ TestingBot.prototype.getBrowsers = function(callback, type) {
4640
}, callback);
4741
};
4842

49-
TestingBot.prototype.getLabTestDetails = function(testID, callback) {
50-
this.request({
51-
method: 'GET',
52-
url: '/lab/' + testID
53-
}, callback);
54-
};
55-
56-
TestingBot.prototype.getTunnel = function(callback) {
43+
TestingBot.prototype.getUserInfo = function(callback) {
5744
this.request({
5845
method: 'GET',
59-
url: '/tunnel'
46+
url: '/user'
6047
}, callback);
6148
};
6249

63-
TestingBot.prototype.getUserInfo = function(callback) {
50+
TestingBot.prototype.updateUserInfo = function(data, callback) {
6451
this.request({
65-
method: 'GET',
66-
url: '/user'
52+
method: 'PUT',
53+
url: '/user',
54+
data: data
6755
}, callback);
6856
};
6957

@@ -81,6 +69,56 @@ TestingBot.prototype.getTests = function(callback, offset, limit) {
8169
}, callback);
8270
};
8371

72+
TestingBot.prototype.getTestDetails = function(testID, callback) {
73+
this.request({
74+
method: 'GET',
75+
url: '/tests/' + testID
76+
}, callback);
77+
};
78+
79+
TestingBot.prototype.updateTest = function(data, testID, callback) {
80+
this.request({
81+
method: 'PUT',
82+
url: '/tests/' + testID,
83+
data: data
84+
}, callback);
85+
};
86+
87+
TestingBot.prototype.deleteTest = function(testID, callback) {
88+
this.request({
89+
method: 'DELETE',
90+
url: '/tests/' + testID
91+
}, callback);
92+
};
93+
94+
TestingBot.prototype.stopTest = function(testID, callback) {
95+
this.request({
96+
method: 'PUT',
97+
url: '/tests/' + testID + '/stop'
98+
}, callback);
99+
};
100+
101+
TestingBot.prototype.getTunnel = function(callback) {
102+
this.request({
103+
method: 'GET',
104+
url: '/tunnel'
105+
}, callback);
106+
};
107+
108+
TestingBot.prototype.getTunnelList = function(callback) {
109+
this.request({
110+
method: 'GET',
111+
url: '/tunnel/list'
112+
}, callback);
113+
};
114+
115+
TestingBot.prototype.deleteTunnel = function(tunnelId, callback) {
116+
this.request({
117+
method: 'DELETE',
118+
url: '/tunnel/' + tunnelId
119+
}, callback);
120+
};
121+
84122
TestingBot.prototype.getLabTests = function(callback, offset, limit) {
85123
if (!offset) {
86124
offset = 0;
@@ -95,34 +133,39 @@ TestingBot.prototype.getLabTests = function(callback, offset, limit) {
95133
}, callback);
96134
};
97135

98-
TestingBot.prototype.updateUserInfo = function(data, callback) {
136+
TestingBot.prototype.updateLabTest = function(data, testID, callback) {
99137
this.request({
100138
method: 'PUT',
101-
url: '/user',
139+
url: '/lab/' + testID,
102140
data: data
103141
}, callback);
104142
};
105143

106-
TestingBot.prototype.updateTest = function(data, testID, callback) {
144+
TestingBot.prototype.getBuilds = function(callback, offset, limit) {
145+
if (!offset) {
146+
offset = 0;
147+
}
148+
if (!limit) {
149+
limit = 10;
150+
}
151+
107152
this.request({
108-
method: 'PUT',
109-
url: '/tests/' + testID,
110-
data: data
153+
method: 'GET',
154+
url: '/builds?offset=' + offset + '&limit=' + limit
111155
}, callback);
112156
};
113157

114-
TestingBot.prototype.updateLabTest = function(data, testID, callback) {
158+
TestingBot.prototype.getTestsForBuild = function(buildId, callback) {
115159
this.request({
116-
method: 'PUT',
117-
url: '/lab/' + testID,
118-
data: data
160+
method: 'GET',
161+
url: '/builds/' + buildId
119162
}, callback);
120163
};
121164

122-
TestingBot.prototype.deleteTest = function(testID, callback) {
165+
TestingBot.prototype.deleteBuild = function(buildId, callback) {
123166
this.request({
124167
method: 'DELETE',
125-
url: '/tests/' + testID
168+
url: '/builds/' + buildId
126169
}, callback);
127170
};
128171

@@ -133,6 +176,10 @@ TestingBot.prototype.deleteLabTest = function(testID, callback) {
133176
}, callback);
134177
};
135178

179+
TestingBot.prototype.getAuthenticationHashForSharing = function(sessionId) {
180+
return crypto.createHash('md5').update(this.options.api_key + ':' + this.options.api_secret + ':' + sessionId).digest('hex');
181+
};
182+
136183
TestingBot.prototype.request = function(req_data, callback) {
137184
var requestPath = '/v1' + req_data.url;
138185
if (req_data.method === 'GET' && req_data.data) {
@@ -154,7 +201,7 @@ TestingBot.prototype.request = function(req_data, callback) {
154201

155202
request(requestOptions, function(error, response) {
156203
var responseBody = null;
157-
if (typeof(response.body) === 'string') {
204+
if (response.body && typeof(response.body) === 'string') {
158205
response.body = JSON.parse(response.body);
159206
}
160207
if (response.statusCode.toString().substring(0, 1) === '2') {

package.json

Lines changed: 10 additions & 10 deletions
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.5",
5+
"version": "1.0.6",
66
"scripts": {
77
"lint": "eslint .",
88
"test": "make test"
@@ -13,19 +13,19 @@
1313
"url": "git://github.com/testingbot/testingbot-api.git"
1414
},
1515
"devDependencies": {
16-
"eslint": "^3.15.0",
17-
"eslint-config-airbnb-base": "^11.1.0",
18-
"eslint-config-standard": "^10.2.1",
19-
"eslint-plugin-import": "^2.2.0",
20-
"eslint-plugin-promise": "^3.4.1",
21-
"eslint-plugin-standard": "^3.0.1",
22-
"mocha": "^3.1.2"
16+
"eslint": "^5.12.1",
17+
"eslint-config-airbnb-base": "^13.1.0",
18+
"eslint-config-standard": "^12.0.0",
19+
"eslint-plugin-import": "^2.16.0",
20+
"eslint-plugin-promise": "^4.0.1",
21+
"eslint-plugin-standard": "^4.0.0",
22+
"mocha": "^5.2.0"
2323
},
2424
"engines": {
2525
"node": "*"
2626
},
2727
"dependencies": {
28-
"qs": "^6.3.1",
29-
"request": "^2.79.0"
28+
"qs": "^6.6.0",
29+
"request": "^2.88.0"
3030
}
3131
}

test/api_test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ describe('Api Tests', function() {
6666
});
6767
});
6868

69+
it('should share a test', function(done) {
70+
assert.equal(this.api.getAuthenticationHashForSharing('sampleSessionId'), '7af1007a329eeeef3c69577517ca827c');
71+
done();
72+
});
73+
6974
it('should update a test by specifying legacy data', function(done) {
7075
var that = this;
7176
this.api.getTests(function(err, response) {

0 commit comments

Comments
 (0)