import type {PrismaClient, Prisma} from '@prisma/client'; import {newApp} from './app.js'; import {newLogContext} from './logger.js'; import * as request from 'supertest'; import {expect} from 'chai'; import {apiVersion} from './api-types.js'; export async function resetDB( prisma: PrismaClient< Prisma.PrismaClientOptions, never, Prisma.RejectOnNotFound | Prisma.RejectPerOperation | undefined >, ) { await prisma.active.deleteMany({}); await prisma.license.deleteMany({}); await prisma.customer.deleteMany({}); } export const TEST_PW = 'test pw'; export function newAppForTest() { const lc = newLogContext('info'); const app = newApp(TEST_PW, lc); return app; } export function s(obj: unknown) { return JSON.stringify(obj, null, 1).replace(/\n/g, ''); } export async function apiVersionTest( version: string, app: Express.Application, path: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any req: any, expStatus: number, expError: string, ) { const re = new RegExp(apiVersion); path = path.replace(re, version); const resp = await request.default(app).post(path).send(req).set({ // eslint-disable-next-line @typescript-eslint/naming-convention 'Accept': 'appplication/json', // eslint-disable-next-line @typescript-eslint/naming-convention 'Content-Type': 'application/json', }); expect(resp.statusCode).to.equal(expStatus); if (expStatus !== 200) { expect(resp.text).to.match( new RegExp(expError), `expected: ${expError}, got: ${resp.text}}`, ); } }