mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
fix lint
This commit is contained in:
parent
c27c07003d
commit
f5d79e8a36
@ -118,10 +118,7 @@ export class AppDatabase {
|
||||
}
|
||||
|
||||
public async destroy(): Promise<void> {
|
||||
await Promise.all([
|
||||
this.dataSource?.destroy(),
|
||||
this.drizzleConnection?.end(),
|
||||
])
|
||||
await Promise.all([this.dataSource?.destroy(), this.drizzleConnection?.end()])
|
||||
if (this.redisClient) {
|
||||
await this.redisClient.quit()
|
||||
this.redisClient = undefined
|
||||
|
||||
@ -18,15 +18,13 @@ beforeAll(async () => {
|
||||
await db.delete(openaiThreadsTable)
|
||||
})
|
||||
afterAll(async () => {
|
||||
console.log('destroying database')
|
||||
await appDB.destroy()
|
||||
})
|
||||
|
||||
describe('openaiThreads query test', () => {
|
||||
it('should insert a new openai thread', async () => {
|
||||
await Promise.resolve([
|
||||
dbInsertOpenaiThread('7', 1),
|
||||
dbInsertOpenaiThread('72', 6),
|
||||
])
|
||||
await Promise.resolve([dbInsertOpenaiThread('7', 1), dbInsertOpenaiThread('72', 6)])
|
||||
const result = await db.select().from(openaiThreadsTable)
|
||||
expect(result).toHaveLength(2)
|
||||
expect(result).toMatchObject([
|
||||
@ -38,18 +36,25 @@ describe('openaiThreads query test', () => {
|
||||
it('should find the newest created openai thread by user id', async () => {
|
||||
await db.insert(openaiThreadsTable).values([
|
||||
{ id: '75', userId: 2, createdAt: new Date('2025-01-01T00:00:00.000Z') },
|
||||
{ id: '172', userId: 2, createdAt: new Date('2025-01-02T00:00:00.000Z') }
|
||||
{ id: '172', userId: 2, createdAt: new Date('2025-01-02T00:00:00.000Z') },
|
||||
])
|
||||
const result = await dbFindNewestCreatedOpenaiThreadByUserId(2)
|
||||
expect(result).toBeDefined()
|
||||
expect(result).toMatchObject({ id: '172', userId: 2, createdAt: new Date('2025-01-02T00:00:00.000Z') })
|
||||
expect(result).toMatchObject({
|
||||
id: '172',
|
||||
userId: 2,
|
||||
createdAt: new Date('2025-01-02T00:00:00.000Z'),
|
||||
})
|
||||
})
|
||||
|
||||
it('should update an existing openai thread', async () => {
|
||||
const now = new Date()
|
||||
now.setMilliseconds(0)
|
||||
await dbUpdateOpenaiThread('172')
|
||||
const result = await db.select().from(openaiThreadsTable).where(eq(openaiThreadsTable.id, '172'))
|
||||
const result = await db
|
||||
.select()
|
||||
.from(openaiThreadsTable)
|
||||
.where(eq(openaiThreadsTable.id, '172'))
|
||||
expect(result).toHaveLength(1)
|
||||
expect(result[0].updatedAt.getTime()).toBeGreaterThanOrEqual(now.getTime())
|
||||
expect(result).toMatchObject([{ id: '172', userId: 2, updatedAt: expect.any(Date) }])
|
||||
@ -57,7 +62,10 @@ describe('openaiThreads query test', () => {
|
||||
|
||||
it('should delete an existing openai thread', async () => {
|
||||
await dbDeleteOpenaiThread('172')
|
||||
const result = await db.select().from(openaiThreadsTable).where(eq(openaiThreadsTable.id, '172'))
|
||||
const result = await db
|
||||
.select()
|
||||
.from(openaiThreadsTable)
|
||||
.where(eq(openaiThreadsTable.id, '172'))
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
@ -5,9 +5,7 @@ import { drizzleDb } from '.'
|
||||
// TODO: replace results with valibot schema after update to typescript 5 is possible
|
||||
|
||||
export async function dbInsertOpenaiThread(id: string, userId: number): Promise<void> {
|
||||
await drizzleDb()
|
||||
.insert(openaiThreadsTable)
|
||||
.values({ id, userId })
|
||||
await drizzleDb().insert(openaiThreadsTable).values({ id, userId })
|
||||
}
|
||||
|
||||
export async function dbUpdateOpenaiThread(id: string): Promise<void> {
|
||||
@ -17,7 +15,9 @@ export async function dbUpdateOpenaiThread(id: string): Promise<void> {
|
||||
.where(eq(openaiThreadsTable.id, id))
|
||||
}
|
||||
|
||||
export async function dbFindNewestCreatedOpenaiThreadByUserId(userId: number): Promise<typeof openaiThreadsTable.$inferSelect | undefined> {
|
||||
export async function dbFindNewestCreatedOpenaiThreadByUserId(
|
||||
userId: number,
|
||||
): Promise<typeof openaiThreadsTable.$inferSelect | undefined> {
|
||||
const result = await drizzleDb()
|
||||
.select()
|
||||
.from(openaiThreadsTable)
|
||||
@ -28,7 +28,5 @@ export async function dbFindNewestCreatedOpenaiThreadByUserId(userId: number): P
|
||||
}
|
||||
|
||||
export async function dbDeleteOpenaiThread(id: string): Promise<void> {
|
||||
await drizzleDb()
|
||||
.delete(openaiThreadsTable)
|
||||
.where(eq(openaiThreadsTable.id, id))
|
||||
await drizzleDb().delete(openaiThreadsTable).where(eq(openaiThreadsTable.id, id))
|
||||
}
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
import DHT from '@hyperswarm/dht'
|
||||
import { cleanDB, testEnvironment } from '@test/helpers'
|
||||
import { getLogger } from 'config-schema/test/testSetup'
|
||||
import { AppDatabase, Community as DbCommunity, FederatedCommunity as DbFederatedCommunity } from 'database'
|
||||
import {
|
||||
AppDatabase,
|
||||
Community as DbCommunity,
|
||||
FederatedCommunity as DbFederatedCommunity,
|
||||
} from 'database'
|
||||
import { validate as validateUUID, version as versionUUID } from 'uuid'
|
||||
import { CONFIG } from '@/config'
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
|
||||
|
||||
@ -1,7 +1,12 @@
|
||||
import { cleanDB, testEnvironment } from '@test/helpers'
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import { EncryptedTransferArgs } from 'core'
|
||||
import { AppDatabase, Community as DbCommunity, User as DbUser, UserContact as DbUserContact } from 'database'
|
||||
import {
|
||||
AppDatabase,
|
||||
Community as DbCommunity,
|
||||
User as DbUser,
|
||||
UserContact as DbUserContact,
|
||||
} from 'database'
|
||||
import Decimal from 'decimal.js-light'
|
||||
import { GraphQLError } from 'graphql'
|
||||
import { getLogger } from 'log4js'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user