This repository was archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathe2e_test.go
More file actions
63 lines (53 loc) · 1.42 KB
/
e2e_test.go
File metadata and controls
63 lines (53 loc) · 1.42 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
59
60
61
62
63
package main
import (
"bytes"
"encoding/json"
"github.com/Tutor2Tutee/T2T-GO/routers"
"github.com/Tutor2Tutee/T2T-GO/tests"
"github.com/gin-gonic/gin"
"log"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func init() {
log.SetPrefix("[TESTING] ")
if err := os.Setenv("GO_ENV", "TEST"); err != nil {
log.Fatalln("failed to set env")
}
gin.SetMode(gin.TestMode)
}
func TestShouldReturnNotFound(t *testing.T) {
req, _ := http.NewRequest("GET", "/notapage", nil)
w := httptest.NewRecorder()
r := routers.GetRouter(tests.GetMockDatabase())
r.ServeHTTP(w, req)
if w.Code != http.StatusNotFound {
t.Error("Status not found should come here")
}
}
func TestShouldGetEveryClasses(t *testing.T) {
req, _ := http.NewRequest("GET", "/api/classes", nil)
w := httptest.NewRecorder()
r := routers.GetRouter(tests.GetMockDatabase())
r.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Error("should return 200 OK")
}
}
func TestShouldCreateASingleClass(t *testing.T) {
//RequestBody := models.Class{Name: "HELLO", Description: "description"}
RequestBody := gin.H{
"name": "HELLO",
"description": "DESCRIPTION",
}
body, _ := json.Marshal(RequestBody)
req, _ := http.NewRequest("POST", "/api/classes", bytes.NewBuffer(body))
w := httptest.NewRecorder()
r := routers.GetRouter(tests.GetMockDatabase())
r.ServeHTTP(w, req)
if w.Code != http.StatusCreated {
t.Error("should return 201 CREATED", w.Code, w.Body)
}
}