-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcategory_add_http_test.go
More file actions
38 lines (35 loc) · 1.26 KB
/
category_add_http_test.go
File metadata and controls
38 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gobookmarks
import (
"context"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
func TestCategoryAddSaveAction(t *testing.T) {
p, user, _, ctx := setupCategoryEditTest(t)
original := "Category: First\nhttp://one.com one\n"
if err := p.CreateBookmarks(context.Background(), user, nil, "main", original); err != nil {
t.Fatalf("CreateBookmarks: %v", err)
}
_, sha, err := p.GetBookmarks(context.Background(), user, "refs/heads/main", nil)
if err != nil {
t.Fatalf("GetBookmarks: %v", err)
}
form := url.Values{"text": {"Category: New\nhttp://two.com two"}, "branch": {"main"}, "ref": {"refs/heads/main"}, "sha": {sha}, "tab": {"0"}, "page": {"0"}, "col": {"0"}}
req := httptest.NewRequest("POST", "/addCategory", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req = req.WithContext(ctx)
w := httptest.NewRecorder()
if err := CategoryAddSaveAction(w, req); err != nil {
t.Fatalf("CategoryAddSaveAction: %v", err)
}
got, _, err := p.GetBookmarks(context.Background(), user, "refs/heads/main", nil)
if err != nil {
t.Fatalf("GetBookmarks after: %v", err)
}
expected := original + "Category: New\nhttp://two.com two\n"
if got != expected {
t.Fatalf("expected %q got %q", expected, got)
}
}