fix(catalog): add deduplication for logs join

This commit is contained in:
Ivan Shmidt
2020-07-20 17:06:54 +02:00
parent 5e36d0cf28
commit 52787a3a8c
2 changed files with 26 additions and 0 deletions
@@ -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;
`);
};
@@ -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([]);