-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="px-4 py-5 my-5 text-center"> | ||
<h2>{{t .Lang "Method not allowed"}}</h2> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,25 @@ func TestHighlights(t *testing.T) { | |
adminUser := model.User{} | ||
db.Where("email = ?", "[email protected]").First(&adminUser) | ||
|
||
regularUserData := url.Values{ | ||
"name": {"Test user"}, | ||
"email": {"[email protected]"}, | ||
"password": {"test"}, | ||
"confirm-password": {"test"}, | ||
"role": {fmt.Sprint(model.RoleRegular)}, | ||
"words-per-minute": {"250"}, | ||
} | ||
|
||
adminCookie, err := login(app, "[email protected]", "admin") | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
response, err := addUser(regularUserData, adminCookie, app) | ||
if response == nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
t.Run("Try to highlight a document without an active session", func(t *testing.T) { | ||
response, err := highlight(&http.Cookie{}, app, strings.NewReader(data.Encode()), fiber.MethodPost) | ||
if err != nil { | ||
|
@@ -56,6 +70,46 @@ func TestHighlights(t *testing.T) { | |
|
||
assertHighlights(app, t, adminCookie, adminUser.Uuid, 0) | ||
}) | ||
|
||
t.Run("Deleting a user also remove his/her highlights", func(t *testing.T) { | ||
regularUser := model.User{} | ||
db.Where("email = ?", "[email protected]").First(®ularUser) | ||
|
||
regularUserCookie, err := login(app, "[email protected]", "test") | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
response, err := highlight(regularUserCookie, app, strings.NewReader(data.Encode()), fiber.MethodPost) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
mustReturnStatus(response, fiber.StatusOK, t) | ||
|
||
assertHighlights(app, t, regularUserCookie, regularUser.Uuid, 1) | ||
|
||
adminCookie, err = login(app, "[email protected]", "admin") | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
data = url.Values{ | ||
"uuid": {regularUser.Uuid}, | ||
} | ||
|
||
_, err = deleteUser(data, adminCookie, app) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
assertNoHighlights(app, t, adminCookie, regularUser.Uuid) | ||
var total int64 | ||
db.Table("highlights").Where("user_id = ?", regularUser.ID).Count(&total) | ||
if total != 0 { | ||
t.Errorf("Expected no highlights in DB for deleted user, got %d", total) | ||
} | ||
}) | ||
} | ||
|
||
func highlight(cookie *http.Cookie, app *fiber.App, reader *strings.Reader, method string) (*http.Response, error) { | ||
|
@@ -92,3 +146,18 @@ func assertHighlights(app *fiber.App, t *testing.T, cookie *http.Cookie, uuid st | |
t.Errorf("Expected %d results, got %d", expectedResults, actualResults) | ||
} | ||
} | ||
|
||
func assertNoHighlights(app *fiber.App, t *testing.T, cookie *http.Cookie, uuid string) { | ||
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("/en/highlights/%s", uuid), nil) | ||
req.AddCookie(cookie) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
response, err := app.Test(req) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
if expectedStatus := http.StatusNotFound; response.StatusCode != expectedStatus { | ||
t.Errorf("Expected status %d, received %d", expectedStatus, response.StatusCode) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ func TestUserManagement(t *testing.T) { | |
"email": {"[email protected]"}, | ||
"password": {"test"}, | ||
"confirm-password": {"test"}, | ||
"role": {"1"}, | ||
"role": {fmt.Sprint(model.RoleRegular)}, | ||
"words-per-minute": {"250"}, | ||
} | ||
|
||
|