Tests[TestSendCompatMessageByQuery, TestSendCompatMessageByFormData]
This commit is contained in:
parent
590665a5e9
commit
3d602af135
@ -1092,12 +1092,12 @@ func (h APIHandler) ListChannelSubscriptions(g *gin.Context) ginresp.HTTPRespons
|
|||||||
return ginresp.APIError(g, 404, apierr.CHANNEL_NOT_FOUND, "Channel not found", err)
|
return ginresp.APIError(g, 404, apierr.CHANNEL_NOT_FOUND, "Channel not found", err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query channels", err)
|
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query channel", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
clients, err := h.database.ListSubscriptionsByChannel(ctx, u.ChannelID)
|
clients, err := h.database.ListSubscriptionsByChannel(ctx, u.ChannelID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query channels", err)
|
return ginresp.APIError(g, 500, apierr.DATABASE_ERROR, "Failed to query subscriptions", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
res := langext.ArrMap(clients, func(v models.Subscription) models.SubscriptionJSON { return v.JSON() })
|
res := langext.ArrMap(clients, func(v models.Subscription) models.SubscriptionJSON { return v.JSON() })
|
||||||
|
@ -148,7 +148,7 @@ func (pp *DBPreprocessor) PreQuery(ctx context.Context, txID *uint16, sql *strin
|
|||||||
|
|
||||||
aliasMap := make(map[string]string)
|
aliasMap := make(map[string]string)
|
||||||
for _, v := range regexAlias.MatchAll(sqlOriginal) {
|
for _, v := range regexAlias.MatchAll(sqlOriginal) {
|
||||||
aliasMap[strings.TrimSpace(v.GroupByIndex(1).Value())] = strings.TrimSpace(v.GroupByIndex(2).Value())
|
aliasMap[strings.TrimSpace(v.GroupByIndex(2).Value())] = strings.TrimSpace(v.GroupByIndex(1).Value())
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, expr := range split {
|
for _, expr := range split {
|
||||||
|
@ -1,12 +1,198 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"blackforestbytes.com/simplecloudnotifier/push"
|
||||||
tt "blackforestbytes.com/simplecloudnotifier/test/util"
|
tt "blackforestbytes.com/simplecloudnotifier/test/util"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestSendCompatWithOldUser(t *testing.T) {
|
||||||
|
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
pusher := ws.Pusher.(*push.TestSink)
|
||||||
|
|
||||||
|
r0 := tt.RequestGet[gin.H](t, baseUrl, "/api/register.php?fcm_token=DUMMY_FCM&pro=0&pro_token=")
|
||||||
|
|
||||||
|
uidold := int64(r0["user_id"].(float64))
|
||||||
|
admintok := r0["user_key"].(string)
|
||||||
|
|
||||||
|
msg1 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_key": admintok,
|
||||||
|
"user_id": fmt.Sprintf("%d", uidold),
|
||||||
|
"title": "HelloWorld_001",
|
||||||
|
})
|
||||||
|
|
||||||
|
// does not allow json - only form & query
|
||||||
|
tt.RequestPostShouldFail(t, baseUrl, "/send.php", gin.H{
|
||||||
|
"user_key": admintok,
|
||||||
|
"user_id": uidold,
|
||||||
|
"title": "HelloWorld_001",
|
||||||
|
}, 400, 0)
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "messageCount", 1, len(pusher.Data))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", pusher.Last().Message.Title)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
||||||
|
|
||||||
|
exp1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", uidold, admintok, int64(msg1["scn_msg_id"].(float64))))
|
||||||
|
tt.AssertEqual(t, "success", true, exp1["success"])
|
||||||
|
|
||||||
|
type mglist struct {
|
||||||
|
Messages []gin.H `json:"messages"`
|
||||||
|
}
|
||||||
|
|
||||||
|
msgList1 := tt.RequestAuthGet[mglist](t, admintok, baseUrl, "/api/messages")
|
||||||
|
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
||||||
|
|
||||||
|
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", pusher.Last().Message.MessageID))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", msg1Get["title"])
|
||||||
|
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", admintok, uidold, "HelloWorld_002"), nil)
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "messageCount", 2, len(pusher.Data))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_002", pusher.Last().Message.Title)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
||||||
|
|
||||||
|
exp2 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", uidold, admintok, int64(msg2["scn_msg_id"].(float64))))
|
||||||
|
tt.AssertEqual(t, "success", true, exp2["success"])
|
||||||
|
|
||||||
|
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", pusher.Last().Message.MessageID))
|
||||||
|
|
||||||
|
content3 := "039c1817-76ee-44ab-972a-4cec0a15a791\n" +
|
||||||
|
"046f59ea-9a49-4060-93e6-8a4e14134faf\n" +
|
||||||
|
"ab566fbe-9020-41b6-afa6-94f3d8d7c7b4\n" +
|
||||||
|
"d52e5f7d-26a8-45b9-befc-da44a3f112da\n" +
|
||||||
|
"d19fae55-d52a-4753-b9f1-66a935d68b1e\n" +
|
||||||
|
"99a4099d-44d5-497a-a69b-18e277400d6e\n" +
|
||||||
|
"a55757aa-afaa-420e-afaf-f3951e9e2434\n" +
|
||||||
|
"ee58f5fc-b384-49f4-bc2c-c5b3c7bd54b7\n" +
|
||||||
|
"5a7008d9-dd15-406a-83d1-fd6209c56141\n"
|
||||||
|
ts3 := time.Now().Unix() - int64(time.Hour.Seconds())
|
||||||
|
|
||||||
|
msg3 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_key": admintok,
|
||||||
|
"user_id": fmt.Sprintf("%d", uidold),
|
||||||
|
"title": "HelloWorld_003",
|
||||||
|
"content": content3,
|
||||||
|
"priority": "2",
|
||||||
|
"msg_id": "8a2c7e92-86f3-4d69-897a-571286954030",
|
||||||
|
"timestamp": fmt.Sprintf("%d", ts3),
|
||||||
|
})
|
||||||
|
|
||||||
|
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", pusher.Last().Message.MessageID))
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "messageCount", 3, len(pusher.Data))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.Title", "HelloWorld_003", pusher.Last().Message.Title)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.Content", content3, pusher.Last().Message.Content)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.Priority", 2, pusher.Last().Message.Priority)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.UserMessageID", "8a2c7e92-86f3-4d69-897a-571286954030", pusher.Last().Message.UserMessageID)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.UserMessageID", ts3, pusher.Last().Message.Timestamp().Unix())
|
||||||
|
|
||||||
|
exp3 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", uidold, admintok, int64(msg3["scn_msg_id"].(float64))))
|
||||||
|
tt.AssertEqual(t, "success", true, exp3["success"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSendCompatWithNewUser(t *testing.T) {
|
||||||
|
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
pusher := ws.Pusher.(*push.TestSink)
|
||||||
|
|
||||||
|
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 := r0["user_id"].(string)
|
||||||
|
admintok := r0["admin_key"].(string)
|
||||||
|
readtok := r0["read_key"].(string)
|
||||||
|
sendtok := r0["send_key"].(string)
|
||||||
|
|
||||||
|
uidold := tt.CreateCompatID(t, ws, "userid", uid)
|
||||||
|
|
||||||
|
msg1 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_key": sendtok,
|
||||||
|
"user_id": fmt.Sprintf("%d", uidold),
|
||||||
|
"title": "HelloWorld_001",
|
||||||
|
})
|
||||||
|
|
||||||
|
// does not allow json - only form & query
|
||||||
|
tt.RequestPostShouldFail(t, baseUrl, "/send.php", gin.H{
|
||||||
|
"user_key": readtok,
|
||||||
|
"user_id": uidold,
|
||||||
|
"title": "HelloWorld_001",
|
||||||
|
}, 400, 0)
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "messageCount", 1, len(pusher.Data))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", pusher.Last().Message.Title)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
||||||
|
|
||||||
|
exp1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", uidold, admintok, int64(msg1["scn_msg_id"].(float64))))
|
||||||
|
tt.AssertEqual(t, "success", true, exp1["success"])
|
||||||
|
|
||||||
|
type mglist struct {
|
||||||
|
Messages []gin.H `json:"messages"`
|
||||||
|
}
|
||||||
|
|
||||||
|
msgList1 := tt.RequestAuthGet[mglist](t, admintok, baseUrl, "/api/messages")
|
||||||
|
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
||||||
|
|
||||||
|
msg1Get := tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", pusher.Last().Message.MessageID))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", msg1Get["title"])
|
||||||
|
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, uidold, "HelloWorld_002"), nil)
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "messageCount", 2, len(pusher.Data))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_002", pusher.Last().Message.Title)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
||||||
|
|
||||||
|
exp2 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", uidold, admintok, int64(msg2["scn_msg_id"].(float64))))
|
||||||
|
tt.AssertEqual(t, "success", true, exp2["success"])
|
||||||
|
|
||||||
|
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", pusher.Last().Message.MessageID))
|
||||||
|
|
||||||
|
content3 := "039c1817-76ee-44ab-972a-4cec0a15a791\n" +
|
||||||
|
"046f59ea-9a49-4060-93e6-8a4e14134faf\n" +
|
||||||
|
"ab566fbe-9020-41b6-afa6-94f3d8d7c7b4\n" +
|
||||||
|
"d52e5f7d-26a8-45b9-befc-da44a3f112da\n" +
|
||||||
|
"d19fae55-d52a-4753-b9f1-66a935d68b1e\n" +
|
||||||
|
"99a4099d-44d5-497a-a69b-18e277400d6e\n" +
|
||||||
|
"a55757aa-afaa-420e-afaf-f3951e9e2434\n" +
|
||||||
|
"ee58f5fc-b384-49f4-bc2c-c5b3c7bd54b7\n" +
|
||||||
|
"5a7008d9-dd15-406a-83d1-fd6209c56141\n"
|
||||||
|
ts3 := time.Now().Unix() - int64(time.Hour.Seconds())
|
||||||
|
|
||||||
|
msg3 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_key": sendtok,
|
||||||
|
"user_id": fmt.Sprintf("%d", uidold),
|
||||||
|
"title": "HelloWorld_003",
|
||||||
|
"content": content3,
|
||||||
|
"priority": "2",
|
||||||
|
"msg_id": "8a2c7e92-86f3-4d69-897a-571286954030",
|
||||||
|
"timestamp": fmt.Sprintf("%d", ts3),
|
||||||
|
})
|
||||||
|
|
||||||
|
exp3 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", uidold, admintok, int64(msg3["scn_msg_id"].(float64))))
|
||||||
|
tt.AssertEqual(t, "success", true, exp3["success"])
|
||||||
|
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", pusher.Last().Message.MessageID))
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "messageCount", 3, len(pusher.Data))
|
||||||
|
tt.AssertStrRepEqual(t, "msg.Title", "HelloWorld_003", pusher.Last().Message.Title)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.Content", content3, pusher.Last().Message.Content)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.Priority", 2, pusher.Last().Message.Priority)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.UserMessageID", "8a2c7e92-86f3-4d69-897a-571286954030", pusher.Last().Message.UserMessageID)
|
||||||
|
tt.AssertStrRepEqual(t, "msg.UserMessageID", ts3, pusher.Last().Message.Timestamp().Unix())
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateCompatUser(t *testing.T) {
|
func TestCreateCompatUser(t *testing.T) {
|
||||||
_, baseUrl, stop := tt.StartSimpleWebserver(t)
|
_, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||||
defer stop()
|
defer stop()
|
||||||
@ -23,6 +209,115 @@ func TestCreateCompatUser(t *testing.T) {
|
|||||||
tt.AssertEqual(t, "success", true, r1["success"])
|
tt.AssertEqual(t, "success", true, r1["success"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSendCompatMessageByQuery(t *testing.T) {
|
||||||
|
_, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
r0 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "0", ""))
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "success", true, r0["success"])
|
||||||
|
|
||||||
|
userid := int64(r0["user_id"].(float64))
|
||||||
|
userkey := r0["user_key"].(string)
|
||||||
|
|
||||||
|
r1 := tt.RequestPost[gin.H](t, baseUrl, fmt.Sprintf("/send.php?user_id=%d&user_key=%s&title=%s",
|
||||||
|
userid,
|
||||||
|
userkey,
|
||||||
|
url.QueryEscape("my title 11 & x")), nil)
|
||||||
|
tt.AssertEqual(t, "success", true, r1["success"])
|
||||||
|
tt.AssertEqual(t, "suppress_send", false, r1["suppress_send"])
|
||||||
|
|
||||||
|
r1scnid := int64(r1["scn_msg_id"].(float64))
|
||||||
|
|
||||||
|
r1x := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r1scnid))
|
||||||
|
tt.AssertEqual(t, "success", true, r1x["success"])
|
||||||
|
tt.AssertEqual(t, "success", "my title 11 & x", (r1x["data"].(map[string]any))["title"])
|
||||||
|
|
||||||
|
r2 := tt.RequestPost[gin.H](t, baseUrl, fmt.Sprintf("/send.php?user_id=%d&user_key=%s&title=%s&content=%s&priority=%s&msg_id=%s×tamp=%s",
|
||||||
|
userid,
|
||||||
|
userkey,
|
||||||
|
url.QueryEscape("my title"),
|
||||||
|
url.QueryEscape("message content"),
|
||||||
|
url.QueryEscape("2"),
|
||||||
|
url.QueryEscape("624dbe5e-6d03-47cd-9a0e-a306faa2e977"),
|
||||||
|
url.QueryEscape("1673894797")), nil)
|
||||||
|
tt.AssertEqual(t, "success", true, r2["success"])
|
||||||
|
tt.AssertEqual(t, "suppress_send", false, r2["suppress_send"])
|
||||||
|
|
||||||
|
r2scnid := int64(r2["scn_msg_id"].(float64))
|
||||||
|
|
||||||
|
r2x := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r2scnid))
|
||||||
|
tt.AssertEqual(t, "success", true, r2x["success"])
|
||||||
|
tt.AssertEqual(t, "success", "my title", (r2x["data"].(map[string]any))["title"])
|
||||||
|
|
||||||
|
r3 := tt.RequestPost[gin.H](t, baseUrl, fmt.Sprintf("/send.php?user_id=%d&user_key=%s&title=%s&content=%s&priority=%s&msg_id=%s×tamp=%s",
|
||||||
|
userid,
|
||||||
|
userkey,
|
||||||
|
url.QueryEscape("my title"),
|
||||||
|
url.QueryEscape("message content"),
|
||||||
|
url.QueryEscape("2"),
|
||||||
|
url.QueryEscape("624dbe5e-6d03-47cd-9a0e-a306faa2e977"),
|
||||||
|
url.QueryEscape("1673894797")), nil)
|
||||||
|
tt.AssertEqual(t, "success", true, r3["success"])
|
||||||
|
tt.AssertEqual(t, "suppress_send", true, r3["suppress_send"])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSendCompatMessageByFormData(t *testing.T) {
|
||||||
|
_, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||||
|
defer stop()
|
||||||
|
|
||||||
|
r0 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "0", ""))
|
||||||
|
|
||||||
|
tt.AssertEqual(t, "success", true, r0["success"])
|
||||||
|
|
||||||
|
userid := int64(r0["user_id"].(float64))
|
||||||
|
userkey := r0["user_key"].(string)
|
||||||
|
|
||||||
|
r1 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_id": fmt.Sprintf("%d", userid),
|
||||||
|
"user_key": userkey,
|
||||||
|
"title": "my title 11 & x",
|
||||||
|
})
|
||||||
|
tt.AssertEqual(t, "success", true, r1["success"])
|
||||||
|
tt.AssertEqual(t, "suppress_send", false, r1["suppress_send"])
|
||||||
|
|
||||||
|
r1scnid := int64(r1["scn_msg_id"].(float64))
|
||||||
|
|
||||||
|
r1x := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r1scnid))
|
||||||
|
tt.AssertEqual(t, "success", true, r1x["success"])
|
||||||
|
tt.AssertEqual(t, "success", "my title 11 & x", (r1x["data"].(map[string]any))["title"])
|
||||||
|
|
||||||
|
r2 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_id": fmt.Sprintf("%d", userid),
|
||||||
|
"user_key": userkey,
|
||||||
|
"title": "my title",
|
||||||
|
"content": "message content",
|
||||||
|
"priority": "2",
|
||||||
|
"msg_id": "624dbe5e-6d03-47cd-9a0e-a306faa2e977",
|
||||||
|
"timestamp": "1673894797",
|
||||||
|
})
|
||||||
|
tt.AssertEqual(t, "success", true, r2["success"])
|
||||||
|
tt.AssertEqual(t, "suppress_send", false, r2["suppress_send"])
|
||||||
|
|
||||||
|
r2scnid := int64(r2["scn_msg_id"].(float64))
|
||||||
|
|
||||||
|
r2x := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/expand.php?user_id=%d&user_key=%s&scn_msg_id=%d", userid, userkey, r2scnid))
|
||||||
|
tt.AssertEqual(t, "success", true, r2x["success"])
|
||||||
|
tt.AssertEqual(t, "success", "my title", (r2x["data"].(map[string]any))["title"])
|
||||||
|
|
||||||
|
r3 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
||||||
|
"user_id": fmt.Sprintf("%d", userid),
|
||||||
|
"user_key": userkey,
|
||||||
|
"title": "my title",
|
||||||
|
"content": "message content",
|
||||||
|
"priority": "2",
|
||||||
|
"msg_id": "624dbe5e-6d03-47cd-9a0e-a306faa2e977",
|
||||||
|
"timestamp": "1673894797",
|
||||||
|
})
|
||||||
|
tt.AssertEqual(t, "success", true, r3["success"])
|
||||||
|
tt.AssertEqual(t, "suppress_send", true, r3["suppress_send"])
|
||||||
|
}
|
||||||
|
|
||||||
//TODO test compat methods
|
//TODO test compat methods
|
||||||
|
|
||||||
//TODO also test compat_id mapping
|
//TODO also test compat_id mapping
|
||||||
|
@ -978,179 +978,6 @@ func TestSendInvalidTimestamp(t *testing.T) {
|
|||||||
tt.AssertEqual(t, "messageCount", 0, len(pusher.Data))
|
tt.AssertEqual(t, "messageCount", 0, len(pusher.Data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSendCompatWithOldUser(t *testing.T) {
|
|
||||||
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
|
||||||
defer stop()
|
|
||||||
|
|
||||||
pusher := ws.Pusher.(*push.TestSink)
|
|
||||||
|
|
||||||
r0 := tt.RequestGet[gin.H](t, baseUrl, "/api/register.php?fcm_token=DUMMY_FCM&pro=0&pro_token=")
|
|
||||||
|
|
||||||
uidold := int64(r0["user_id"].(float64))
|
|
||||||
admintok := r0["user_key"].(string)
|
|
||||||
|
|
||||||
msg1 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
|
||||||
"user_key": admintok,
|
|
||||||
"user_id": fmt.Sprintf("%d", uidold),
|
|
||||||
"title": "HelloWorld_001",
|
|
||||||
})
|
|
||||||
|
|
||||||
// does not allow json - only form & query
|
|
||||||
tt.RequestPostShouldFail(t, baseUrl, "/send.php", gin.H{
|
|
||||||
"user_key": admintok,
|
|
||||||
"user_id": uidold,
|
|
||||||
"title": "HelloWorld_001",
|
|
||||||
}, 400, 0)
|
|
||||||
|
|
||||||
tt.AssertEqual(t, "messageCount", 1, len(pusher.Data))
|
|
||||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", pusher.Last().Message.Title)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.scn_msg_id", msg1["scn_msg_id"], pusher.Last().Message.MessageID)
|
|
||||||
|
|
||||||
type mglist struct {
|
|
||||||
Messages []gin.H `json:"messages"`
|
|
||||||
}
|
|
||||||
|
|
||||||
msgList1 := tt.RequestAuthGet[mglist](t, admintok, baseUrl, "/api/messages")
|
|
||||||
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
|
||||||
|
|
||||||
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_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", admintok, uidold, "HelloWorld_002"), nil)
|
|
||||||
|
|
||||||
tt.AssertEqual(t, "messageCount", 2, len(pusher.Data))
|
|
||||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_002", pusher.Last().Message.Title)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.scn_msg_id", msg2["scn_msg_id"], pusher.Last().Message.MessageID)
|
|
||||||
|
|
||||||
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg2["scn_msg_id"]))
|
|
||||||
|
|
||||||
content3 := "039c1817-76ee-44ab-972a-4cec0a15a791\n" +
|
|
||||||
"046f59ea-9a49-4060-93e6-8a4e14134faf\n" +
|
|
||||||
"ab566fbe-9020-41b6-afa6-94f3d8d7c7b4\n" +
|
|
||||||
"d52e5f7d-26a8-45b9-befc-da44a3f112da\n" +
|
|
||||||
"d19fae55-d52a-4753-b9f1-66a935d68b1e\n" +
|
|
||||||
"99a4099d-44d5-497a-a69b-18e277400d6e\n" +
|
|
||||||
"a55757aa-afaa-420e-afaf-f3951e9e2434\n" +
|
|
||||||
"ee58f5fc-b384-49f4-bc2c-c5b3c7bd54b7\n" +
|
|
||||||
"5a7008d9-dd15-406a-83d1-fd6209c56141\n"
|
|
||||||
ts3 := time.Now().Unix() - int64(time.Hour.Seconds())
|
|
||||||
|
|
||||||
msg3 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
|
||||||
"user_key": admintok,
|
|
||||||
"user_id": fmt.Sprintf("%d", uidold),
|
|
||||||
"title": "HelloWorld_003",
|
|
||||||
"content": content3,
|
|
||||||
"priority": "2",
|
|
||||||
"msg_id": "8a2c7e92-86f3-4d69-897a-571286954030",
|
|
||||||
"timestamp": fmt.Sprintf("%d", ts3),
|
|
||||||
})
|
|
||||||
|
|
||||||
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg3["scn_msg_id"]))
|
|
||||||
|
|
||||||
tt.AssertEqual(t, "messageCount", 3, len(pusher.Data))
|
|
||||||
tt.AssertStrRepEqual(t, "msg.Title", "HelloWorld_003", pusher.Last().Message.Title)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.Content", content3, pusher.Last().Message.Content)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.MessageID", msg3["scn_msg_id"], pusher.Last().Message.MessageID)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.Priority", 2, pusher.Last().Message.Priority)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.UserMessageID", "8a2c7e92-86f3-4d69-897a-571286954030", pusher.Last().Message.UserMessageID)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.UserMessageID", ts3, pusher.Last().Message.Timestamp().Unix())
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSendCompatWithNewUser(t *testing.T) {
|
|
||||||
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
|
||||||
defer stop()
|
|
||||||
|
|
||||||
pusher := ws.Pusher.(*push.TestSink)
|
|
||||||
|
|
||||||
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 := r0["user_id"].(string)
|
|
||||||
admintok := r0["admin_key"].(string)
|
|
||||||
readtok := r0["read_key"].(string)
|
|
||||||
sendtok := r0["send_key"].(string)
|
|
||||||
|
|
||||||
uidold := tt.CreateCompatID(t, ws, "userid", uid)
|
|
||||||
|
|
||||||
msg1 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
|
||||||
"user_key": sendtok,
|
|
||||||
"user_id": fmt.Sprintf("%d", uidold),
|
|
||||||
"title": "HelloWorld_001",
|
|
||||||
})
|
|
||||||
|
|
||||||
// does not allow json - only form & query
|
|
||||||
tt.RequestPostShouldFail(t, baseUrl, "/send.php", gin.H{
|
|
||||||
"user_key": readtok,
|
|
||||||
"user_id": uidold,
|
|
||||||
"title": "HelloWorld_001",
|
|
||||||
}, 400, 0)
|
|
||||||
|
|
||||||
tt.AssertEqual(t, "messageCount", 1, len(pusher.Data))
|
|
||||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_001", pusher.Last().Message.Title)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.scn_msg_id", msg1["scn_msg_id"], pusher.Last().Message.MessageID)
|
|
||||||
|
|
||||||
type mglist struct {
|
|
||||||
Messages []gin.H `json:"messages"`
|
|
||||||
}
|
|
||||||
|
|
||||||
msgList1 := tt.RequestAuthGet[mglist](t, admintok, baseUrl, "/api/messages")
|
|
||||||
tt.AssertEqual(t, "len(messages)", 1, len(msgList1.Messages))
|
|
||||||
|
|
||||||
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_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, uidold, "HelloWorld_002"), nil)
|
|
||||||
|
|
||||||
tt.AssertEqual(t, "messageCount", 2, len(pusher.Data))
|
|
||||||
tt.AssertStrRepEqual(t, "msg.title", "HelloWorld_002", pusher.Last().Message.Title)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.content", nil, pusher.Last().Message.Content)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.scn_msg_id", msg2["scn_msg_id"], pusher.Last().Message.MessageID)
|
|
||||||
|
|
||||||
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg2["scn_msg_id"]))
|
|
||||||
|
|
||||||
content3 := "039c1817-76ee-44ab-972a-4cec0a15a791\n" +
|
|
||||||
"046f59ea-9a49-4060-93e6-8a4e14134faf\n" +
|
|
||||||
"ab566fbe-9020-41b6-afa6-94f3d8d7c7b4\n" +
|
|
||||||
"d52e5f7d-26a8-45b9-befc-da44a3f112da\n" +
|
|
||||||
"d19fae55-d52a-4753-b9f1-66a935d68b1e\n" +
|
|
||||||
"99a4099d-44d5-497a-a69b-18e277400d6e\n" +
|
|
||||||
"a55757aa-afaa-420e-afaf-f3951e9e2434\n" +
|
|
||||||
"ee58f5fc-b384-49f4-bc2c-c5b3c7bd54b7\n" +
|
|
||||||
"5a7008d9-dd15-406a-83d1-fd6209c56141\n"
|
|
||||||
ts3 := time.Now().Unix() - int64(time.Hour.Seconds())
|
|
||||||
|
|
||||||
msg3 := tt.RequestPost[gin.H](t, baseUrl, "/send.php", tt.FormData{
|
|
||||||
"user_key": sendtok,
|
|
||||||
"user_id": fmt.Sprintf("%d", uidold),
|
|
||||||
"title": "HelloWorld_003",
|
|
||||||
"content": content3,
|
|
||||||
"priority": "2",
|
|
||||||
"msg_id": "8a2c7e92-86f3-4d69-897a-571286954030",
|
|
||||||
"timestamp": fmt.Sprintf("%d", ts3),
|
|
||||||
})
|
|
||||||
|
|
||||||
tt.RequestAuthGet[gin.H](t, admintok, baseUrl, "/api/messages/"+fmt.Sprintf("%v", msg3["scn_msg_id"]))
|
|
||||||
|
|
||||||
tt.AssertEqual(t, "messageCount", 3, len(pusher.Data))
|
|
||||||
tt.AssertStrRepEqual(t, "msg.Title", "HelloWorld_003", pusher.Last().Message.Title)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.Content", content3, pusher.Last().Message.Content)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.MessageID", msg3["scn_msg_id"], pusher.Last().Message.MessageID)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.Priority", 2, pusher.Last().Message.Priority)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.UserMessageID", "8a2c7e92-86f3-4d69-897a-571286954030", pusher.Last().Message.UserMessageID)
|
|
||||||
tt.AssertStrRepEqual(t, "msg.UserMessageID", ts3, pusher.Last().Message.Timestamp().Unix())
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSendToNewChannel(t *testing.T) {
|
func TestSendToNewChannel(t *testing.T) {
|
||||||
_, baseUrl, stop := tt.StartSimpleWebserver(t)
|
_, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||||
defer stop()
|
defer stop()
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
"messagecount": 634,
|
"messagecount": 634,
|
||||||
"quota":17,
|
"quota":17,
|
||||||
"quota_max":100,
|
"quota_max":100,
|
||||||
"scn_msg_id":993625
|
"scn_msg_id":"..."
|
||||||
}</pre>
|
}</pre>
|
||||||
<p>
|
<p>
|
||||||
If the operation is <b>not</b> successful the API will respond with a 4xx or 500 HTTP statuscode.
|
If the operation is <b>not</b> successful the API will respond with a 4xx or 500 HTTP statuscode.
|
||||||
|
Loading…
Reference in New Issue
Block a user