Add tests [TestListSenderNames] [TestListUserSenderNames]

This commit is contained in:
2024-09-20 16:33:45 +02:00
parent 5dd94eca38
commit 584a9e983f
7 changed files with 157 additions and 13 deletions

View File

@@ -13,7 +13,7 @@ func TestResponseChannel(t *testing.T) {
data := tt.InitDefaultData(t, ws)
response := tt.RequestAuthGetRaw(t, data.User[0].AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s", data.User[0].UID, data.User[0].Channels[0]))
response := tt.RequestAuthGetRaw(t, data.User[0].AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels/%s", data.User[0].UID, data.User[0].Channels[0].ChannelID))
tt.AssertJsonStructureMatch(t, "json[channel]", response, map[string]any{
"channel_id": "id",
@@ -63,7 +63,7 @@ func TestResponseKeyToken1(t *testing.T) {
data := tt.InitDefaultData(t, ws)
response := tt.RequestAuthGetRaw(t, data.User[0].AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.User[0].UID, data.User[0].Keys[0]))
response := tt.RequestAuthGetRaw(t, data.User[0].AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/%s", data.User[0].UID, data.User[0].Keys[0].KeyID))
tt.AssertJsonStructureMatch(t, "json[key]", response, map[string]any{
"keytoken_id": "id",
@@ -246,7 +246,7 @@ func TestResponseChannelPreview(t *testing.T) {
data := tt.InitDefaultData(t, ws)
response := tt.RequestAuthGetRaw(t, data.User[1].AdminKey, baseUrl, fmt.Sprintf("/api/v2/preview/channels/%s", data.User[0].Channels[0]))
response := tt.RequestAuthGetRaw(t, data.User[1].AdminKey, baseUrl, fmt.Sprintf("/api/v2/preview/channels/%s", data.User[0].Channels[0].ChannelID))
tt.AssertJsonStructureMatch(t, "json[channel]", response, map[string]any{
"channel_id": "id",
@@ -277,7 +277,7 @@ func TestResponseKeyTokenPreview(t *testing.T) {
data := tt.InitDefaultData(t, ws)
response := tt.RequestAuthGetRaw(t, data.User[1].AdminKey, baseUrl, fmt.Sprintf("/api/v2/preview/keys/%s", data.User[0].Keys[0]))
response := tt.RequestAuthGetRaw(t, data.User[1].AdminKey, baseUrl, fmt.Sprintf("/api/v2/preview/keys/%s", data.User[0].Keys[0].KeyID))
tt.AssertJsonStructureMatch(t, "json[key]", response, map[string]any{
"keytoken_id": "id",

View File

@@ -1,11 +1,105 @@
package test
import "testing"
import (
tt "blackforestbytes.com/simplecloudnotifier/test/util"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
"testing"
)
func TestListSenderNames(t *testing.T) {
t.Fail()
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
defer stop()
data := tt.InitDefaultData(t, ws)
type sn struct {
SenderName string `json:"name"`
LastTimestamp string `json:"last_timestamp"`
FirstTimestamp string `json:"first_timestamp"`
Count int `json:"count"`
}
type snlistS struct {
SNList []sn `json:"sender_names"`
}
type snlistH struct {
SNList []gin.H `json:"sender_names"`
}
responses := []struct {
Idx int
Resp []string
}{
{0, []string{"Pocket Pal", "Cellular Confidant", "Mobile Mate"}},
{1, []string{}},
{2, []string{}},
{3, []string{}},
{4, []string{"Server0"}},
{5, []string{"example.org", "example.com", "localhost"}},
{6, []string{"server1", "server2"}},
{7, []string{"localhost"}},
{8, []string{}},
{9, []string{"Vincent", "Tim", "Max"}},
{10, []string{}},
{11, []string{"192.168.0.1", "#S0", "localhost"}},
{12, []string{}},
{13, []string{}},
{14, []string{"dummy-man"}},
{15, []string{"dummy-man"}},
{16, []string{}},
}
for _, resp := range responses {
msgList := tt.RequestAuthGet[snlistH](t, data.User[resp.Idx].AdminKey, baseUrl, "/api/v2/sender-names")
tt.AssertMappedArr(t, "sender_names_"+strconv.Itoa(resp.Idx), resp.Resp, msgList.SNList, "name")
}
}
func TestListUserSenderNames(t *testing.T) {
t.Fail()
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
defer stop()
data := tt.InitDefaultData(t, ws)
type sn struct {
SenderName string `json:"name"`
LastTimestamp string `json:"last_timestamp"`
FirstTimestamp string `json:"first_timestamp"`
Count int `json:"count"`
}
type snlistS struct {
SNList []sn `json:"sender_names"`
}
type snlistH struct {
SNList []gin.H `json:"sender_names"`
}
responses := []struct {
Idx int
Resp []string
}{
{0, []string{"Pocket Pal", "Cellular Confidant", "Mobile Mate"}},
{1, []string{}},
{2, []string{}},
{3, []string{}},
{4, []string{"Server0"}},
{5, []string{"example.org", "example.com", "localhost"}},
{6, []string{"server1", "server2"}},
{7, []string{"localhost"}},
{8, []string{}},
{9, []string{"Vincent", "Tim", "Max"}},
{10, []string{}},
{11, []string{"192.168.0.1", "#S0", "localhost"}},
{12, []string{}},
{13, []string{}},
{14, []string{}},
{15, []string{"dummy-man"}},
{16, []string{}},
}
for _, resp := range responses {
msgList := tt.RequestAuthGet[snlistH](t, data.User[resp.Idx].AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/sender-names", data.User[resp.Idx].UID))
tt.AssertMappedArr(t, "sender_names_"+strconv.Itoa(resp.Idx), resp.Resp, msgList.SNList, "name")
}
}

View File

@@ -294,7 +294,8 @@ var messageExamples = []msgex{
{15, "", "", P0, SKEY, "New Feature Available", "ability to schedule appointments", 0},
{15, "chan_other_nosub", "", P0, SKEY, "Account Suspended", "Please contact us", 0},
{15, "chan_other_request", "", P0, SKEY, "Invitation to Beta Test", "", 0},
{15, "chan_other_accepted", "", P0, SKEY, "New Blog Post", "Congratulations on your promotion! We are proud", 0},
{15, "chan_other_request", "", P0, SKEY, "Invitation to Beta Test (with sendername)", "", 0},
{15, "chan_other_accepted", "dummy-man", P0, SKEY, "New Blog Post", "Congratulations on your promotion! We are proud", 0},
{16, "Chan1", "", P2, SKEY, "Lorem Ipsum 01", Lipsum(30001, 1), 0},
{16, "Chan2", "", P0, SKEY, "Lorem Ipsum 02", Lipsum(30002, 1), 0},