Tests[SendToNewChannel]
This commit is contained in:
parent
66ecad27a7
commit
f1e87170f0
@ -5,7 +5,6 @@ import (
|
||||
tt "blackforestbytes.com/simplecloudnotifier/test/util"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/timeext"
|
||||
"net/url"
|
||||
"testing"
|
||||
@ -26,8 +25,8 @@ func TestSearchMessageFTSSimple(t *testing.T) {
|
||||
|
||||
msgList := tt.RequestAuthGet[mglist](t, data.User[0].AdminKey, baseUrl, fmt.Sprintf("/api/messages?filter=%s", url.QueryEscape("Friday")))
|
||||
tt.AssertEqual(t, "msgList.len", 2, len(msgList.Messages))
|
||||
tt.AssertTrue(t, "msgList.any<1>", langext.ArrAny(msgList.Messages, func(msg gin.H) bool { return msg["title"].(string) == "Invitation" }))
|
||||
tt.AssertTrue(t, "msgList.any<2>", langext.ArrAny(msgList.Messages, func(msg gin.H) bool { return msg["title"].(string) == "Important notice" }))
|
||||
tt.AssertArrAny(t, "msgList.any<1>", msgList.Messages, func(msg gin.H) bool { return msg["title"].(string) == "Invitation" })
|
||||
tt.AssertArrAny(t, "msgList.any<2>", msgList.Messages, func(msg gin.H) bool { return msg["title"].(string) == "Important notice" })
|
||||
}
|
||||
|
||||
func TestSearchMessageFTSMulti(t *testing.T) {
|
||||
|
@ -1013,10 +1013,82 @@ func TestSendCompat(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestSendToNewChannel(t *testing.T) {
|
||||
ws, stop := tt.StartSimpleWebserver(t)
|
||||
defer stop()
|
||||
|
||||
baseUrl := "http://127.0.0.1:" + ws.Port
|
||||
|
||||
r0 := tt.RequestPost[gin.H](t, baseUrl, "/api/users", gin.H{
|
||||
"agent_model": "DUMMY_PHONE",
|
||||
"agent_version": "4X",
|
||||
"client_type": "ANDROID",
|
||||
"fcm_token": "DUMMY_FCM",
|
||||
})
|
||||
|
||||
uid := int(r0["user_id"].(float64))
|
||||
sendtok := r0["send_key"].(string)
|
||||
admintok := r0["admin_key"].(string)
|
||||
|
||||
type chanlist struct {
|
||||
Channels []gin.H `json:"channels"`
|
||||
}
|
||||
|
||||
{
|
||||
chan0 := tt.RequestAuthGet[chanlist](t, baseUrl, admintok, fmt.Sprintf("/api/user/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan-count", 1, len(chan0.Channels))
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
"user_key": sendtok,
|
||||
"user_id": uid,
|
||||
"title": "M1",
|
||||
"content": tt.Lipsum0(4),
|
||||
"channel": "main",
|
||||
})
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, baseUrl, admintok, fmt.Sprintf("/api/user/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "main", clist.Channels[0]["name"])
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
"user_key": sendtok,
|
||||
"user_id": uid,
|
||||
"title": "M2",
|
||||
"content": tt.Lipsum0(4),
|
||||
"channel": "test",
|
||||
})
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, baseUrl, admintok, fmt.Sprintf("/api/user/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan-count", 2, len(clist.Channels))
|
||||
tt.AssertArrAny(t, "chan.has('main')", clist.Channels, func(msg gin.H) bool { return msg["name"].(string) == "main" })
|
||||
tt.AssertArrAny(t, "chan.has('test')", clist.Channels, func(msg gin.H) bool { return msg["name"].(string) == "test" })
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
"user_key": sendtok,
|
||||
"user_id": uid,
|
||||
"title": "M3",
|
||||
"channel": "test",
|
||||
})
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, baseUrl, admintok, fmt.Sprintf("/api/user/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan-count", 2, len(clist.Channels))
|
||||
tt.AssertArrAny(t, "chan.has('main')", clist.Channels, func(msg gin.H) bool { return msg["name"].(string) == "main" })
|
||||
tt.AssertArrAny(t, "chan.has('test')", clist.Channels, func(msg gin.H) bool { return msg["name"].(string) == "test" })
|
||||
}
|
||||
}
|
||||
|
||||
//TODO post to channel
|
||||
|
||||
//TODO post to newly-created-channel
|
||||
|
||||
//TODO post to existing-channel
|
||||
|
||||
//TODO post to foreign channel via send-key
|
||||
|
||||
//TODO quota exceed (+ quota counter)
|
||||
|
@ -2,6 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
@ -163,6 +164,14 @@ func TestFailIfErr(t *testing.T, e error) {
|
||||
}
|
||||
}
|
||||
|
||||
func AssertArrAny[T any](t *testing.T, key string, arr []T, fn func(T) bool) {
|
||||
if !langext.ArrAny(arr, fn) {
|
||||
t.Errorf("AssertArrAny(%s) failed", key)
|
||||
t.Error(string(debug.Stack()))
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func unpointer(v any) any {
|
||||
if v == nil {
|
||||
return v
|
||||
|
Loading…
Reference in New Issue
Block a user