Skip to content

Commit

Permalink
Merge pull request #104 from ConsenSys/fix-103
Browse files Browse the repository at this point in the history
url.URL -> URL
  • Loading branch information
nbanmp authored Apr 23, 2019
2 parents 931c534 + e4ee448 commit 7c9420f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const url = require('url')
var URL
URL = URL || require('url').URL

const requester = require('./lib/requester')
const simpleRequester = require('./lib/simpleRequester')
Expand Down Expand Up @@ -34,7 +35,7 @@ class Client {
throw 'Please provide an Ethereum address and a password.'
}

const apiUrl = new url.URL(inputApiUrl)
const apiUrl = new URL(inputApiUrl)
if (!apiUrl.hostname) {
throw new TypeError(`${inputApiUrl} is not a valid URL`)
}
Expand Down Expand Up @@ -343,7 +344,7 @@ module.exports.mythXToolUse = (toolNames, inputApiUrl = defaultApiUrl) => {
}

module.exports.Client = Client
module.exports.defaultApiUrl = new url.URL(defaultApiUrl)
module.exports.defaultApiUrl = new URL(defaultApiUrl)
module.exports.defaultApiHost = defaultApiUrl
module.exports.defaultApiVersion = defaultApiVersion
module.exports.defaultInitialDelay = defaultInitialDelay
5 changes: 3 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const url = require('url')
var URL
URL = URL || require('url').URL

/**
* Wait for the specified time.
Expand All @@ -10,6 +11,6 @@ exports.timer = async time =>
new Promise(resolve => setTimeout(resolve, time))

exports.joinUrl = (base, path) => {
const u = new url.URL(path, base)
const u = new URL(path, base)
return u.href
}
8 changes: 5 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var URL
URL = URL || require('url').URL

const armlet = require('../index')
const Client = require('../index').Client
const sinon = require('sinon')
const url = require('url')
const HttpErrors = require('http-errors')
require('chai')
.use(require('chai-as-promised'))
Expand Down Expand Up @@ -64,7 +66,7 @@ describe('main module', () => {
it('initialize apiUrl to the given value', () => {
const instance = new Client({ ethAddress, password }, apiUrl)

instance.apiUrl.should.be.deep.equal(new url.URL(apiUrl))
instance.apiUrl.should.be.deep.equal(new URL(apiUrl))
})

describe('instances should', () => {
Expand Down Expand Up @@ -168,7 +170,7 @@ describe('main module', () => {
describe('functionality', () => {
const uuid = 'analysis-uuid'
const issues = ['issue1', 'issue2']
const parsedApiUrl = new url.URL(apiUrl)
const parsedApiUrl = new URL(apiUrl)
const refreshToken = 'refresh-token'
const accessToken = 'access-token'

Expand Down
6 changes: 4 additions & 2 deletions test/lib/analysisPoller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var URL
URL = URL || require('url').URL

const nock = require('nock')
const url = require('url')
const sinon = require('sinon')
require('chai')
.use(require('chai-as-promised'))
Expand All @@ -10,7 +12,7 @@ const util = require('../../lib/util')

describe('analysisPoller', () => {
describe('#do', () => {
const apiUrl = new url.URL('https://api.mythx.io')
const apiUrl = new URL('https://api.mythx.io')
const validApiKey = 'valid-api-key'
const uuid = 'my-uuid'
const statusUrl = `/v1/analyses/${uuid}`
Expand Down
8 changes: 5 additions & 3 deletions test/lib/login.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var URL
URL = URL || require('url').URL

const nock = require('nock')
const url = require('url')
require('chai')
.use(require('chai-as-promised'))
.should()
Expand All @@ -9,7 +11,7 @@ const login = require('../../lib/login')
describe('login', () => {
describe('#do', () => {
const apiUrl = 'https://localhost:3100'
const parsedApiUrl = new url.URL(apiUrl)
const parsedApiUrl = new URL(apiUrl)
const ethAddress = '0x74B904af705Eb2D5a6CDc174c08147bED478a60d'
const password = 'password'
const auth = { ethAddress, password }
Expand All @@ -31,7 +33,7 @@ describe('login', () => {
.post(loginPath, auth)
.reply(200, jsonTokens)

const parsedApiUrlHttp = new url.URL('http://localhost:3100')
const parsedApiUrlHttp = new URL('http://localhost:3100')
await login.do(ethAddress, password, parsedApiUrlHttp)
.should.eventually.deep.equal(jsonTokens)
})
Expand Down
6 changes: 4 additions & 2 deletions test/lib/refresh.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var URL
URL = URL || require('url').URL

const nock = require('nock')
const url = require('url')
require('chai')
.use(require('chai-as-promised'))
.should()
Expand All @@ -9,7 +11,7 @@ const refresh = require('../../lib/refresh')
describe('refresh', () => {
describe('#do', () => {
const apiUrl = 'https://localhost:3100'
const parsedApiUrl = new url.URL(apiUrl)
const parsedApiUrl = new URL(apiUrl)
const refreshPath = '/v1/auth/refresh'
const expiredRefreshToken = 'expiredRefresh'
const expiredAccessToken = 'expiredAccess'
Expand Down
12 changes: 7 additions & 5 deletions test/lib/requester.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var URL
URL = URL || require('url').URL

const nock = require('nock')
const url = require('url')
require('chai')
.use(require('chai-as-promised'))
.should()
Expand All @@ -8,9 +10,9 @@ const requester = require('../../lib/requester')

describe('requester', () => {
describe('#do', () => {
const defaultApiUrl = new url.URL('https://api.mythx.io')
const httpApiUrl = new url.URL('http://localhost:3100')
const httpsApiUrl = new url.URL('https://localhost:3100')
const defaultApiUrl = new URL('https://api.mythx.io')
const httpApiUrl = new URL('http://localhost:3100')
const httpsApiUrl = new URL('https://localhost:3100')

const validApiKey = 'valid-api-key'
const uuid = 'my-uuid'
Expand Down Expand Up @@ -72,7 +74,7 @@ describe('requester', () => {
})

it('should reject on api server connection failure', async () => {
const invalidApiHostname = new url.URL('http://not-a-valid-hostname')
const invalidApiHostname = new URL('http://not-a-valid-hostname')

await requester.do(data, validApiKey, invalidApiHostname).should.be.rejectedWith(Error)
})
Expand Down

0 comments on commit 7c9420f

Please sign in to comment.