package tests

import (
	"context"
	"fmt"
	"gin-vue-admin/im"
	"log"
	"testing"
	"time"

	"nhooyr.io/websocket"
	"nhooyr.io/websocket/wsjson"
)

func TestConnectIm(t *testing.T) {

	ctx := context.Background()

	conn, _, err := websocket.Dial(ctx, "ws://192.168.86.28:1022/ws?policy_number=1234567890", nil)
	if err != nil {
		log.Println("Dial error:", err)
		return
	}

	// go sendMessage(conn, "NeAuCb0IAn", "18611466332")

	time.Sleep(5 * time.Second)
	var message im.Message
	err = wsjson.Read(ctx, conn, &message)
	if err != nil {
		log.Println("receive msg error:", err)
		return
	}

	fmt.Println("message.Receiver: ", message.Receiver)
	fmt.Println("message.Sender: ", message.Sender)
	fmt.Println("message.Content: ", message.Content)

	fmt.Println(message.SendTime)
	fmt.Printf("\n\n\n\n")
	conn.Close(websocket.StatusNormalClosure, "")

}
