diff --git a/plugins/catalog-backend/migrations/20200527114117_location_update_log_latest_view.js b/plugins/catalog-backend/migrations/20200527114117_location_update_log_latest_view.js index 083d0a38aa..1d530c6bae 100644 --- a/plugins/catalog-backend/migrations/20200527114117_location_update_log_latest_view.js +++ b/plugins/catalog-backend/migrations/20200527114117_location_update_log_latest_view.js @@ -33,6 +33,7 @@ exports.up = async function up(knex) { ) t2 ON t1.location_id = t2.location_id AND t1.created_at = t2.MAXDATE + GROUP BY t1.location_id ORDER BY created_at DESC; `); }; diff --git a/plugins/catalog-backend/src/database/CommonDatabase.test.ts b/plugins/catalog-backend/src/database/CommonDatabase.test.ts index 3d1455a886..21dde4ca74 100644 --- a/plugins/catalog-backend/src/database/CommonDatabase.test.ts +++ b/plugins/catalog-backend/src/database/CommonDatabase.test.ts @@ -88,6 +88,31 @@ describe('CommonDatabase', () => { expect(locations).toEqual([output]); const location = await db.location(locations[0].id); expect(location).toEqual(output); + + // If we add 2 new update log events, + // this should not result in location duplication + // due to incorrect join in DB + await db.addLocationUpdateLogEvent( + 'dd12620d-0436-422f-93bd-929aa0788123', + DatabaseLocationUpdateLogStatus.SUCCESS, + ); + + // Have a second in-between + // To avoid having same timestamp on event + await new Promise(res => setTimeout(res, 1000)); + await db.addLocationUpdateLogEvent( + 'dd12620d-0436-422f-93bd-929aa0788123', + DatabaseLocationUpdateLogStatus.FAIL, + ); + + expect(await db.locations()).toEqual([ + { + ...output, + status: DatabaseLocationUpdateLogStatus.FAIL, + timestamp: expect.any(String), + }, + ]); + await db.transaction(tx => db.removeLocation(tx, locations[0].id)); await expect(db.locations()).resolves.toEqual([]);