mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: force updated_at date to change (#9092)
This commit is contained in:
parent
fea3d89fca
commit
1b4d1df84f
@ -5,6 +5,7 @@ import type {
|
||||
IUnleashStores,
|
||||
} from '../../../lib/types';
|
||||
import HyperLogLog from 'hyperloglog-lite';
|
||||
import { isAfter } from 'date-fns';
|
||||
|
||||
let stores: IUnleashStores;
|
||||
let db: ITestDb;
|
||||
@ -56,3 +57,23 @@ test('should indicate when no entry', async () => {
|
||||
|
||||
expect(fetchedHll).toBeNull();
|
||||
});
|
||||
|
||||
test('should update updated_at date', async () => {
|
||||
const hll = HyperLogLog(12);
|
||||
hll.add(HyperLogLog.hash('connection-1'));
|
||||
hll.add(HyperLogLog.hash('connection-2'));
|
||||
|
||||
await uniqueConnectionStore.insert({
|
||||
id: 'current',
|
||||
hll: hll.output().buckets,
|
||||
});
|
||||
const firstFetch = await uniqueConnectionStore.get('current');
|
||||
|
||||
await uniqueConnectionStore.insert({
|
||||
id: 'current',
|
||||
hll: hll.output().buckets,
|
||||
});
|
||||
const secondFetch = await uniqueConnectionStore.get('current');
|
||||
|
||||
expect(isAfter(secondFetch?.updatedAt!, firstFetch?.updatedAt!)).toBe(true);
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import type { Db } from '../../db/db';
|
||||
import type { IUniqueConnectionStore } from '../../types';
|
||||
import type { UniqueConnections } from './unique-connection-store-type';
|
||||
import type { Knex } from 'knex';
|
||||
|
||||
export class UniqueConnectionStore implements IUniqueConnectionStore {
|
||||
private db: Db;
|
||||
@ -10,8 +11,14 @@ export class UniqueConnectionStore implements IUniqueConnectionStore {
|
||||
}
|
||||
|
||||
async insert(uniqueConnections: UniqueConnections): Promise<void> {
|
||||
await this.db<UniqueConnections>('unique_connections')
|
||||
.insert({ id: uniqueConnections.id, hll: uniqueConnections.hll })
|
||||
await this.db<UniqueConnections & { updated_at: Knex.Raw<any> }>(
|
||||
'unique_connections',
|
||||
)
|
||||
.insert({
|
||||
id: uniqueConnections.id,
|
||||
hll: uniqueConnections.hll,
|
||||
updated_at: this.db.raw('DEFAULT'),
|
||||
})
|
||||
.onConflict('id')
|
||||
.merge();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user