Skip to content

Commit 85aa3ed

Browse files
Merge pull request #107 from ConsenSys/fix-bad-data
Fix sending bad data to API
2 parents 86aa793 + 47fbfdc commit 85aa3ed

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Client {
6767
* database using getIssues().
6868
*
6969
**/
70-
async analyze (options) {
70+
async analyze (options, timeout, initialDelay) {
7171
if (options === undefined || options.data === undefined) {
7272
// eslint-disable-next-line no-throw-literal
7373
throw 'Please provide analysis request JSON in a "data" attribute.'
@@ -107,8 +107,7 @@ class Client {
107107
There is also average queuing delay as well which on average may be at
108108
least 5 seconds.
109109
*/
110-
let timeout = options.timeout
111-
if (!('timeout' in options)) {
110+
if (!timeout) {
112111
timeout = (60 * 1000) * (
113112
(options.data.analysisMode !== 'full')
114113
? 5 // 5 minutes
@@ -129,7 +128,7 @@ class Client {
129128
console.log(`Cached Result:\n${util.inspect(result, { depth: depth })}\n------`)
130129
}
131130
} else {
132-
const initialDelay = Math.max(options.initialDelay || 0, defaultInitialDelay)
131+
initialDelay = Math.max(initialDelay || 0, defaultInitialDelay)
133132
try {
134133
result = await analysisPoller.do(requestResponse.uuid, this, timeout, initialDelay, options.debug)
135134
} catch (e) {
@@ -205,9 +204,9 @@ class Client {
205204
* {Object} status - status information as returned in each object of analyses().
206205
*
207206
**/
208-
async analyzeWithStatus (options) {
207+
async analyzeWithStatus (options, timeout, initialDelay) {
209208
const start = Date.now()
210-
const { issues, uuid } = await this.analyze(options, true)
209+
const { issues, uuid } = await this.analyze(options, timeout, initialDelay)
211210
const status = await this.getStatus(uuid)
212211
const elapsed = Date.now() - start
213212
return {

test/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('main module', () => {
109109
.returns(1)
110110

111111
sinon.stub(this.instance, 'analyze')
112-
.withArgs(input, true)
112+
.withArgs(input)
113113
.resolves({ issues: 'issues', uuid: 'uuid' })
114114

115115
sinon.stub(this.instance, 'getStatus')
@@ -304,7 +304,7 @@ describe('main module', () => {
304304
resolve({ access: accessToken, refresh: refreshToken })
305305
}))
306306
sinon.stub(requester, 'do')
307-
.withArgs({ data, timeout }, accessToken, parsedApiUrl)
307+
.withArgs({ data }, accessToken, parsedApiUrl)
308308
.returns(new Promise(resolve => {
309309
resolve({ uuid, status: 'Finished' })
310310
}))
@@ -316,7 +316,7 @@ describe('main module', () => {
316316
.returns(new Promise(resolve => {
317317
resolve(issues)
318318
}))
319-
await this.instance.analyze({ data, timeout }).should.eventually.deep.equal({ issues, uuid })
319+
await this.instance.analyze({ data }, timeout).should.eventually.deep.equal({ issues, uuid })
320320
poller.getIssues.restore()
321321
})
322322

@@ -328,14 +328,14 @@ describe('main module', () => {
328328
resolve({ access: accessToken, refresh: refreshToken })
329329
}))
330330
sinon.stub(requester, 'do')
331-
.withArgs({ data, timeout }, accessToken, parsedApiUrl)
331+
.withArgs({ data }, accessToken, parsedApiUrl)
332332
.returns(new Promise(resolve => {
333333
resolve({ uuid })
334334
}))
335335
sinon.stub(poller, 'do')
336336
.withArgs(uuid, this.instance, timeout, armlet.defaultInitialDelay, undefined)
337337
.resolves(issues)
338-
await this.instance.analyze({ data, timeout }).should.eventually.deep.equal({ issues, uuid })
338+
await this.instance.analyze({ data }, timeout).should.eventually.deep.equal({ issues, uuid })
339339
})
340340

341341
it('should pass initial delay option to poller', async () => {
@@ -347,7 +347,7 @@ describe('main module', () => {
347347
resolve({ access: accessToken, refresh: refreshToken })
348348
}))
349349
sinon.stub(requester, 'do')
350-
.withArgs({ data, timeout, initialDelay }, accessToken, parsedApiUrl)
350+
.withArgs({ data }, accessToken, parsedApiUrl)
351351
.returns(new Promise(resolve => {
352352
resolve({ uuid })
353353
}))
@@ -356,7 +356,7 @@ describe('main module', () => {
356356
.returns(new Promise(resolve => {
357357
resolve(issues)
358358
}))
359-
await this.instance.analyze({ data, timeout, initialDelay }).should.eventually.deep.equal({ issues, uuid })
359+
await this.instance.analyze({ data }, timeout, initialDelay).should.eventually.deep.equal({ issues, uuid })
360360
})
361361
})
362362

0 commit comments

Comments
 (0)