Skip to content

Commit

Permalink
Add unit tests for setting & removing non-unique identifier warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Oct 20, 2023
1 parent e59275b commit 211ead1
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions core/test/datastore/warnings-updater.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WarningsUpdater } from '../../src/datastore/warnings-updater';
import { Warnings } from '../../src/model';
import { Field } from '../../src/model/configuration/field';
import { doc } from '../test-helpers';

Expand Down Expand Up @@ -66,4 +67,61 @@ describe('WarningsUpdater', () => {
});
expect(documents[1].warnings).toBeUndefined();
});


it('set non-unique identifier warnings', async done => {

const documents = [
createDocument('1'),
createDocument('2')
];

const mockIndexFacade = jasmine.createSpyObj('mockIndexFacade', ['put', 'getCount']);
mockIndexFacade.getCount.and.returnValue(2);

const mockDatastore = jasmine.createSpyObj('mockDatastore', ['find']);
mockDatastore.find.and.returnValue(Promise.resolve({ documents: [documents[1]] }));

await WarningsUpdater.updateNonUniqueIdentifierWarning(
documents[0], mockIndexFacade, mockDatastore, undefined, true
);

expect(documents[0].warnings?.nonUniqueIdentifier).toBe(true);
expect(documents[1].warnings?.nonUniqueIdentifier).toBe(true);
expect(mockIndexFacade.put).toHaveBeenCalledWith(documents[0]);
expect(mockIndexFacade.put).toHaveBeenCalledWith(documents[1]);

done();
});


it('remove non-unique identifier warnings', async done => {

const documents = [
createDocument('1'),
createDocument('2')
];

documents[0].warnings = Warnings.createDefault();
documents[0].warnings.nonUniqueIdentifier = true;
documents[1].warnings = Warnings.createDefault();
documents[1].warnings.nonUniqueIdentifier = true;

const mockIndexFacade = jasmine.createSpyObj('mockIndexFacade', ['put', 'getCount']);
mockIndexFacade.getCount.and.returnValue(1);

const mockDatastore = jasmine.createSpyObj('mockDatastore', ['find']);
mockDatastore.find.and.returnValue(Promise.resolve({ documents: [documents[1]] }));

await WarningsUpdater.updateNonUniqueIdentifierWarning(
documents[0], mockIndexFacade, mockDatastore, 'previousIdentifier', true
);

expect(documents[0].warnings).toBeUndefined();
expect(documents[1].warnings).toBeUndefined();
expect(mockIndexFacade.put).toHaveBeenCalledWith(documents[0]);
expect(mockIndexFacade.put).toHaveBeenCalledWith(documents[1]);

done();
});
});

0 comments on commit 211ead1

Please sign in to comment.