mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Added method to block/unblock user (close #233)
This commit is contained in:
@@ -258,4 +258,30 @@ WAConnectionTest('Misc', conn => {
|
||||
)
|
||||
assert.ok(msg.message.extendedTextMessage)
|
||||
})
|
||||
it('should block & unblock a user', async () => {
|
||||
const blockedCount = conn.blocklist.length;
|
||||
|
||||
const waitForEventAdded = new Promise<void> (resolve => {
|
||||
conn.once ('blocklist-update', ({added}) => {
|
||||
assert.ok (added.length)
|
||||
resolve ()
|
||||
})
|
||||
})
|
||||
|
||||
await conn.blockUser (testJid, 'add')
|
||||
assert.strictEqual(conn.blocklist.length, blockedCount + 1);
|
||||
await waitForEventAdded
|
||||
|
||||
await delay (2000)
|
||||
const waitForEventRemoved = new Promise<void> (resolve => {
|
||||
conn.once ('blocklist-update', ({removed}) => {
|
||||
assert.ok (removed.length)
|
||||
resolve ()
|
||||
})
|
||||
})
|
||||
|
||||
await conn.blockUser (testJid, 'remove')
|
||||
assert.strictEqual(conn.blocklist.length, blockedCount);
|
||||
await waitForEventRemoved
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user