mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 14:04:04 +00:00
test(adapters-db): increase integration test timeouts to 10s
This commit is contained in:
@@ -26,77 +26,83 @@ describe('createDbHouseholdConfigurationRepository', () => {
|
|||||||
await queryClient.end({ timeout: 5 })
|
await queryClient.end({ timeout: 5 })
|
||||||
})
|
})
|
||||||
|
|
||||||
testIfDatabase('registers a Telegram household chat and binds topics', async () => {
|
testIfDatabase(
|
||||||
const repositoryClient = createDbHouseholdConfigurationRepository(databaseUrl!)
|
'registers a Telegram household chat and binds topics',
|
||||||
const suffix = randomUUID()
|
async () => {
|
||||||
const telegramChatId = `-100${Date.now()}`
|
const repositoryClient = createDbHouseholdConfigurationRepository(databaseUrl!)
|
||||||
|
const suffix = randomUUID()
|
||||||
|
const telegramChatId = `-100${Date.now()}`
|
||||||
|
|
||||||
const registered = await repositoryClient.repository.registerTelegramHouseholdChat({
|
const registered = await repositoryClient.repository.registerTelegramHouseholdChat({
|
||||||
householdName: `Integration Household ${suffix}`,
|
householdName: `Integration Household ${suffix}`,
|
||||||
telegramChatId,
|
telegramChatId,
|
||||||
telegramChatType: 'supergroup',
|
telegramChatType: 'supergroup',
|
||||||
title: 'Integration Household'
|
title: 'Integration Household'
|
||||||
})
|
})
|
||||||
|
|
||||||
createdHouseholdIds.push(registered.household.householdId)
|
createdHouseholdIds.push(registered.household.householdId)
|
||||||
|
|
||||||
expect(registered.status).toBe('created')
|
expect(registered.status).toBe('created')
|
||||||
expect(registered.household.telegramChatId).toBe(telegramChatId)
|
expect(registered.household.telegramChatId).toBe(telegramChatId)
|
||||||
|
|
||||||
const existing = await repositoryClient.repository.registerTelegramHouseholdChat({
|
const existing = await repositoryClient.repository.registerTelegramHouseholdChat({
|
||||||
householdName: 'Ignored replacement title',
|
householdName: 'Ignored replacement title',
|
||||||
telegramChatId,
|
telegramChatId,
|
||||||
telegramChatType: 'supergroup',
|
telegramChatType: 'supergroup',
|
||||||
title: 'Updated Integration Household'
|
title: 'Updated Integration Household'
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(existing.status).toBe('existing')
|
expect(existing.status).toBe('existing')
|
||||||
expect(existing.household.householdId).toBe(registered.household.householdId)
|
expect(existing.household.householdId).toBe(registered.household.householdId)
|
||||||
expect(existing.household.title).toBe('Updated Integration Household')
|
expect(existing.household.title).toBe('Updated Integration Household')
|
||||||
|
|
||||||
const purchase = await repositoryClient.repository.bindHouseholdTopic({
|
const purchase = await repositoryClient.repository.bindHouseholdTopic({
|
||||||
householdId: registered.household.householdId,
|
householdId: registered.household.householdId,
|
||||||
role: 'purchase',
|
role: 'purchase',
|
||||||
telegramThreadId: '7001',
|
telegramThreadId: '7001',
|
||||||
topicName: 'Общие покупки'
|
topicName: 'Общие покупки'
|
||||||
})
|
})
|
||||||
|
|
||||||
const feedback = await repositoryClient.repository.bindHouseholdTopic({
|
const feedback = await repositoryClient.repository.bindHouseholdTopic({
|
||||||
householdId: registered.household.householdId,
|
householdId: registered.household.householdId,
|
||||||
role: 'feedback',
|
role: 'feedback',
|
||||||
telegramThreadId: '7002',
|
telegramThreadId: '7002',
|
||||||
topicName: 'Feedback'
|
topicName: 'Feedback'
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(purchase.role).toBe('purchase')
|
expect(purchase.role).toBe('purchase')
|
||||||
expect(feedback.role).toBe('feedback')
|
expect(feedback.role).toBe('feedback')
|
||||||
|
|
||||||
const resolvedChat = await repositoryClient.repository.getTelegramHouseholdChat(telegramChatId)
|
const resolvedChat =
|
||||||
const resolvedPurchase = await repositoryClient.repository.findHouseholdTopicByTelegramContext({
|
await repositoryClient.repository.getTelegramHouseholdChat(telegramChatId)
|
||||||
telegramChatId,
|
const resolvedPurchase =
|
||||||
telegramThreadId: '7001'
|
await repositoryClient.repository.findHouseholdTopicByTelegramContext({
|
||||||
})
|
telegramChatId,
|
||||||
const bindings = await repositoryClient.repository.listHouseholdTopicBindings(
|
telegramThreadId: '7001'
|
||||||
registered.household.householdId
|
})
|
||||||
)
|
const bindings = await repositoryClient.repository.listHouseholdTopicBindings(
|
||||||
|
registered.household.householdId
|
||||||
|
)
|
||||||
|
|
||||||
expect(resolvedChat?.householdId).toBe(registered.household.householdId)
|
expect(resolvedChat?.householdId).toBe(registered.household.householdId)
|
||||||
expect(resolvedPurchase?.role).toBe('purchase')
|
expect(resolvedPurchase?.role).toBe('purchase')
|
||||||
expect(bindings).toHaveLength(2)
|
expect(bindings).toHaveLength(2)
|
||||||
|
|
||||||
const verificationClient = createDbClient(databaseUrl!, {
|
const verificationClient = createDbClient(databaseUrl!, {
|
||||||
max: 1,
|
max: 1,
|
||||||
prepare: false
|
prepare: false
|
||||||
})
|
})
|
||||||
const storedChatRows = await verificationClient.db
|
const storedChatRows = await verificationClient.db
|
||||||
.select({ title: schema.householdTelegramChats.title })
|
.select({ title: schema.householdTelegramChats.title })
|
||||||
.from(schema.householdTelegramChats)
|
.from(schema.householdTelegramChats)
|
||||||
.where(eq(schema.householdTelegramChats.telegramChatId, telegramChatId))
|
.where(eq(schema.householdTelegramChats.telegramChatId, telegramChatId))
|
||||||
.limit(1)
|
.limit(1)
|
||||||
|
|
||||||
expect(storedChatRows[0]?.title).toBe('Updated Integration Household')
|
expect(storedChatRows[0]?.title).toBe('Updated Integration Household')
|
||||||
|
|
||||||
await verificationClient.queryClient.end({ timeout: 5 })
|
await verificationClient.queryClient.end({ timeout: 5 })
|
||||||
await repositoryClient.close()
|
await repositoryClient.close()
|
||||||
})
|
},
|
||||||
|
10000
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,67 +28,71 @@ describe('createDbTopicMessageHistoryRepository', () => {
|
|||||||
await queryClient.end({ timeout: 5 })
|
await queryClient.end({ timeout: 5 })
|
||||||
})
|
})
|
||||||
|
|
||||||
testIfDatabase('lists the latest same-day chat messages in chronological order', async () => {
|
testIfDatabase(
|
||||||
const householdClient = createDbHouseholdConfigurationRepository(databaseUrl!)
|
'lists the latest same-day chat messages in chronological order',
|
||||||
const historyClient = createDbTopicMessageHistoryRepository(databaseUrl!)
|
async () => {
|
||||||
const telegramChatId = `-100${Date.now()}`
|
const householdClient = createDbHouseholdConfigurationRepository(databaseUrl!)
|
||||||
const registered = await householdClient.repository.registerTelegramHouseholdChat({
|
const historyClient = createDbTopicMessageHistoryRepository(databaseUrl!)
|
||||||
householdName: `History Household ${randomUUID()}`,
|
const telegramChatId = `-100${Date.now()}`
|
||||||
telegramChatId,
|
const registered = await householdClient.repository.registerTelegramHouseholdChat({
|
||||||
telegramChatType: 'supergroup',
|
householdName: `History Household ${randomUUID()}`,
|
||||||
title: 'History Household'
|
telegramChatId,
|
||||||
})
|
telegramChatType: 'supergroup',
|
||||||
|
title: 'History Household'
|
||||||
|
})
|
||||||
|
|
||||||
createdHouseholdIds.push(registered.household.householdId)
|
createdHouseholdIds.push(registered.household.householdId)
|
||||||
|
|
||||||
const baseMessage = {
|
const baseMessage = {
|
||||||
householdId: registered.household.householdId,
|
householdId: registered.household.householdId,
|
||||||
telegramChatId,
|
telegramChatId,
|
||||||
telegramThreadId: '777',
|
telegramThreadId: '777',
|
||||||
senderTelegramUserId: '10002',
|
senderTelegramUserId: '10002',
|
||||||
senderDisplayName: 'Mia',
|
senderDisplayName: 'Mia',
|
||||||
isBot: false
|
isBot: false
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
await historyClient.repository.saveMessage({
|
await historyClient.repository.saveMessage({
|
||||||
...baseMessage,
|
...baseMessage,
|
||||||
telegramMessageId: 'msg-1',
|
telegramMessageId: 'msg-1',
|
||||||
telegramUpdateId: 'upd-1',
|
telegramUpdateId: 'upd-1',
|
||||||
rawText: '08:00',
|
rawText: '08:00',
|
||||||
messageSentAt: instantFromIso('2026-03-05T08:00:00.000Z')
|
messageSentAt: instantFromIso('2026-03-05T08:00:00.000Z')
|
||||||
})
|
})
|
||||||
await historyClient.repository.saveMessage({
|
await historyClient.repository.saveMessage({
|
||||||
...baseMessage,
|
...baseMessage,
|
||||||
telegramMessageId: 'msg-2',
|
telegramMessageId: 'msg-2',
|
||||||
telegramUpdateId: 'upd-2',
|
telegramUpdateId: 'upd-2',
|
||||||
rawText: '10:00',
|
rawText: '10:00',
|
||||||
messageSentAt: instantFromIso('2026-03-05T10:00:00.000Z')
|
messageSentAt: instantFromIso('2026-03-05T10:00:00.000Z')
|
||||||
})
|
})
|
||||||
await historyClient.repository.saveMessage({
|
await historyClient.repository.saveMessage({
|
||||||
...baseMessage,
|
...baseMessage,
|
||||||
telegramMessageId: 'msg-3',
|
telegramMessageId: 'msg-3',
|
||||||
telegramUpdateId: 'upd-3',
|
telegramUpdateId: 'upd-3',
|
||||||
rawText: '11:00',
|
rawText: '11:00',
|
||||||
messageSentAt: instantFromIso('2026-03-05T11:00:00.000Z')
|
messageSentAt: instantFromIso('2026-03-05T11:00:00.000Z')
|
||||||
})
|
})
|
||||||
await historyClient.repository.saveMessage({
|
await historyClient.repository.saveMessage({
|
||||||
...baseMessage,
|
...baseMessage,
|
||||||
telegramMessageId: 'msg-4',
|
telegramMessageId: 'msg-4',
|
||||||
telegramUpdateId: 'upd-4',
|
telegramUpdateId: 'upd-4',
|
||||||
rawText: '12:00',
|
rawText: '12:00',
|
||||||
messageSentAt: instantFromIso('2026-03-05T12:00:00.000Z')
|
messageSentAt: instantFromIso('2026-03-05T12:00:00.000Z')
|
||||||
})
|
})
|
||||||
|
|
||||||
const rows = await historyClient.repository.listRecentChatMessages({
|
const rows = await historyClient.repository.listRecentChatMessages({
|
||||||
householdId: registered.household.householdId,
|
householdId: registered.household.householdId,
|
||||||
telegramChatId,
|
telegramChatId,
|
||||||
sentAtOrAfter: instantFromIso('2026-03-05T00:00:00.000Z'),
|
sentAtOrAfter: instantFromIso('2026-03-05T00:00:00.000Z'),
|
||||||
limit: 2
|
limit: 2
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(rows.map((row) => row.rawText)).toEqual(['11:00', '12:00'])
|
expect(rows.map((row) => row.rawText)).toEqual(['11:00', '12:00'])
|
||||||
|
|
||||||
await householdClient.close()
|
await householdClient.close()
|
||||||
await historyClient.close()
|
await historyClient.close()
|
||||||
})
|
},
|
||||||
|
10000
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user