chatDB tests + message length identical with WA

This commit is contained in:
Adhiraj
2020-09-02 22:40:51 +05:30
parent f12551ba18
commit 4c646e3e02
6 changed files with 41 additions and 12 deletions

View File

@@ -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),
[]
)
))
}

View File

@@ -2,6 +2,7 @@ import * as assert from 'assert'
import {WAConnection} from '../WAConnection/WAConnection'
import { AuthenticationCredentialsBase64, BaileysError, ReconnectMode, DisconnectReason } from '../WAConnection/Constants'
import { delay } from '../WAConnection/Utils'
import { assertChatDBIntegrity } from './Common'
describe('QR Generation', () => {
it('should generate QR', async () => {
@@ -37,6 +38,8 @@ describe('Test Connect', () => {
assert.ok(conn.user?.phone)
assert.ok (conn.user?.imgUrl || conn.user.imgUrl === '')
assertChatDBIntegrity (conn)
conn.close()
auth = conn.base64EncodedAuthInfo()
})