mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Better phone connection detection
This commit is contained in:
@@ -372,6 +372,21 @@ describe ('Pending Requests', () => {
|
||||
|
||||
conn.close ()
|
||||
})
|
||||
it('[MANUAL] should receive query response after phone disconnect', async () => {
|
||||
const conn = makeConnection ()
|
||||
await conn.loadAuthInfo('./auth_info.json').connect ()
|
||||
|
||||
console.log(`disconnect your phone from the internet!`)
|
||||
await delay(5000)
|
||||
const task = conn.loadMessages(testJid, 50)
|
||||
setTimeout(() => console.log('reconnect your phone!'), 20_000)
|
||||
|
||||
const result = await task
|
||||
assert.ok(result.messages[0])
|
||||
assert.ok(!conn['phoneCheckInterval']) // should be undefined
|
||||
|
||||
conn.close ()
|
||||
})
|
||||
it('should re-execute query on connection closed error', async () => {
|
||||
const conn = makeConnection ()
|
||||
//conn.pendingRequestTimeoutMs = 10_000
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Presence, ChatModification, delay, newMessagesDB, WA_DEFAULT_EPHEMERAL, MessageType } from '../WAConnection/WAConnection'
|
||||
import { Presence, ChatModification, delay, newMessagesDB, WA_DEFAULT_EPHEMERAL, MessageType, WAMessage } from '../WAConnection/WAConnection'
|
||||
import { promises as fs } from 'fs'
|
||||
import * as assert from 'assert'
|
||||
import fetch from 'node-fetch'
|
||||
@@ -397,4 +397,20 @@ WAConnectionTest('Misc', conn => {
|
||||
assert.strictEqual(conn.blocklist.length, blockedCount);
|
||||
await waitForEventRemoved
|
||||
})
|
||||
it('should exit an invalid query', async () => {
|
||||
// try and send an already sent message
|
||||
let msg: WAMessage
|
||||
await conn.findMessage(testJid, 5, m => {
|
||||
if(m.key.fromMe) {
|
||||
msg = m
|
||||
return true
|
||||
}
|
||||
})
|
||||
try {
|
||||
await conn.relayWAMessage(msg)
|
||||
assert.fail('should not have sent')
|
||||
} catch(error) {
|
||||
assert.strictEqual(error.status, 422)
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user