Skip to content

Commit

Permalink
add test unit for data access
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Apr 6, 2020
1 parent 093b322 commit 2cfec16
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/data-access/src/data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export default class DataAccess implements DataAccessTypes.IDataAccess {
this.checkInitialized();

// last transaction timestamp retrieved
const lastLocationTimestamp = this.transactionIndex.getLastTransactionTimestamp();
const lastLocationTimestamp = await this.transactionIndex.getLastTransactionTimestamp();
const listIndexedLocation = await this.transactionIndex.getIndexedLocation();
const listIgnoredLocation = await this.ignoredLocation.getIgnoredLocation();

Expand Down
46 changes: 45 additions & 1 deletion packages/data-access/test/data-access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ let clock: sinon.SinonFakeTimers;

// tslint:disable:no-magic-numbers
/* tslint:disable:no-unused-expression */
describe.only('data-access', () => {
describe('data-access', () => {
beforeEach(async () => {
clock = sinon.useFakeTimers();
});
Expand Down Expand Up @@ -546,6 +546,50 @@ describe.only('data-access', () => {
});
});

describe('_getInformation', () => {
let dataAccess: any;

beforeEach(async () => {
const fakeStorage = {
...defaultFakeStorage,
read: (param: string): any => {
const dataIdBlock2txFake: StorageTypes.IEntry = {
content: JSON.stringify(blockWith2tx),
id: '1',
meta: { state: StorageTypes.ContentState.CONFIRMED, timestamp: 10 },
};
const result: any = {
dataIdBlock2tx: dataIdBlock2txFake,
};
return result[param];
},
};

dataAccess = new DataAccess(fakeStorage);
await dataAccess.initialize();
});

it('can _getInformation()', async () => {
expect(await dataAccess._getInformation(), 'result with arbitraryTopic1 wrong').to.deep.equal(
{
filesIgnored: { count: 0, list: undefined },
filesRetrieved: { count: 1, lastTimestamp: 10, list: undefined },
lastSynchronizationTimestamp: 0,
},
);
});
it('can _getInformation() with details', async () => {
expect(
await dataAccess._getInformation(true),
'result with arbitraryTopic1 wrong',
).to.deep.equal({
filesIgnored: { count: 0, list: {} },
filesRetrieved: { count: 1, lastTimestamp: 10, list: ['dataIdBlock2tx'] },
lastSynchronizationTimestamp: 0,
});
});
});

it('synchronizeNewDataId() should throw an error if not initialized', async () => {
const dataAccess = new DataAccess(defaultFakeStorage);

Expand Down

0 comments on commit 2cfec16

Please sign in to comment.