mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Track updated contacts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as assert from 'assert'
|
||||
import {WAConnection} from '../WAConnection/WAConnection'
|
||||
import { AuthenticationCredentialsBase64, BaileysError, ReconnectMode, DisconnectReason, WAChat } from '../WAConnection/Constants'
|
||||
import { AuthenticationCredentialsBase64, BaileysError, ReconnectMode, DisconnectReason, WAChat, WAContact } from '../WAConnection/Constants'
|
||||
import { delay } from '../WAConnection/Utils'
|
||||
import { assertChatDBIntegrity, makeConnection, testJid } from './Common'
|
||||
|
||||
@@ -285,7 +285,7 @@ describe ('Reconnects', () => {
|
||||
})
|
||||
|
||||
describe ('Pending Requests', () => {
|
||||
it ('should correctly send updates', async () => {
|
||||
it ('should correctly send updates for chats', async () => {
|
||||
const conn = makeConnection ()
|
||||
conn.pendingRequestTimeoutMs = null
|
||||
conn.loadAuthInfo('./auth_info.json')
|
||||
@@ -315,6 +315,42 @@ describe ('Pending Requests', () => {
|
||||
|
||||
conn.close ()
|
||||
})
|
||||
it ('should correctly send updates for contacts', async () => {
|
||||
const conn = makeConnection ()
|
||||
conn.pendingRequestTimeoutMs = null
|
||||
conn.loadAuthInfo('./auth_info.json')
|
||||
|
||||
const task: any = new Promise(resolve => conn.once('contacts-received', resolve))
|
||||
await conn.connect ()
|
||||
const initialResult = await task
|
||||
assert.strictEqual(
|
||||
initialResult.updatedContacts.length,
|
||||
Object.keys(conn.contacts).length
|
||||
)
|
||||
|
||||
|
||||
conn.close ()
|
||||
|
||||
const [jid] = Object.keys(conn.contacts)
|
||||
const oldContact = conn.contacts[jid]
|
||||
oldContact.name = 'Lol'
|
||||
oldContact.index = 'L'
|
||||
|
||||
const promise = new Promise(resolve => conn.once('contacts-received', resolve))
|
||||
|
||||
const result = await conn.connect ()
|
||||
assert.ok (!result.newConnection)
|
||||
|
||||
const {updatedContacts} = await promise as { updatedContacts: Partial<WAContact>[] }
|
||||
const contact = updatedContacts.find (c => c.jid === jid)
|
||||
assert.ok (contact)
|
||||
|
||||
assert.ok ('name' in contact)
|
||||
assert.strictEqual (Object.keys(contact).length, 3)
|
||||
assert.strictEqual (Object.keys(updatedContacts).length, 1)
|
||||
|
||||
conn.close ()
|
||||
})
|
||||
it('should queue requests when closed', async () => {
|
||||
const conn = makeConnection ()
|
||||
//conn.pendingRequestTimeoutMs = null
|
||||
|
||||
@@ -203,7 +203,7 @@ WAConnectionTest('Misc', conn => {
|
||||
if (!chat) {
|
||||
// wait for chats
|
||||
await new Promise(resolve => (
|
||||
conn.once('chats-received', () => resolve())
|
||||
conn.once('chats-received', resolve)
|
||||
))
|
||||
chat = conn.chats.get(testJid)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user