import { AppDatabase, entities } from 'database' export const headerPushMock = jest.fn((t) => { context.token = t.value }) const context = { token: '', setHeaders: { push: headerPushMock, forEach: jest.fn(), }, clientTimezoneOffset: 0, } export const cleanDB = async () => { // this only works as long we do not have foreign key constraints for (const entity of entities) { if (entity.name !== 'Migration') { await resetEntity(entity) } } } export const testEnvironment = async () => { const appDB = AppDatabase.getInstance() await appDB.init() return { con: appDB.getDataSource() } } export const resetEntity = async (entity: any) => { const items = await entity.find({ withDeleted: true }) if (items.length > 0) { const ids = items.map((i: any) => i.id) await entity.delete(ids) } } export const resetToken = () => { context.token = '' } // format date string as it comes from the frontend for the contribution date export const contributionDateFormatter = (date: Date): string => { return `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()}` } export const setClientTimezoneOffset = (offset: number): void => { context.clientTimezoneOffset = offset }