Adding the mergeAssets unit test

Let's add the content of this additional test case to the test/logic.js file:

 describe('MergeAssets()', () => {
it('should change the value to ' + assetType + ' to 200', () => {
const factory = businessNetworkConnection.getBusinessNetwork().getFactory();
// Create the asset 1
const asset1 = factory.newResource(namespace, assetType, 'ASSET_001');
asset1.value = 100;
// Create the asset 2
const asset2 = factory.newResource(namespace, assetType, 'ASSET_002');
asset2.value = 100;

// Create a transaction to change the asset's value property
const mergeAssetTx = factory.newTransaction(namespace, 'MergeAssets');
mergeAssetTx.mergeFrom = factory.newRelationship(namespace, assetType, asset1.$identifier);
mergeAssetTx.mergeTo = factory.newRelationship(namespace, assetType, asset2.$identifier);

let assetRegistry;
return businessNetworkConnection.getAssetRegistry(namespace + '.' + assetType).then(registry => {
assetRegistry = registry;
// Add the asset to the appropriate asset registry
return assetRegistry.add(asset1);
}).then(() => {
return assetRegistry.add(asset2);
}).then(() => {
// Submit the transaction
return businessNetworkConnection.submitTransaction(mergeAssetTx);
}).then(() => {
// Get the asset
return assetRegistry.get(asset2.$identifier);
}).then(newAsset => {
// Assert that the asset has the new value property
newAsset.value.should.equal(200);
});
});
});

We won't cover the details of this test case, as it has been covered in previous chapters. However, if you want to see whether the test has completed successfully, run the following command:

npm test

Let's commit this new test to Git:

git add -A
git commit -S -m "Added new test case"
git push origin Feat-

This should automatically trigger our build pipeline, which should complete successfully and leave our pull request in the following state:

This should allow you to merge the pull request. Click the Merge request button, confirm the merge, and get ready to create your first release!

If your pull request is not green and asks for a code review, you may have forgotten to uncheck the Require pull request reviews before merging option, as mentioned in the Protecting the master branch section.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset