Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
feat: rename online -> exchange (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and daviddias committed Jul 4, 2017
1 parent 5627f47 commit 330e19f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BlockService {
* @param {Bitswap} bitswap
* @returns {void}
*/
goOnline (bitswap) {
setExchange (bitswap) {
this._bitswap = bitswap
}

Expand All @@ -36,7 +36,7 @@ class BlockService {
*
* @returns {void}
*/
goOffline () {
unsetExchange () {
this._bitswap = null
}

Expand All @@ -45,7 +45,7 @@ class BlockService {
*
* @returns {bool}
*/
isOnline () {
hasExchange () {
return this._bitswap != null
}

Expand All @@ -57,7 +57,7 @@ class BlockService {
* @returns {void}
*/
put (block, callback) {
if (this.isOnline()) {
if (this.hasExchange()) {
return this._bitswap.put(block, callback)
}

Expand All @@ -72,7 +72,7 @@ class BlockService {
* @returns {void}
*/
putMany (blocks, callback) {
if (this.isOnline()) {
if (this.hasExchange()) {
return this._bitswap.putMany(blocks, callback)
}

Expand All @@ -87,7 +87,7 @@ class BlockService {
* @returns {void}
*/
get (cid, callback) {
if (this.isOnline()) {
if (this.hasExchange()) {
return this._bitswap.get(cid, callback)
}

Expand Down
22 changes: 11 additions & 11 deletions test/block-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ module.exports = (repo) => {
})
})

it('goes offline', () => {
it('sets and unsets exchange', () => {
bs = new BlockService(repo)
bs.goOnline({})
expect(bs.isOnline()).to.be.eql(true)
bs.goOffline()
expect(bs.isOnline()).to.be.eql(false)
bs.setExchange({})
expect(bs.hasExchange()).to.be.eql(true)
bs.unsetExchange()
expect(bs.hasExchange()).to.be.eql(false)
})
})

describe('online', () => {
describe('has exchange', () => {
beforeEach(() => {
bs = new BlockService(repo)
})

it('isOnline returns true when online', () => {
bs.goOnline({})
expect(bs.isOnline()).to.be.eql(true)
it('hasExchange returns true when online', () => {
bs.setExchange({})
expect(bs.hasExchange()).to.be.eql(true)
})

it('retrieves a block through bitswap', (done) => {
Expand All @@ -156,7 +156,7 @@ module.exports = (repo) => {
}
}

bs.goOnline(bitswap)
bs.setExchange(bitswap)

const data = new Buffer('secret')

Expand All @@ -178,7 +178,7 @@ module.exports = (repo) => {
callback()
}
}
bs.goOnline(bitswap)
bs.setExchange(bitswap)

const data = new Buffer('secret sauce')

Expand Down

0 comments on commit 330e19f

Please sign in to comment.