Created
January 30, 2019 14:22
-
-
Save Jojoooo1/eb92574825d3db5134395e180ea896c2 to your computer and use it in GitHub Desktop.
test.js
This file contains hidden or 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
import { expect } from 'chai'; | |
import { ChaincodeMockStub, Transform} from '@theledger/fabric-mock-stub'; | |
import Chaincode from '../app/chaincode.js'; | |
const MyChaincode = new Chaincode(); | |
describe('Test chaincode', () => { | |
const mockStub = new ChaincodeMockStub('MyMockStub', MyChaincode); | |
it('Should init without issues', async () => { | |
const response = await mockStub.mockInit('tx1', []); | |
expect(response.status).to.equal(200); | |
}); | |
it('Return errors if method does not exist', async () => { | |
const testFunction = 'testFunction'; | |
const response = await mockStub.mockInvoke('tx1', [testFunction, 'test']); | |
console.log(response); | |
expect(response.message).to.equal(`funcao com nome "${testFunction}" nao encontrado`); | |
}); | |
it('Should return empty string if the data requested does not exist', async () => { | |
const response = await mockStub.mockInvoke('tx1', ['getDataById', 'test']); | |
console.log(response); | |
expect(response.payload.toString()).to.equal(''); | |
}); | |
it('Should be able to CREATE a Batch', async () => { | |
const request = { | |
quantidade: 10, | |
embarcador: 'b2w' | |
}; | |
const response = await mockStub.mockInvoke('tx1', ['solicitarCodigo', JSON.stringify(request)]); | |
console.log(response); | |
expect(response.status).to.equal(200); | |
}); | |
it('Should be able to CREATE & GET a Batch by ID', async () => { | |
const request = { | |
quantidade: 10, | |
embarcador: 'b2w' | |
}; | |
const batchResponse = await mockStub.mockInvoke('tx1', ['solicitarCodigo', JSON.stringify(request)]); | |
const eventPayload = await mockStub.getEvent('batchCreated'); | |
const batchId = JSON.parse(eventPayload.toString()).id; | |
const response = await mockStub.mockInvoke('tx2', ['getDataById', batchId]); | |
expect(JSON.parse(response.payload.toString()).id).to.equal(batchId); | |
}); | |
// [...] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment