Save internal_name and display_name in channel
This commit is contained in:
@@ -29,7 +29,8 @@ func TestCreateChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "name")
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestAuthPost[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
@@ -39,7 +40,8 @@ func TestCreateChannel(t *testing.T) {
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertMappedSet(t, "channels", []string{"test"}, clist.Channels, "name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestAuthPost[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
@@ -48,7 +50,8 @@ func TestCreateChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"asdf", "test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,8 +93,9 @@ func TestChannelNameNormalization(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
chan0 := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan-count", 0, len(chan0.Channels))
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestAuthPost[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
@@ -100,8 +104,8 @@ func TestChannelNameNormalization(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "test", clist.Channels[0]["name"])
|
||||
tt.AssertMappedSet(t, "channels", []string{"tESt"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestAuthPostShouldFail(t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
@@ -125,14 +129,25 @@ func TestChannelNameNormalization(t *testing.T) {
|
||||
}, 409, apierr.CHANNEL_ALREADY_EXISTS)
|
||||
|
||||
tt.RequestAuthPostShouldFail(t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
"name": " T e s t ",
|
||||
"name": "\rTeSt\n",
|
||||
}, 409, apierr.CHANNEL_ALREADY_EXISTS)
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "test", clist.Channels[0]["name"])
|
||||
tt.AssertMappedSet(t, "channels", []string{"tESt"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestAuthPost[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
"name": " WeiRD_[\uF5FF]\\stUFf\r\n\t ",
|
||||
})
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertMappedSet(t, "channels", []string{"tESt", "WeiRD_[\uF5FF]\\stUFf"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"test", "weird_[\uF5FF]\\stuff"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestListChannelsOwned(t *testing.T) {
|
||||
@@ -147,24 +162,26 @@ func TestListChannelsOwned(t *testing.T) {
|
||||
|
||||
testdata := map[int][]string{
|
||||
0: {"main", "chattingchamber", "unicdhll", "promotions", "reminders"},
|
||||
1: {"promotions"},
|
||||
2: {},
|
||||
3: {},
|
||||
4: {},
|
||||
5: {},
|
||||
6: {},
|
||||
7: {},
|
||||
8: {},
|
||||
9: {},
|
||||
10: {},
|
||||
11: {},
|
||||
1: {"main", "private"},
|
||||
2: {"main", "ü", "ö", "ä"},
|
||||
3: {"main", "innovations", "reminders"},
|
||||
4: {"main"},
|
||||
5: {"main", "test1", "test2", "test3", "test4", "test5"},
|
||||
6: {"main", "security", "lipsum"},
|
||||
7: {"main"},
|
||||
8: {"main"},
|
||||
9: {"main", "manual@chan"},
|
||||
10: {"main"},
|
||||
11: {"promotions"},
|
||||
12: {},
|
||||
13: {},
|
||||
14: {"", "chan_self_subscribed", "chan_self_unsub"}, //TODO these two have the interesting cases
|
||||
15: {"", "chan_other_nosub", "chan_other_request", "chan_other_request", "chan_other_accepted"}, //TODO these two have the interesting cases
|
||||
}
|
||||
|
||||
for k, v := range testdata {
|
||||
r0 := tt.RequestAuthGet[chanlist](t, data.User[k].AdminKey, baseUrl, fmt.Sprintf("/api/users/%d/channels", data.User[k].UID))
|
||||
tt.AssertMappedSet(t, fmt.Sprintf("%d->chanlist", k), v, r0.Channels, "name")
|
||||
tt.AssertMappedSet(t, fmt.Sprintf("%d->chanlist", k), v, r0.Channels, "internal_name")
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -166,7 +166,7 @@ func TestGetMessageFull(t *testing.T) {
|
||||
|
||||
tt.AssertEqual(t, "msg.title", "Message_1", msgIn["title"])
|
||||
tt.AssertEqual(t, "msg.content", content, msgIn["content"])
|
||||
tt.AssertEqual(t, "msg.channel", "demo-channel-007", msgIn["channel_name"])
|
||||
tt.AssertEqual(t, "msg.channel", "demo-channel-007", msgIn["channel_internal_name"])
|
||||
tt.AssertEqual(t, "msg.msg_id", "580b5055-a9b5-4cee-b53c-28cf304d25b0", msgIn["usr_message_id"])
|
||||
tt.AssertStrRepEqual(t, "msg.priority", 0, msgIn["priority"])
|
||||
tt.AssertEqual(t, "msg.sender_name", "unit-test-[TestGetMessageFull]", msgIn["sender_name"])
|
||||
|
@@ -61,7 +61,7 @@ func TestSendSimpleMessageJSON(t *testing.T) {
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
}
|
||||
|
||||
func TestSendSimpleMessageQuery(t *testing.T) {
|
||||
@@ -97,7 +97,7 @@ func TestSendSimpleMessageQuery(t *testing.T) {
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "Hello World 2134", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
}
|
||||
|
||||
func TestSendSimpleMessageForm(t *testing.T) {
|
||||
@@ -137,7 +137,7 @@ func TestSendSimpleMessageForm(t *testing.T) {
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "Hello World 9999 [$$$]", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
}
|
||||
|
||||
func TestSendSimpleMessageFormAndQuery(t *testing.T) {
|
||||
@@ -238,7 +238,7 @@ func TestSendSimpleMessageAlt1(t *testing.T) {
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
}
|
||||
|
||||
func TestSendContentMessage(t *testing.T) {
|
||||
@@ -278,12 +278,12 @@ func TestSendContentMessage(t *testing.T) {
|
||||
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_042", msgList1.Messages[0]["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", "I am Content\nasdf", msgList1.Messages[0]["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msgList1.Messages[0]["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msgList1.Messages[0]["channel_internal_name"])
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_042", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", "I am Content\nasdf", msg1Get["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
}
|
||||
|
||||
func TestSendWithSendername(t *testing.T) {
|
||||
@@ -326,13 +326,13 @@ func TestSendWithSendername(t *testing.T) {
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_xyz", msgList1.Messages[0]["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", "Unicode: 日本 - yäy\000\n\t\x00...", msgList1.Messages[0]["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.sender_name", "localhorst", msgList1.Messages[0]["sender_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msgList1.Messages[0]["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msgList1.Messages[0]["channel_internal_name"])
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_xyz", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", "Unicode: 日本 - yäy\000\n\t\x00...", msg1Get["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.sender_name", "localhorst", msg1Get["sender_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
}
|
||||
|
||||
func TestSendLongContent(t *testing.T) {
|
||||
@@ -377,20 +377,20 @@ func TestSendLongContent(t *testing.T) {
|
||||
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_042", msgList1.Messages[0]["title"])
|
||||
tt.AssertNotStrRepEqual(t, "msg.content", longContent, msgList1.Messages[0]["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msgList1.Messages[0]["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msgList1.Messages[0]["channel_internal_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.trimmmed", true, msgList1.Messages[0]["trimmed"])
|
||||
|
||||
msgList2 := tt.RequestAuthGet[mglist](t, admintok, baseUrl, "/api/messages?trimmed=false")
|
||||
tt.AssertEqual(t, "len(messages)", 1, len(msgList2.Messages))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_042", msgList2.Messages[0]["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", longContent, msgList2.Messages[0]["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msgList2.Messages[0]["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msgList2.Messages[0]["channel_internal_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.trimmmed", false, msgList2.Messages[0]["trimmed"])
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_042", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.titcontentle", longContent, msg1Get["content"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.trimmmed", false, msg1Get["trimmed"])
|
||||
}
|
||||
|
||||
@@ -859,7 +859,7 @@ func TestSendWithTimestamp(t *testing.T) {
|
||||
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "TTT", msgList1.Messages[0]["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", nil, msgList1.Messages[0]["sender_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msgList1.Messages[0]["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msgList1.Messages[0]["channel_internal_name"])
|
||||
|
||||
tm1, err := time.Parse(time.RFC3339Nano, msgList1.Messages[0]["timestamp"].(string))
|
||||
tt.TestFailIfErr(t, err)
|
||||
@@ -868,7 +868,7 @@ func TestSendWithTimestamp(t *testing.T) {
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "TTT", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.content", nil, msg1Get["sender_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
|
||||
tmg1, err := time.Parse(time.RFC3339Nano, msg1Get["timestamp"].(string))
|
||||
tt.TestFailIfErr(t, err)
|
||||
@@ -1022,7 +1022,7 @@ func TestSendCompat(t *testing.T) {
|
||||
|
||||
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg1["scn_msg_id"]))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", msg1Get["title"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_name", "main", msg1Get["channel_name"])
|
||||
tt.AssertStrRepEqual(t, "msg.channel_internal_name", "main", msg1Get["channel_internal_name"])
|
||||
|
||||
msg2 := tt.RequestPost[gin.H](t, baseUrl, fmt.Sprintf("/send.php?user_key=%s&user_id=%d&title=%s", sendtok, uid, "HelloWorld_002"), nil)
|
||||
|
||||
@@ -1098,8 +1098,8 @@ func TestSendToNewChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "main", clist.Channels[0]["name"])
|
||||
tt.AssertMappedSet(t, "channels", []string{"main"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1112,8 +1112,8 @@ func TestSendToNewChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "main", clist.Channels[0]["name"])
|
||||
tt.AssertMappedSet(t, "channels", []string{"main"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1126,9 +1126,8 @@ func TestSendToNewChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%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.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1140,9 +1139,8 @@ func TestSendToNewChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%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.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1166,8 +1164,9 @@ func TestSendToManualChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
chan0 := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan-count", 0, len(chan0.Channels))
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1178,8 +1177,8 @@ func TestSendToManualChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "main", clist.Channels[0]["name"])
|
||||
tt.AssertMappedSet(t, "channels", []string{"main"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1193,7 +1192,8 @@ func TestSendToManualChannel(t *testing.T) {
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid))
|
||||
tt.AssertEqual(t, "chan.len", 1, len(clist.Channels))
|
||||
tt.AssertEqual(t, "chan.name", "main", clist.Channels[0]["name"])
|
||||
tt.AssertEqual(t, "chan.internal_name", "main", clist.Channels[0]["internal_name"])
|
||||
tt.AssertEqual(t, "chan.display_name", "main", clist.Channels[0]["display_name"])
|
||||
}
|
||||
|
||||
tt.RequestAuthPost[gin.H](t, admintok, baseUrl, fmt.Sprintf("/api/users/%d/channels", uid), gin.H{
|
||||
@@ -1202,9 +1202,8 @@ func TestSendToManualChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%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.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1217,9 +1216,8 @@ func TestSendToManualChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%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.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
|
||||
tt.RequestPost[gin.H](t, baseUrl, "/", gin.H{
|
||||
@@ -1231,9 +1229,8 @@ func TestSendToManualChannel(t *testing.T) {
|
||||
|
||||
{
|
||||
clist := tt.RequestAuthGet[chanlist](t, admintok, baseUrl, fmt.Sprintf("/api/users/%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.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "display_name")
|
||||
tt.AssertMappedSet(t, "channels", []string{"main", "test"}, clist.Channels, "internal_name")
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -203,7 +203,14 @@ func AssertMultiNonEmpty(t *testing.T, key string, args ...any) {
|
||||
|
||||
func AssertMappedSet[T langext.OrderedConstraint](t *testing.T, key string, expected []T, values []gin.H, objkey string) {
|
||||
|
||||
actual := langext.ArrMap(values, func(v gin.H) T { return v[objkey].(T) })
|
||||
actual := make([]T, 0)
|
||||
for idx, vv := range values {
|
||||
if tv, ok := vv[objkey].(T); ok {
|
||||
actual = append(actual, tv)
|
||||
} else {
|
||||
TestFailFmt(t, "[%s]->[%d] is wrong type (expected: %T, actual: %T)", key, idx, *new(T), vv)
|
||||
}
|
||||
}
|
||||
|
||||
langext.Sort(actual)
|
||||
langext.Sort(expected)
|
||||
|
@@ -86,8 +86,10 @@ var userExamples = []userex{
|
||||
{9, true, "UniqueUnicorn", "Galaxy Quest", "2023.1", "ANDROID", "FCM_TOK_EX_010", ""},
|
||||
{10, false, "", "", "", "", "", ""},
|
||||
{11, false, "", "", "", "", "", "ANDROID|v2|PURCHASED:PRO_TOK_002"},
|
||||
{12, true, "ChanTester1", "StarfireXX", "1.x", "IOS", "FCM_TOK_EX_012", ""},
|
||||
{13, true, "ChanTester2", "StarfireXX", "1.x", "IOS", "FCM_TOK_EX_013", ""},
|
||||
{12, true, "NoMessageUser", "Ocean Explorer", "737edc01", "IOS", "FCM_TOK_EX_014", ""},
|
||||
{13, false, "EmptyUser", "", "", "", "", ""},
|
||||
{14, true, "ChanTester1", "StarfireXX", "1.x", "IOS", "FCM_TOK_EX_012", ""},
|
||||
{15, true, "ChanTester2", "StarfireXX", "1.x", "IOS", "FCM_TOK_EX_013", ""},
|
||||
}
|
||||
|
||||
var clientExamples = []clientex{
|
||||
@@ -267,14 +269,14 @@ var messageExamples = []msgex{
|
||||
{11, "Promotions", "", PX, AKEY, "Join Our VIP Club and Enjoy Exclusive Benefits", "Sign up for our VIP club and enjoy exclusive benefits like early access to sales, special offers, and personalized service. Don't miss out on this exclusive opportunity.", timeext.FromHours(2.32)},
|
||||
{11, "Promotions", "", P2, SKEY, "Summer Clearance: Save Up to 75% on Your Favorite Products", "It's time for our annual summer clearance sale! Save up to 75% on your favorite products, from clothing and accessories to home decor and more.", timeext.FromHours(1.87)},
|
||||
|
||||
{12, "", "", P0, SKEY, "New Product Launch", "We are excited to announce the launch of our new product, the XYZ widget", 0},
|
||||
{12, "chan_self_subscribed", "", P0, SKEY, "Important Update", "We have released a critical update", 0},
|
||||
{12, "chan_self_unsub", "", P0, SKEY, "Reminder: Upcoming Maintenance", "", 0},
|
||||
{14, "", "", P0, SKEY, "New Product Launch", "We are excited to announce the launch of our new product, the XYZ widget", 0},
|
||||
{14, "chan_self_subscribed", "", P0, SKEY, "Important Update", "We have released a critical update", 0},
|
||||
{14, "chan_self_unsub", "", P0, SKEY, "Reminder: Upcoming Maintenance", "", 0},
|
||||
|
||||
{13, "", "", P0, SKEY, "New Feature Available", "ability to schedule appointments", 0},
|
||||
{13, "chan_other_nosub", "", P0, SKEY, "Account Suspended", "Please contact us", 0},
|
||||
{13, "chan_other_request", "", P0, SKEY, "Invitation to Beta Test", "", 0},
|
||||
{13, "chan_other_accepted", "", P0, SKEY, "New Blog Post", "Congratulations on your promotion! We are proud", 0},
|
||||
{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},
|
||||
}
|
||||
|
||||
type DefData struct {
|
||||
@@ -373,6 +375,12 @@ func InitDefaultData(t *testing.T, ws *logic.Application) DefData {
|
||||
RequestPost[gin.H](t, baseUrl, "/", body)
|
||||
}
|
||||
|
||||
// create manual channels
|
||||
|
||||
{
|
||||
RequestAuthPost[Void](t, users[9].AdminKey, baseUrl, fmt.Sprintf("/api/users/%d/channels", users[9].UID), gin.H{"name": "manual@chan"})
|
||||
}
|
||||
|
||||
// Sub/Unsub for Users 12+13
|
||||
|
||||
{
|
||||
|
@@ -163,10 +163,10 @@ func RequestAny[TResult any](t *testing.T, akey string, method string, baseURL s
|
||||
return data
|
||||
}
|
||||
|
||||
func RequestAuthAnyShouldFail(t *testing.T, akey string, method string, baseURL string, urlSuffix string, body any, statusCode int, errcode apierr.APIError) {
|
||||
func RequestAuthAnyShouldFail(t *testing.T, akey string, method string, baseURL string, urlSuffix string, body any, expectedStatusCode int, errcode apierr.APIError) {
|
||||
client := http.Client{}
|
||||
|
||||
TPrintf("[-> REQUEST] (%s) %s%s [%s] (should-fail with %d/%d)\n", method, baseURL, urlSuffix, langext.Conditional(akey == "", "NO AUTH", "AUTH"), statusCode, errcode)
|
||||
TPrintf("[-> REQUEST] (%s) %s%s [%s] (should-fail with %d/%d)\n", method, baseURL, urlSuffix, langext.Conditional(akey == "", "NO AUTH", "AUTH"), expectedStatusCode, errcode)
|
||||
|
||||
bytesbody := make([]byte, 0)
|
||||
contentType := ""
|
||||
@@ -224,17 +224,17 @@ func RequestAuthAnyShouldFail(t *testing.T, akey string, method string, baseURL
|
||||
TPrintln("")
|
||||
TPrintf("---------------- RESPONSE (%d) ----------------\n", resp.StatusCode)
|
||||
TPrintln(langext.TryPrettyPrintJson(string(respBodyBin)))
|
||||
if (statusCode != 0 && resp.StatusCode != statusCode) || (statusCode == 0 && resp.StatusCode == 200) {
|
||||
if (expectedStatusCode != 0 && resp.StatusCode != expectedStatusCode) || (expectedStatusCode == 0 && resp.StatusCode == 200) {
|
||||
TryPrintTraceObj("---------------- -------- ----------------", respBodyBin, "")
|
||||
}
|
||||
TPrintln("---------------- -------- ----------------")
|
||||
TPrintln("")
|
||||
|
||||
if statusCode != 0 && resp.StatusCode != statusCode {
|
||||
TestFailFmt(t, "Statuscode != %d (expected failure)", statusCode)
|
||||
if expectedStatusCode != 0 && resp.StatusCode != expectedStatusCode {
|
||||
TestFailFmt(t, "Statuscode != %d (expected failure, but got %d)", expectedStatusCode, resp.StatusCode)
|
||||
}
|
||||
if statusCode == 0 && resp.StatusCode == 200 {
|
||||
TestFailFmt(t, "Statuscode == %d (expected failure)", resp.StatusCode)
|
||||
if expectedStatusCode == 0 && resp.StatusCode == 200 {
|
||||
TestFailFmt(t, "Statuscode == %d (expected any failure, but got %d)", resp.StatusCode, resp.StatusCode)
|
||||
}
|
||||
|
||||
var data gin.H
|
||||
|
Reference in New Issue
Block a user