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