Refactor models to use single struct per entity
This commit is contained in:
@@ -131,7 +131,7 @@ func TestTokenKeys(t *testing.T) {
|
||||
|
||||
msg1 := tt.RequestAuthGet[gin.H](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/messages/%s", msg1s["scn_msg_id"]))
|
||||
|
||||
tt.AssertEqual(t, "AllChannels", key7.KeytokenId, msg1["used_key_id"])
|
||||
tt.AssertEqual(t, "used_key_id", key7.KeytokenId, msg1["used_key_id"])
|
||||
|
||||
tt.RequestPostShouldFail(t, baseUrl, "/", gin.H{
|
||||
"key": key7.Token,
|
||||
|
@@ -113,6 +113,59 @@ func TestResponseKeyToken2(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestResponseKeyToken3(t *testing.T) {
|
||||
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||
defer stop()
|
||||
|
||||
data := tt.InitSingleData(t, ws)
|
||||
|
||||
response := tt.RequestAuthGetRaw(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys/current", data.UID))
|
||||
|
||||
tt.AssertJsonStructureMatch(t, "json[key]", response, map[string]any{
|
||||
"keytoken_id": "id",
|
||||
"name": "string",
|
||||
"timestamp_created": "rfc3339",
|
||||
"timestamp_lastused": "rfc3339|null",
|
||||
"owner_user_id": "id",
|
||||
"all_channels": "bool",
|
||||
"channels": []any{"string"},
|
||||
"permissions": "string",
|
||||
"messages_sent": "int",
|
||||
"token": "string",
|
||||
})
|
||||
}
|
||||
|
||||
func TestResponseKeyToken4(t *testing.T) {
|
||||
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||
defer stop()
|
||||
|
||||
data := tt.InitSingleData(t, ws)
|
||||
|
||||
chan1 := tt.RequestAuthPost[gin.H](t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/channels", data.UID), gin.H{
|
||||
"name": "TestChan1asdf",
|
||||
})
|
||||
|
||||
response := tt.RequestAuthPostRaw(t, data.AdminKey, baseUrl, fmt.Sprintf("/api/v2/users/%s/keys", data.UID), gin.H{
|
||||
"all_channels": false,
|
||||
"channels": []string{chan1["channel_id"].(string)},
|
||||
"name": "TKey1",
|
||||
"permissions": "CS",
|
||||
})
|
||||
|
||||
tt.AssertJsonStructureMatch(t, "json[key]", response, map[string]any{
|
||||
"keytoken_id": "id",
|
||||
"name": "string",
|
||||
"timestamp_created": "rfc3339",
|
||||
"timestamp_lastused": "rfc3339|null",
|
||||
"owner_user_id": "id",
|
||||
"all_channels": "bool",
|
||||
"channels": []any{"string"},
|
||||
"permissions": "string",
|
||||
"messages_sent": "int",
|
||||
"token": "string",
|
||||
})
|
||||
}
|
||||
|
||||
func TestResponseMessage(t *testing.T) {
|
||||
ws, baseUrl, stop := tt.StartSimpleWebserver(t)
|
||||
defer stop()
|
||||
|
@@ -836,7 +836,7 @@ func TestSendWithTimestamp(t *testing.T) {
|
||||
|
||||
tt.AssertEqual(t, "messageCount", 1, len(pusher.Data))
|
||||
tt.AssertStrRepEqual(t, "msg.title", "TTT", pusher.Last().Message.Title)
|
||||
tt.AssertStrRepEqual(t, "msg.TimestampClient", ts, pusher.Last().Message.TimestampClient.Unix())
|
||||
tt.AssertStrRepEqual(t, "msg.TimestampClient", ts, pusher.Last().Message.TimestampClient.Time().Unix())
|
||||
tt.AssertStrRepEqual(t, "msg.Timestamp", ts, pusher.Last().Message.Timestamp().Unix())
|
||||
tt.AssertNotStrRepEqual(t, "msg.ts", pusher.Last().Message.TimestampClient, pusher.Last().Message.TimestampReal)
|
||||
tt.AssertStrRepEqual(t, "msg.scn_msg_id", msg1["scn_msg_id"], pusher.Last().Message.MessageID)
|
||||
|
@@ -34,6 +34,10 @@ func RequestPost[TResult any](t *testing.T, baseURL string, urlSuffix string, bo
|
||||
return RequestAny[TResult](t, "", "POST", baseURL, urlSuffix, body, true)
|
||||
}
|
||||
|
||||
func RequestAuthPostRaw(t *testing.T, akey string, baseURL string, urlSuffix string, body any) string {
|
||||
return RequestAny[string](t, akey, "POST", baseURL, urlSuffix, body, false)
|
||||
}
|
||||
|
||||
func RequestAuthPost[TResult any](t *testing.T, akey string, baseURL string, urlSuffix string, body any) TResult {
|
||||
return RequestAny[TResult](t, akey, "POST", baseURL, urlSuffix, body, true)
|
||||
}
|
||||
|
@@ -135,13 +135,13 @@ func assertjsonStructureMatchMapObject(t *testing.T, mapschema map[string]any, r
|
||||
|
||||
for k := range mapschema {
|
||||
if _, ok := realValue[k]; !ok {
|
||||
t.Errorf("Missing Key: < %s >", keyPath)
|
||||
t.Errorf("Missing Key: < %s >", keyPath+"."+k)
|
||||
}
|
||||
}
|
||||
|
||||
for k := range realValue {
|
||||
if _, ok := mapschema[k]; !ok {
|
||||
t.Errorf("Additional key: < %s >", keyPath)
|
||||
t.Errorf("Additional key: < %s >", keyPath+"."+k)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user