Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
refactor: remove v2 from endpoint requests (#1913)
Browse files Browse the repository at this point in the history
  • Loading branch information
brenopolanski authored May 9, 2020
1 parent fac7e77 commit 420e1a4
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 113 deletions.
2 changes: 1 addition & 1 deletion __tests__/unit/components/Network/NetworkModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('NetworkModal', () => {

it('should fetch data and populate', async () => {
nock('http://1.2.3.4')
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
nethash: 1234,
Expand Down
24 changes: 12 additions & 12 deletions __tests__/unit/services/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ describe('Services > Client', () => {
it('should create a new connection', () => {
const connection = ClientService.newConnection('http://localhost')

expect(connection.host).toBe('http://localhost/api/v2')
expect(connection.host).toBe('http://localhost/api')
})

it('should set timeout if provided', () => {
Expand All @@ -225,7 +225,7 @@ describe('Services > Client', () => {
describe('fetchNetworkConfig', () => {
const mockEndpoint = (config) => {
nock('http://127.0.0.1')
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: config
})
Expand Down Expand Up @@ -294,7 +294,7 @@ describe('Services > Client', () => {
}

nock('http://127.0.0.1')
.get('/api/v2/node/configuration/crypto')
.get('/api/node/configuration/crypto')
.reply(200, {
data: cryptoConfig
})
Expand All @@ -306,7 +306,7 @@ describe('Services > Client', () => {
describe('fetchFeeStatistics', () => {
const mockEndpoint = (config) => {
nock('http://127.0.0.1')
.get('/api/v2/node/fees')
.get('/api/node/fees')
.query({ days: 7 })
.reply(200, {
data: config
Expand Down Expand Up @@ -364,7 +364,7 @@ describe('Services > Client', () => {

it('should return empty array on error', async () => {
nock('http://127.0.0.1')
.get('/api/v2/node/fees')
.get('/api/node/fees')
.query({ days: 7 })
.reply(500)

Expand All @@ -376,13 +376,13 @@ describe('Services > Client', () => {
it('should return formatted host', () => {
client.host = 'http://6.6.6.6'

expect(client.host).toEqual('http://6.6.6.6/api/v2')
expect(client.host).toEqual('http://6.6.6.6/api')
})

it('should update current client', () => {
client.host = 'http://7.7.7.7'

expect(client.client.host).toEqual('http://7.7.7.7/api/v2')
expect(client.client.host).toEqual('http://7.7.7.7/api')
})
})

Expand All @@ -396,7 +396,7 @@ describe('Services > Client', () => {
}

nock('http://127.0.0.1:4003')
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(200, {
data: response
})
Expand Down Expand Up @@ -444,7 +444,7 @@ describe('Services > Client', () => {
}

nock('http://127.0.0.1:4003')
.get('/api/v2/delegates/USERNAME/voters')
.get('/api/delegates/USERNAME/voters')
.reply(200, {
meta,
data: {}
Expand Down Expand Up @@ -562,7 +562,7 @@ describe('Services > Client', () => {
}

nock('http://127.0.0.1:4003')
.get('/api/v2/businesses/BUSINESS_ID/bridgechains?page=1&limit=50&orderBy=name%3Aasc')
.get('/api/businesses/BUSINESS_ID/bridgechains?page=1&limit=50&orderBy=name%3Aasc')
.reply(200, response)

expect(await client.fetchBusinessBridgechains('BUSINESS_ID')).toEqual(response)
Expand Down Expand Up @@ -2046,7 +2046,7 @@ describe('Services > Client', () => {
describe('broadcastTransaction', () => {
beforeEach(() => {
nock('http://127.0.0.1:4003')
.post('/api/v2/transactions')
.post('/api/transactions')
.reply(200, {
data: 'transaction'
})
Expand Down Expand Up @@ -2118,7 +2118,7 @@ describe('Services > Client', () => {

for (const ip of ['1.1.1.1', '2.2.2.2']) {
nock(`http://${ip}:8080`)
.post('/api/v2/transactions')
.post('/api/transactions')
.reply(200, {
data: `broadcast transaction for ${ip}`
})
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/store/modules/delegate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('delegate store module', () => {
describe('load', () => {
it('should fetch delegates from api', async () => {
nock('http://127.0.0.1')
.get('/api/v2/delegates')
.get('/api/delegates')
.query({ page: 1, limit: 100, orderBy: 'rank:asc' })
.reply(200, {
data: delegates,
Expand All @@ -74,7 +74,7 @@ describe('delegate store module', () => {

for (let page = 1; page <= pageCount; page++) {
nock('http://127.0.0.1')
.get('/api/v2/delegates')
.get('/api/delegates')
.query({ page, limit: 100, orderBy: 'rank:asc' })
.reply(200, {
data: delegates.map(delegate => ({ ...delegate, address: `${delegate.address}-${page}` })),
Expand Down
4 changes: 2 additions & 2 deletions __tests__/unit/store/modules/ledger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('ledger store module', () => {
it('should load all wallets with multi-wallet search', async () => {
nock('http://127.0.0.1')
.persist()
.post('/api/v2/wallets/search')
.post('/api/wallets/search')
.reply(200, {
data: ledgerWallets.slice(0, 9)
})
Expand All @@ -374,7 +374,7 @@ describe('ledger store module', () => {

nock('http://127.0.0.1')
.persist()
.post('/api/v2/wallets/search')
.post('/api/wallets/search')
.reply(200, {
data: ledgerWallets.slice(0, 9)
})
Expand Down
42 changes: 21 additions & 21 deletions __tests__/unit/store/modules/peer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('peer store module', () => {
it('should get & set current peer', async () => {
for (const peer of peers) {
nock(`http://${peer.ip}:${peer.port}`)
.get('/api/v2/transactions/fees')
.get('/api/transactions/fees')
.reply(200, {
data: {
send: 1,
Expand Down Expand Up @@ -122,23 +122,23 @@ describe('peer store module', () => {
for (const peer of peers) {
nock(`http://${peer.ip}:${peer.port}`)
.persist()
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(200, {
data: {
height: 20000
}
})
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
nethash
}
})
.get('/api/v2/blocks/getEpoch')
.get('/api/blocks/getEpoch')
.reply(200, {
epoch: new Date()
})
.get('/api/v2/transactions/fees')
.get('/api/transactions/fees')
.reply(200, {
data: {
send: 1,
Expand All @@ -147,7 +147,7 @@ describe('peer store module', () => {
vote: 1
}
})
.get('/api/v2/peers')
.get('/api/peers')
.reply(200, {
data: peerResponse
})
Expand All @@ -167,7 +167,7 @@ describe('peer store module', () => {

nock(`http://${goodPeer1.ip}:${goodPeer1.ports['@arkecosystem/core-api']}`)
.persist()
.get('/api/v2/transactions/fees')
.get('/api/transactions/fees')
.reply(200, {
data: {
send: 1,
Expand All @@ -180,7 +180,7 @@ describe('peer store module', () => {
for (const peer of refreshPeers) {
nock(`http://${peer.ip}:${peer.ports['@arkecosystem/core-api']}`)
.persist()
.get('/api/v2/peers')
.get('/api/peers')
.reply(200, {
data: refreshPeers
})
Expand All @@ -205,13 +205,13 @@ describe('peer store module', () => {
client.host = host

nock(host)
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(200, {
data: {
height: 21000
}
})
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
constants: {},
Expand All @@ -229,7 +229,7 @@ describe('peer store module', () => {
it('should update current peer status', async () => {
nock(`http://${goodPeer1.ip}:${goodPeer1.port}`)
.persist()
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
constants: {
Expand All @@ -238,13 +238,13 @@ describe('peer store module', () => {
nethash
}
})
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(200, {
data: {
height: 10000
}
})
.get('/api/v2/transactions/fees')
.get('/api/transactions/fees')
.reply(200, {
data: {
send: 1,
Expand All @@ -268,14 +268,14 @@ describe('peer store module', () => {

it('should validate a v2 peer successfully', async () => {
nock(`http://${goodPeer1.ip}:${goodPeer1.port}`)
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
constants: {},
nethash
}
})
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(200, {
data: {
height: 10002
Expand All @@ -293,14 +293,14 @@ describe('peer store module', () => {

it('should validate a v2 https peer successfully', async () => {
nock(`https://${goodPeer1.ip}:${goodPeer1.port}`)
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
constants: {},
nethash
}
})
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(200, {
data: {
height: 10002
Expand All @@ -322,7 +322,7 @@ describe('peer store module', () => {

it('should fail validating a v2 peer due to bad network url', async () => {
nock(`http://${goodPeer1.ip}:${goodPeer1.port}`)
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(400)

const response = await store.dispatch('peer/validatePeer', { ...goodPeer1, timeout: 100 })
Expand All @@ -331,14 +331,14 @@ describe('peer store module', () => {

it('should fail validating a v2 peer due to bad sync status url', async () => {
nock(`http://${goodPeer1.ip}:${goodPeer1.port}`)
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
constants: {},
nethash
}
})
.get('/api/v2/node/syncing')
.get('/api/node/syncing')
.reply(400)

const response = await store.dispatch('peer/validatePeer', { ...goodPeer1, timeout: 100 })
Expand All @@ -348,7 +348,7 @@ describe('peer store module', () => {
it('should fail validating a v2 peer because of wrong nethash', async () => {
nock(`http://${goodPeer1.ip}:${goodPeer1.port}`)
.persist()
.get('/api/v2/node/configuration')
.get('/api/node/configuration')
.reply(200, {
data: {
constants: {},
Expand Down
2 changes: 1 addition & 1 deletion __tests__/unit/store/modules/transaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('TransactionModule', () => {
describe('dispatch updateStaticFees', () => {
it('should return update all fees on v2', async () => {
nock('http://127.0.0.1:4003')
.get('/api/v2/transactions/fees')
.get('/api/transactions/fees')
.reply(200, {
data: {
transfer: 1,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@arkecosystem/core-magistrate-crypto": "^2.6.27",
"@arkecosystem/crypto": "^2.6.27",
"@arkecosystem/ledger-transport": "^1.0.5",
"@arkecosystem/peers": "^0.2.1",
"@arkecosystem/peers": "^0.3.0",
"@arkecosystem/platform-sdk": "^0.0.2",
"@babel/runtime": "^7.4.2",
"@fortawesome/fontawesome-svg-core": "^1.2.21",
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/services/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ClientService {
* @return {Connection}
*/
static newConnection (server, timeout) {
return new Connection(`${server}/api/v2`).withOptions({
return new Connection(`${server}/api`).withOptions({
timeout: timeout || 5000
})
}
Expand Down Expand Up @@ -151,7 +151,7 @@ export default class ClientService {
}

set host (host) {
this.__host = `${host}/api/v2`
this.__host = `${host}/api`
this.client = ClientService.newConnection(host)
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/store/modules/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ export default {
const peerUrl = getBaseUrl(getters.current())

return PeerDiscovery.new({
networkOrHost: `${peerUrl}/api/v2/peers`
networkOrHost: `${peerUrl}/api/peers`
})
}

return PeerDiscovery.new({
networkOrHost: `${network.server}/api/v2/peers`
networkOrHost: `${network.server}/api/peers`
})
},

Expand Down
Loading

0 comments on commit 420e1a4

Please sign in to comment.