-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcategories.controller_test.go
More file actions
45 lines (36 loc) · 1.04 KB
/
categories.controller_test.go
File metadata and controls
45 lines (36 loc) · 1.04 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
39
40
41
42
43
44
45
package main
import (
"bytes"
"encoding/json"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestInsertNewCategory(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
var category Categorise
category.Name = "test category"
category.Order = 1
category.ParentId = 0
jsonValue, _ := json.Marshal(category)
req, _ := http.NewRequest("POST", "/v1/companies/1/categories", bytes.NewBuffer(jsonValue))
req.Header.Add("Authorization", "Bearer "+os.Getenv("JWT_TEST_TOKEN"))
router.ServeHTTP(w, req)
assert.Equal(t, 201, w.Code)
}
func TestInsertNewCategoryFailed(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
var category Categorise
category.Name = ""
category.Order = 0
category.ParentId = 0
jsonValue, _ := json.Marshal(category)
req, _ := http.NewRequest("POST", "/v1/companies/1/categories", bytes.NewBuffer(jsonValue))
req.Header.Add("Authorization", "Bearer "+os.Getenv("JWT_TEST_TOKEN"))
router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
}