add new tests

This commit is contained in:
Yuli
2020-02-20 12:05:05 +02:00
parent d988ab5b85
commit 0cbca1cbf2
3 changed files with 29 additions and 1 deletions

View File

@@ -360,6 +360,10 @@ func (e mainEnv) consentUserRecord(w http.ResponseWriter, r *http.Request, ps ht
returnError(w, r, "internal error", 405, err, event)
return
}
if resultJSON == nil {
returnError(w, r, "not found", 405, nil, event)
return
}
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.WriteHeader(200)

View File

@@ -163,7 +163,7 @@ func (dbobj dbcon) listConsentRecords(userTOKEN string) ([]byte, int, error) {
func (dbobj dbcon) viewConsentRecord(userTOKEN string, brief string) ([]byte, error) {
record, err := dbobj.getRecord2(TblName.Consent, "token", userTOKEN, "brief", brief)
if err != nil {
if record == nil || err != nil {
return nil, err
}
resultJSON, err := json.Marshal(record)

View File

@@ -110,6 +110,10 @@ func TestCreateWithdrawConsent(t *testing.T) {
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
t.Fatalf("Failed to get user consent")
}
raw, _ = helpGetUserConsent("email", "moshe@moshe-int.com", brief)
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
t.Fatalf("Failed to get user consent")
}
record := raw["data"].(map[string]interface{})
if record["brief"].(string) != brief {
t.Fatalf("Wrong consent brief value")
@@ -162,12 +166,32 @@ func TestGetFakeBrief(t *testing.T) {
}
}
func TestGetUserUnkConsent(t *testing.T) {
userJSON := `{"email":"moshe23@mosh23e-int.com","phone":"123586678"}`
raw, err := helpCreateUser(userJSON)
if err != nil {
t.Fatalf("Wrror in user creation: %s", err)
}
if _, ok := raw["status"]; !ok || raw["status"].(string) != "ok" {
t.Fatalf("Failed to create user")
}
userTOKEN := raw["token"].(string)
raw, _ = helpGetUserConsent("token", userTOKEN, "kolhoz")
if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" {
t.Fatalf("Should fail to get user consent")
}
}
func TestGetFakeUserConsents(t *testing.T) {
userTOKEN, _ := uuid.GenerateUUID()
raw, _ := helpGetUserConsent("token", userTOKEN, "alibaba")
if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" {
t.Fatalf("Should fail to get user consent")
}
raw, _ = helpGetUserConsent("token", userTOKEN, "ali$baba")
if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" {
t.Fatalf("Should fail to get user consent")
}
raw, _ = helpGetUserConsent("fake", userTOKEN, "alibaba")
if _, ok := raw["status"]; ok && raw["status"].(string) == "ok" {
t.Fatalf("Should fail to get user consent")