-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtransactions.controller_test.go
More file actions
58 lines (46 loc) · 1.23 KB
/
transactions.controller_test.go
File metadata and controls
58 lines (46 loc) · 1.23 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
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"bytes"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestInsertNewTransaction(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
jsonValue := `
{
"product_id": 1,
"title": "sale product 1",
"amount": 10001,
"type":"input",
"date":"2018-02-18 12:12:12"
}
`
req, _ := http.NewRequest("POST", "/v1/companies/1/transactions", bytes.NewBuffer([]byte(jsonValue)))
req.Header.Add("Authorization", "Bearer "+os.Getenv("JWT_TEST_TOKEN"))
router.ServeHTTP(w, req)
assert.Equal(t, 201, w.Code)
}
func TestInsertNewTransactionFailed(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
jsonValue := `
{
}
`
req, _ := http.NewRequest("POST", "/v1/companies/1/transactions", bytes.NewBuffer([]byte(jsonValue)))
req.Header.Add("Authorization", "Bearer "+os.Getenv("JWT_TEST_TOKEN"))
router.ServeHTTP(w, req)
assert.Equal(t, 400, w.Code)
}
func TestGetAllTransactions(t *testing.T) {
router := setupRouter()
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/v1/companies/1/transactions", nil)
req.Header.Add("Authorization", "Bearer "+os.Getenv("JWT_TEST_TOKEN"))
router.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
}