mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Initial Conversion to typescript
This commit is contained in:
58
WAConnection/Tests.ts
Normal file
58
WAConnection/Tests.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import assert from 'assert'
|
||||
import WAConnection from './WAConnection'
|
||||
import { AuthenticationCredentialsBase64 } from './Constants'
|
||||
|
||||
describe('QR generation', () => {
|
||||
it('should generate QR', async () => {
|
||||
const conn = new WAConnection()
|
||||
let calledQR = false
|
||||
conn.onReadyForPhoneAuthentication = ([ref, curveKey, clientID]) => {
|
||||
assert.ok(ref, 'ref nil')
|
||||
assert.ok(curveKey, 'curve key nil')
|
||||
assert.ok(clientID, 'client ID nil')
|
||||
calledQR = true
|
||||
}
|
||||
await assert.rejects(async () => conn.connectSlim(null, 5000), 'should have failed connect')
|
||||
assert.equal(calledQR, true, 'QR not called')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Test Connect', () => {
|
||||
let auth: AuthenticationCredentialsBase64
|
||||
it('should connect', async () => {
|
||||
console.log('please be ready to scan with your phone')
|
||||
const conn = new WAConnection()
|
||||
await assert.doesNotReject(async () => conn.connectSlim(null), 'initial connection failed')
|
||||
assert.ok(conn.userMetaData)
|
||||
assert.ok(conn.userMetaData.id)
|
||||
|
||||
conn.close()
|
||||
auth = conn.base64EncodedAuthInfo()
|
||||
})
|
||||
it('should reconnect', async () => {
|
||||
const conn = new WAConnection()
|
||||
|
||||
const [user, chats, contacts, unread] = await conn.connect('./auth_info.json', 20 * 1000)
|
||||
|
||||
assert.ok(user)
|
||||
assert.ok(user.id)
|
||||
|
||||
assert.ok(chats)
|
||||
if (chats.length > 0) {
|
||||
assert.ok(chats[0].jid)
|
||||
assert.ok(chats[0].count)
|
||||
}
|
||||
assert.ok(contacts)
|
||||
if (contacts.length > 0) {
|
||||
assert.ok(contacts[0].jid)
|
||||
}
|
||||
assert.ok(unread)
|
||||
if (unread.length > 0) {
|
||||
assert.ok(unread[0].key)
|
||||
}
|
||||
|
||||
await conn.logout()
|
||||
|
||||
await assert.rejects(async () => conn.connectSlim(auth), 'reconnect should have failed')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user