mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chatDB tests + message length identical with WA
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { WAConnection, MessageLogLevel, MessageOptions, MessageType, unixTimestampSeconds } from '../WAConnection/WAConnection'
|
||||
import { WAConnection, MessageLogLevel, MessageOptions, MessageType, unixTimestampSeconds, toNumber } from '../WAConnection/WAConnection'
|
||||
import * as assert from 'assert'
|
||||
import {promises as fs} from 'fs'
|
||||
|
||||
@@ -13,6 +13,7 @@ export async function sendAndRetreiveMessage(conn: WAConnection, content, type:
|
||||
|
||||
const chat = conn.chats.get(testJid)
|
||||
|
||||
assertChatDBIntegrity (conn)
|
||||
assert.ok (chat.messages.find(m => m.key.id === response.key.id))
|
||||
assert.ok (chat.t >= (unixTimestampSeconds()-5) )
|
||||
return message
|
||||
@@ -32,4 +33,18 @@ export const WAConnectionTest = (name: string, func: (conn: WAConnection) => voi
|
||||
|
||||
func(conn)
|
||||
})
|
||||
)
|
||||
)
|
||||
export const assertChatDBIntegrity = (conn: WAConnection) => {
|
||||
conn.chats.all ().forEach (chat => (
|
||||
assert.equal (
|
||||
chat.messages.sort ((m1, m2) => toNumber(m1.messageTimestamp)-toNumber(m2.messageTimestamp)),
|
||||
chat.messages
|
||||
)
|
||||
))
|
||||
conn.chats.all ().forEach (chat => (
|
||||
assert.deepEqual (
|
||||
chat.messages.filter (m => chat.messages.filter(m1 => m1.key.id === m.key.id).length > 1),
|
||||
[]
|
||||
)
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user