mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
Add jobs spec tests
Signed-off-by: James Taylor <jamest@uk.ibm.com>
This commit is contained in:
parent
dfe79f7fb4
commit
fce803af24
2 changed files with 74 additions and 17 deletions
|
|
@ -4,29 +4,54 @@
|
||||||
|
|
||||||
import { Job, Queue } from 'bullmq';
|
import { Job, Queue } from 'bullmq';
|
||||||
import {
|
import {
|
||||||
|
addSubmitTransactionJob,
|
||||||
getJobCounts,
|
getJobCounts,
|
||||||
getJobSummary,
|
getJobSummary,
|
||||||
processSubmitTransactionJob,
|
processSubmitTransactionJob,
|
||||||
JobNotFoundError,
|
JobNotFoundError,
|
||||||
|
updateJobData,
|
||||||
} from './jobs';
|
} from './jobs';
|
||||||
import { Contract, Transaction } from 'fabric-network';
|
import { Contract, Transaction } from 'fabric-network';
|
||||||
import { mock, MockProxy } from 'jest-mock-extended';
|
import { mock, MockProxy } from 'jest-mock-extended';
|
||||||
import { Application } from 'express';
|
import { Application } from 'express';
|
||||||
|
|
||||||
describe('initJobQueue', () => {
|
|
||||||
it.todo('write tests');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('initJobQueueWorker', () => {
|
|
||||||
it.todo('write tests');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('initJobQueueScheduler', () => {
|
|
||||||
it.todo('write tests');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('addSubmitTransactionJob', () => {
|
describe('addSubmitTransactionJob', () => {
|
||||||
it.todo('write tests');
|
let mockJob: MockProxy<Job>;
|
||||||
|
let mockQueue: MockProxy<Queue>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockJob = mock<Job>();
|
||||||
|
mockQueue = mock<Queue>();
|
||||||
|
mockQueue.add.mockResolvedValue(mockJob);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the new job ID', async () => {
|
||||||
|
mockJob.id = 'mockJobId';
|
||||||
|
|
||||||
|
const jobid = await addSubmitTransactionJob(
|
||||||
|
mockQueue,
|
||||||
|
'mockMspId',
|
||||||
|
'txn',
|
||||||
|
'arg1',
|
||||||
|
'arg2'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(jobid).toBe('mockJobId');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws an error if there is no job ID', async () => {
|
||||||
|
mockJob.id = undefined;
|
||||||
|
|
||||||
|
await expect(async () => {
|
||||||
|
await addSubmitTransactionJob(
|
||||||
|
mockQueue,
|
||||||
|
'mockMspId',
|
||||||
|
'txn',
|
||||||
|
'arg1',
|
||||||
|
'arg2'
|
||||||
|
);
|
||||||
|
}).rejects.toThrowError('Submit transaction job ID not available');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getJobSummary', () => {
|
describe('getJobSummary', () => {
|
||||||
|
|
@ -133,8 +158,40 @@ describe('getJobSummary', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateSubmitTransactionJobStateData', () => {
|
describe('updateJobData', () => {
|
||||||
it.todo('write tests');
|
let mockJob: MockProxy<Job>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
mockJob = mock<Job>();
|
||||||
|
mockJob.data = {
|
||||||
|
transactionIds: ['txn1'],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('stores the serialized state in the job data if a transaction is specified', async () => {
|
||||||
|
const mockSavedState = Buffer.from('MOCK SAVED STATE');
|
||||||
|
const mockTransaction = mock<Transaction>();
|
||||||
|
mockTransaction.getTransactionId.mockReturnValue('txn2');
|
||||||
|
mockTransaction.serialize.mockReturnValue(mockSavedState);
|
||||||
|
|
||||||
|
await updateJobData(mockJob, mockTransaction);
|
||||||
|
|
||||||
|
expect(mockJob.update).toBeCalledTimes(1);
|
||||||
|
expect(mockJob.update).toBeCalledWith({
|
||||||
|
transactionIds: ['txn1', 'txn2'],
|
||||||
|
transactionState: mockSavedState,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes the serialized state from the job data if a transaction is not specified', async () => {
|
||||||
|
await updateJobData(mockJob, undefined);
|
||||||
|
|
||||||
|
expect(mockJob.update).toBeCalledTimes(1);
|
||||||
|
expect(mockJob.update).toBeCalledWith({
|
||||||
|
transactionIds: ['txn1'],
|
||||||
|
transactionState: undefined,
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getJobCounts', () => {
|
describe('getJobCounts', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue