-
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.
Use HTTP delete verb for deleting docs and users
- Loading branch information
Showing
12 changed files
with
26 additions
and
83 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
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 |
---|---|---|
|
@@ -19,7 +19,6 @@ func TestHighlights(t *testing.T) { | |
db *gorm.DB | ||
app *fiber.App | ||
adminCookie *http.Cookie | ||
data url.Values | ||
adminUser model.User | ||
) | ||
|
||
|
@@ -34,9 +33,6 @@ func TestHighlights(t *testing.T) { | |
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
data = url.Values{ | ||
"slug": {"john-doe-test-epub"}, | ||
} | ||
adminUser = model.User{} | ||
db.Where("email = ?", "[email protected]").First(&adminUser) | ||
|
||
|
@@ -116,11 +112,7 @@ func TestHighlights(t *testing.T) { | |
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
data = url.Values{ | ||
"id": {"john-doe-test-epub"}, | ||
} | ||
|
||
_, err = deleteRequest(data, adminCookie, app, "/documents", t) | ||
_, err = deleteRequest(url.Values{}, adminCookie, app, "/documents/john-doe-test-epub", t) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
@@ -158,11 +150,7 @@ func TestHighlights(t *testing.T) { | |
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
data := url.Values{ | ||
"id": {regularUser.Uuid}, | ||
} | ||
|
||
_, err = deleteRequest(data, adminCookie, app, "/users", t) | ||
_, err = deleteRequest(url.Values{}, adminCookie, app, fmt.Sprintf("/users/%s", regularUser.Username), t) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package webserver_test | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
|
@@ -43,8 +43,7 @@ func TestRemoveDocument(t *testing.T) { | |
slug string | ||
expectedHTTPStatus int | ||
}{ | ||
{"Remove no document slug", "[email protected]", "admin", "", "", http.StatusBadRequest}, | ||
{"Remove non existing document slug", "[email protected]", "admin", "wrong.epub", "", http.StatusBadRequest}, | ||
{"Remove non existing document slug", "[email protected]", "admin", "wrong.epub", "wrong-epub", http.StatusBadRequest}, | ||
{"Remove document with a regular user", "[email protected]", "regular", "metadata.epub", "john-doe-test-epub", http.StatusForbidden}, | ||
{"Remove document with an admin user", "[email protected]", "admin", "metadata.epub", "john-doe-test-epub", http.StatusOK}, | ||
} | ||
|
@@ -56,23 +55,15 @@ func TestRemoveDocument(t *testing.T) { | |
err error | ||
) | ||
|
||
data := url.Values{ | ||
"id": {tcase.slug}, | ||
} | ||
|
||
cookie, err := login(app, tcase.email, tcase.password, t) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodDelete, "/documents", strings.NewReader(data.Encode())) | ||
response, err = deleteRequest(url.Values{}, cookie, app, fmt.Sprintf("/documents/%s", tcase.slug), t) | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
} | ||
req.Header.Add("Content-Type", "application/x-www-form-urlencoded") | ||
req.AddCookie(cookie) | ||
|
||
response, err = app.Test(req) | ||
|
||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err.Error()) | ||
|
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