1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/src/lib/db/event-store.test.ts
Christopher Kolstad 6673d131fe
feat: biome lint (#4853)
This commit changes our linter/formatter to biome (https://biomejs.dev/)
Causing our prehook to run almost instantly, and our "yarn lint" task to
run in sub 100ms.

Some trade-offs:
* Biome isn't quite as well established as ESLint
* Are we ready to install a different vscode plugin (the biome plugin)
instead of the prettier plugin


The configuration set for biome also has a set of recommended rules,
this is turned on by default, in order to get to something that was
mergeable I have turned off a couple the rules we seemed to violate the
most, that we also explicitly told eslint to ignore.
2023-09-29 14:18:21 +02:00

55 lines
1.7 KiB
TypeScript

import knex from 'knex';
import EventStore from './event-store';
import getLogger from '../../test/fixtures/no-logger';
import { subHours, formatRFC3339 } from 'date-fns';
import dbInit from '../../test/e2e/helpers/database-init';
beforeAll(() => {
getLogger.setMuteError(true);
});
afterAll(() => {
getLogger.setMuteError(false);
});
test('Trying to get events if db fails should yield empty list', async () => {
const db = knex({
client: 'pg',
});
const store = new EventStore(db, getLogger);
const events = await store.getEvents();
expect(events.length).toBe(0);
await db.destroy();
});
test('Trying to get events by name if db fails should yield empty list', async () => {
const db = knex({
client: 'pg',
});
const store = new EventStore(db, getLogger);
const events = await store.searchEvents({ type: 'application-created' });
expect(events).toBeTruthy();
expect(events.length).toBe(0);
await db.destroy();
});
// We might want to cap this to 500 and this test can help checking that
test('Find unannounced events returns all events', async () => {
const db = await dbInit('events_test', getLogger);
const type = 'application-created' as const;
const allEvents = Array.from({ length: 505 }).map((_, i) => ({
type,
created_at: formatRFC3339(subHours(new Date(), i)),
created_by: `test ${i}`,
data: { name: 'test', iteration: i },
}));
await db.rawDatabase('events').insert(allEvents).returning(['id']);
const store = new EventStore(db.rawDatabase, getLogger);
const events = await store.setUnannouncedToAnnounced();
expect(events).toBeTruthy();
expect(events.length).toBe(505);
await db.destroy();
});