mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
Initial V3.0
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { WAConnection, MessageLogLevel, MessageOptions, MessageType } from '../WAConnection/WAConnection'
|
||||
import { WAConnection, MessageLogLevel, MessageOptions, MessageType, unixTimestampSeconds } from '../WAConnection/WAConnection'
|
||||
import * as assert from 'assert'
|
||||
import {promises as fs} from 'fs'
|
||||
|
||||
@@ -7,22 +7,29 @@ export const testJid = process.env.TEST_JID || '1234@s.whatsapp.net' // set TEST
|
||||
|
||||
export async function sendAndRetreiveMessage(conn: WAConnection, content, type: MessageType, options: MessageOptions = {}) {
|
||||
const response = await conn.sendMessage(testJid, content, type, options)
|
||||
const messages = await conn.loadConversation(testJid, 10, null, true)
|
||||
const {messages} = await conn.loadMessages(testJid, 10)
|
||||
const message = messages.find (m => m.key.id === response.key.id)
|
||||
assert.ok(message)
|
||||
|
||||
const chat = conn.chats.get(testJid)
|
||||
|
||||
assert.ok (chat.messages.find(m => m.key.id === response.key.id))
|
||||
assert.ok (chat.t >= (unixTimestampSeconds()-5) )
|
||||
return message
|
||||
}
|
||||
export function WAConnectionTest(name: string, func: (conn: WAConnection) => void) {
|
||||
export const WAConnectionTest = (name: string, func: (conn: WAConnection) => void) => (
|
||||
describe(name, () => {
|
||||
const conn = new WAConnection()
|
||||
conn.logLevel = MessageLogLevel.info
|
||||
|
||||
before(async () => {
|
||||
//conn.logLevel = MessageLogLevel.unhandled
|
||||
const file = './auth_info.json'
|
||||
await conn.connectSlim(file)
|
||||
await conn.loadAuthInfo(file).connect()
|
||||
await fs.writeFile(file, JSON.stringify(conn.base64EncodedAuthInfo(), null, '\t'))
|
||||
})
|
||||
after(() => conn.close())
|
||||
|
||||
func(conn)
|
||||
})
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user