-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted apm versions command logic
- Loading branch information
1 parent
20ab9c0
commit 49f42ce
Showing
5 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,9 @@ | |
], | ||
"env": { | ||
"test": { | ||
"plugins": [ "istanbul" ] | ||
"plugins": [ | ||
"istanbul" | ||
] | ||
} | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const APM = require('@aragon/apm') | ||
|
||
module.exports = async (web3, apmRepoName, apmOptions, progressHandler) => { | ||
if (progressHandler) { | ||
progressHandler(1) | ||
} | ||
|
||
// Ensure the ens-registry property is present, | ||
// and available with the name "ensRegistryAddress". | ||
if (!apmOptions.ensRegistryAddress) { | ||
if (apmOptions['ens-registry']) { | ||
apmOptions.ensRegistryAddress = apmOptions['ens-registry'] | ||
} else { | ||
throw new Error('ens-registry not found in given apm options.') | ||
} | ||
} | ||
|
||
// Prepare APM object that can comunicate with the apm contracts. | ||
const apm = await APM(web3, apmOptions) | ||
|
||
if (progressHandler) { | ||
progressHandler(2) | ||
} | ||
|
||
// Query all versions for this repo. | ||
const versions = await apm.getAllVersions(apmRepoName) | ||
|
||
if (progressHandler) { | ||
progressHandler(3) | ||
} | ||
|
||
return versions | ||
} |
128 changes: 128 additions & 0 deletions
128
packages/aragon-cli/test/lib/apm/getApmRepoVersions.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import test from 'ava' | ||
import sinon from 'sinon' | ||
import proxyquire from 'proxyquire' | ||
|
||
// Default values used to call getApmVersions(...). | ||
const web3 = { name: 'web3' } | ||
const apmRepoName = 'test.aragonpm.eth' | ||
const apmOptions = {} | ||
apmOptions['ens-registry'] = '0x1234512345123451234512345123451234512345' | ||
const progressHandler = (step) => {} | ||
|
||
/* Setup and cleanup */ | ||
|
||
test.beforeEach('setup', t => { | ||
const apmStub = sinon.stub() | ||
apmStub.returns({ | ||
getAllVersions: async () => {} | ||
}) | ||
|
||
const getApmRepoVersions = proxyquire.noCallThru().load('../../../src/lib/apm/getApmRepoVersions', { | ||
'@aragon/apm': apmStub, | ||
}) | ||
|
||
t.context = { | ||
getApmRepoVersions, | ||
apmStub | ||
} | ||
}) | ||
|
||
test.afterEach('cleanup', t => { | ||
sinon.restore() | ||
}) | ||
|
||
/* Tests */ | ||
|
||
test('properly calls the progressHandler', async t => { | ||
const { getApmRepoVersions } = t.context | ||
|
||
const progressHandlerSpy = sinon.spy() | ||
|
||
await getApmRepoVersions( | ||
web3, | ||
apmRepoName, | ||
apmOptions, | ||
progressHandlerSpy | ||
) | ||
|
||
t.true(progressHandlerSpy.calledThrice) | ||
t.true(progressHandlerSpy.getCall(0).calledWith(1)) | ||
t.true(progressHandlerSpy.getCall(1).calledWith(2)) | ||
t.true(progressHandlerSpy.getCall(2).calledWith(3)) | ||
}) | ||
|
||
test('tolerates a progressHandler not being specified', async t => { | ||
const { getApmRepoVersions } = t.context | ||
|
||
await getApmRepoVersions( | ||
web3, | ||
apmRepoName, | ||
apmOptions, | ||
undefined | ||
) | ||
|
||
t.pass() | ||
}) | ||
|
||
test('calls apm.getAllVersions() with the correct parameters and returns the expected object', async t => { | ||
const { getApmRepoVersions, apmStub } = t.context | ||
|
||
const getAllVersionsResponse = { name: 'allVersions' } | ||
const getAllVersions = sinon.stub() | ||
getAllVersions.returns(getAllVersionsResponse) | ||
apmStub.returns({ | ||
getAllVersions | ||
}) | ||
|
||
const versions = await getApmRepoVersions( | ||
web3, | ||
apmRepoName, | ||
apmOptions, | ||
progressHandler | ||
) | ||
|
||
t.true( | ||
getAllVersions.calledOnceWith( | ||
apmRepoName | ||
) | ||
) | ||
|
||
t.is(versions, getAllVersionsResponse) | ||
}) | ||
|
||
test('APM constructor gets called with the appropriate parameters', async t => { | ||
const { getApmRepoVersions, apmStub } = t.context | ||
|
||
await getApmRepoVersions( | ||
web3, | ||
apmRepoName, | ||
apmOptions, | ||
progressHandler | ||
) | ||
|
||
t.true( | ||
apmStub.calledOnceWith( | ||
web3, | ||
apmOptions | ||
) | ||
) | ||
}) | ||
|
||
test('fails if apmOptions does not contain an ens-registry property', async t => { | ||
const { getApmRepoVersions } = t.context | ||
|
||
const emptyApmOptions = {} | ||
|
||
const error = await t.throwsAsync( | ||
async () => { | ||
await getApmRepoVersions( | ||
web3, | ||
apmRepoName, | ||
emptyApmOptions, | ||
progressHandler | ||
) | ||
} | ||
) | ||
|
||
t.is(error.message, 'ens-registry not found in given apm options.') | ||
}) |
The cases handled don't match with 49f42ce#diff-8dec29eb941e7ae1e45cf9dd83abd092R3, where it also calls
progressHandler
for2
and3