Tests[CompatUpgrade]

This commit is contained in:
Mike Schwörer 2023-01-17 22:32:13 +01:00
parent 23c7729fcf
commit ec9a326002
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 24 additions and 7 deletions

View File

@ -171,7 +171,7 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
UserKey string `json:"user_key"` UserKey string `json:"user_key"`
QuotaUsed int `json:"quota"` QuotaUsed int `json:"quota"`
QuotaMax int `json:"quota_max"` QuotaMax int `json:"quota_max"`
IsPro int `json:"is_pro"` IsPro bool `json:"is_pro"`
} }
var datq query var datq query
@ -251,7 +251,7 @@ func (h CompatHandler) Register(g *gin.Context) ginresp.HTTPResponse {
UserKey: user.AdminKey, UserKey: user.AdminKey,
QuotaUsed: user.QuotaUsedToday(), QuotaUsed: user.QuotaUsedToday(),
QuotaMax: user.QuotaPerDay(), QuotaMax: user.QuotaPerDay(),
IsPro: langext.Conditional(user.IsPro, 1, 0), IsPro: user.IsPro,
})) }))
} }

View File

@ -17,6 +17,7 @@ func TestSendCompatWithOldUser(t *testing.T) {
pusher := ws.Pusher.(*push.TestSink) pusher := ws.Pusher.(*push.TestSink)
r0 := tt.RequestGet[gin.H](t, baseUrl, "/api/register.php?fcm_token=DUMMY_FCM&pro=0&pro_token=") r0 := tt.RequestGet[gin.H](t, baseUrl, "/api/register.php?fcm_token=DUMMY_FCM&pro=0&pro_token=")
tt.AssertEqual(t, "success", true, r0["success"])
uidold := int64(r0["user_id"].(float64)) uidold := int64(r0["user_id"].(float64))
admintok := r0["user_key"].(string) admintok := r0["user_key"].(string)
@ -198,7 +199,6 @@ func TestSendCompatMessageByQuery(t *testing.T) {
defer stop() 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", "")) 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"]) tt.AssertEqual(t, "success", true, r0["success"])
userid := int64(r0["user_id"].(float64)) userid := int64(r0["user_id"].(float64))
@ -251,7 +251,6 @@ func TestSendCompatMessageByFormData(t *testing.T) {
defer stop() 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", "")) 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"]) tt.AssertEqual(t, "success", true, r0["success"])
userid := int64(r0["user_id"].(float64)) userid := int64(r0["user_id"].(float64))
@ -311,7 +310,7 @@ func TestCompatRegister(t *testing.T) {
tt.AssertEqual(t, "message", "New user registered", r0["message"]) tt.AssertEqual(t, "message", "New user registered", r0["message"])
tt.AssertEqual(t, "quota", 0, r0["quota"]) tt.AssertEqual(t, "quota", 0, r0["quota"])
tt.AssertEqual(t, "quota_max", 50, r0["quota_max"]) tt.AssertEqual(t, "quota_max", 50, r0["quota_max"])
tt.AssertEqual(t, "is_pro", 0, r0["is_pro"]) tt.AssertEqual(t, "is_pro", false, r0["is_pro"])
} }
func TestCompatRegisterPro(t *testing.T) { func TestCompatRegisterPro(t *testing.T) {
@ -323,7 +322,7 @@ func TestCompatRegisterPro(t *testing.T) {
tt.AssertEqual(t, "message", "New user registered", r0["message"]) tt.AssertEqual(t, "message", "New user registered", r0["message"])
tt.AssertEqual(t, "quota", 0, r0["quota"]) tt.AssertEqual(t, "quota", 0, r0["quota"])
tt.AssertEqual(t, "quota_max", 1000, r0["quota_max"]) tt.AssertEqual(t, "quota_max", 1000, r0["quota_max"])
tt.AssertEqual(t, "is_pro", 1, r0["is_pro"]) tt.AssertEqual(t, "is_pro", true, r0["is_pro"])
r1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "true", url.QueryEscape("INVALID"))) r1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/register.php?fcm_token=%s&pro=%s&pro_token=%s", "DUMMY_FCM", "true", url.QueryEscape("INVALID")))
tt.AssertEqual(t, "success", false, r1["success"]) tt.AssertEqual(t, "success", false, r1["success"])
@ -498,5 +497,23 @@ func TestCompatUpdate(t *testing.T) {
} }
func TestCompatUpgrade(t *testing.T) { func TestCompatUpgrade(t *testing.T) {
t.SkipNow() //TODO _, 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", "FCM_DUMMY_FCM", "0", ""))
tt.AssertEqual(t, "success", true, r0["success"])
tt.AssertEqual(t, "message", "New user registered", r0["message"])
tt.AssertEqual(t, "quota", 0, r0["quota"])
tt.AssertEqual(t, "quota_max", 50, r0["quota_max"])
tt.AssertEqual(t, "is_pro", false, r0["is_pro"])
userid := int64(r0["user_id"].(float64))
userkey := r0["user_key"].(string)
r1 := tt.RequestGet[gin.H](t, baseUrl, fmt.Sprintf("/api/upgrade.php?user_id=%d&user_key=%s&pro=%s&pro_token=%s", userid, userkey, "true", url.QueryEscape("PURCHASED:000")))
tt.AssertEqual(t, "success", true, r1["success"])
tt.AssertEqual(t, "message", "user updated", r1["message"])
tt.AssertEqual(t, "quota", 0, r1["quota"])
tt.AssertEqual(t, "quota_max", 1000, r1["quota_max"])
tt.AssertEqual(t, "is_pro", true, r1["is_pro"])
} }