From 81b609f01049ef8902bd47c405eabc33460731e1 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Fri, 30 Apr 2021 09:55:44 +0200 Subject: [PATCH] chore: test for getProcessableEntities Signed-off-by: Johan Haals --- .../DefaultProcessingDatabase.test.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.test.ts b/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.test.ts index d76bd74260..ae17746799 100644 --- a/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.test.ts +++ b/plugins/catalog-backend/src/next/database/DefaultProcessingDatabase.test.ts @@ -514,4 +514,48 @@ describe('Default Processing Database', () => { }); }); }); + + describe('getProcessableEntities', () => { + it('should return entities to process', async () => { + const entity = JSON.stringify({ + apiVersion: '1.0.0', + metadata: { + name: 'xyz', + }, + kind: 'Location', + } as Entity); + await db('refresh_state').insert({ + entity_id: '2', + entity_ref: 'location:default/new-root', + unprocessed_entity: entity, + errors: '', + next_update_at: '2019-01-01 23:00:00', + last_discovery_at: 'now()', + }); + await db('refresh_state').insert({ + entity_id: '1', + entity_ref: 'location:default/foobar', + unprocessed_entity: entity, + errors: '', + next_update_at: '2042-01-01 23:00:00', + last_discovery_at: 'now()', + }); + + await processingDatabase.transaction(async tx => { + // request two items but only one can be processed. + const result = await processingDatabase.getProcessableEntities(tx, { + processBatchSize: 2, + }); + expect(result.items.length).toEqual(1); + expect(result.items[0].entityRef).toEqual('location:default/new-root'); + + // should not return the same item as there's nothing left to process. + await expect( + processingDatabase.getProcessableEntities(tx, { + processBatchSize: 2, + }), + ).resolves.toEqual({ items: [] }); + }); + }); + }); });