Add extra post test
This commit is contained in:
parent
5a233073c7
commit
7727bedbbd
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TestAllowanceName = "Test History"
|
TestHistoryName = "Test History"
|
||||||
)
|
)
|
||||||
|
|
||||||
func startServer(t *testing.T) *httpexpect.Expect {
|
func startServer(t *testing.T) *httpexpect.Expect {
|
||||||
@ -62,7 +62,7 @@ func TestGetUserAllowance(t *testing.T) {
|
|||||||
|
|
||||||
// Create a new allowance
|
// Create a new allowance
|
||||||
requestBody := map[string]interface{}{
|
requestBody := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 5000,
|
"target": 5000,
|
||||||
"weight": 10,
|
"weight": 10,
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func TestGetUserAllowance(t *testing.T) {
|
|||||||
result.Length().IsEqual(2)
|
result.Length().IsEqual(2)
|
||||||
item := result.Value(1).Object()
|
item := result.Value(1).Object()
|
||||||
item.Value("id").IsEqual(1)
|
item.Value("id").IsEqual(1)
|
||||||
item.Value("name").IsEqual(TestAllowanceName)
|
item.Value("name").IsEqual(TestHistoryName)
|
||||||
item.Value("target").IsEqual(5000)
|
item.Value("target").IsEqual(5000)
|
||||||
item.Value("weight").IsEqual(10)
|
item.Value("weight").IsEqual(10)
|
||||||
item.Value("progress").IsEqual(0)
|
item.Value("progress").IsEqual(0)
|
||||||
@ -95,7 +95,7 @@ func TestCreateUserAllowance(t *testing.T) {
|
|||||||
|
|
||||||
// Create a new allowance
|
// Create a new allowance
|
||||||
requestBody := map[string]interface{}{
|
requestBody := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 5000,
|
"target": 5000,
|
||||||
"weight": 10,
|
"weight": 10,
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func TestCreateUserAllowance(t *testing.T) {
|
|||||||
|
|
||||||
allowance := allowances.Value(1).Object()
|
allowance := allowances.Value(1).Object()
|
||||||
allowance.Value("id").IsEqual(allowanceId)
|
allowance.Value("id").IsEqual(allowanceId)
|
||||||
allowance.Value("name").IsEqual(TestAllowanceName)
|
allowance.Value("name").IsEqual(TestHistoryName)
|
||||||
allowance.Value("target").IsEqual(5000)
|
allowance.Value("target").IsEqual(5000)
|
||||||
allowance.Value("weight").IsEqual(10)
|
allowance.Value("weight").IsEqual(10)
|
||||||
allowance.Value("progress").IsEqual(0)
|
allowance.Value("progress").IsEqual(0)
|
||||||
@ -130,7 +130,7 @@ func TestCreateUserAllowanceNoUser(t *testing.T) {
|
|||||||
e := startServer(t)
|
e := startServer(t)
|
||||||
|
|
||||||
requestBody := map[string]interface{}{
|
requestBody := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 5000,
|
"target": 5000,
|
||||||
"weight": 10,
|
"weight": 10,
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ func TestCreateUserAllowanceBadId(t *testing.T) {
|
|||||||
e := startServer(t)
|
e := startServer(t)
|
||||||
|
|
||||||
requestBody := map[string]interface{}{
|
requestBody := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 5000,
|
"target": 5000,
|
||||||
"weight": 10,
|
"weight": 10,
|
||||||
}
|
}
|
||||||
@ -187,7 +187,7 @@ func TestDeleteUserAllowance(t *testing.T) {
|
|||||||
|
|
||||||
// Create a new allowance to delete
|
// Create a new allowance to delete
|
||||||
createRequest := map[string]interface{}{
|
createRequest := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 1000,
|
"target": 1000,
|
||||||
"weight": 5,
|
"weight": 5,
|
||||||
}
|
}
|
||||||
@ -434,7 +434,7 @@ func TestPutTaskInvalidTaskId(t *testing.T) {
|
|||||||
e.PUT("/task/999").WithJSON(requestBody).Expect().Status(404)
|
e.PUT("/task/999").WithJSON(requestBody).Expect().Status(404)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostAllowance(t *testing.T) {
|
func TestPostHistory(t *testing.T) {
|
||||||
e := startServer(t)
|
e := startServer(t)
|
||||||
|
|
||||||
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: 100}).Expect().Status(200)
|
e.POST("/user/1/history").WithJSON(PostHistory{Allowance: 100}).Expect().Status(200)
|
||||||
@ -445,7 +445,7 @@ func TestPostAllowance(t *testing.T) {
|
|||||||
response.Value("allowance").Number().IsEqual(100 + 20 - 10)
|
response.Value("allowance").Number().IsEqual(100 + 20 - 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostAllowanceInvalidUserId(t *testing.T) {
|
func TestPostHistoryInvalidUserId(t *testing.T) {
|
||||||
e := startServer(t)
|
e := startServer(t)
|
||||||
|
|
||||||
e.POST("/user/999/history").WithJSON(PostHistory{Allowance: 100}).Expect().
|
e.POST("/user/999/history").WithJSON(PostHistory{Allowance: 100}).Expect().
|
||||||
@ -472,7 +472,7 @@ func TestGetUserAllowanceById(t *testing.T) {
|
|||||||
|
|
||||||
// Create a new allowance
|
// Create a new allowance
|
||||||
requestBody := map[string]interface{}{
|
requestBody := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 5000,
|
"target": 5000,
|
||||||
"weight": 10,
|
"weight": 10,
|
||||||
}
|
}
|
||||||
@ -482,7 +482,7 @@ func TestGetUserAllowanceById(t *testing.T) {
|
|||||||
// Retrieve the created allowance by ID
|
// Retrieve the created allowance by ID
|
||||||
result := e.GET("/user/1/allowance/" + strconv.Itoa(allowanceId)).Expect().Status(200).JSON().Object()
|
result := e.GET("/user/1/allowance/" + strconv.Itoa(allowanceId)).Expect().Status(200).JSON().Object()
|
||||||
result.Value("id").IsEqual(allowanceId)
|
result.Value("id").IsEqual(allowanceId)
|
||||||
result.Value("name").IsEqual(TestAllowanceName)
|
result.Value("name").IsEqual(TestHistoryName)
|
||||||
result.Value("target").IsEqual(5000)
|
result.Value("target").IsEqual(5000)
|
||||||
result.Value("weight").IsEqual(10)
|
result.Value("weight").IsEqual(10)
|
||||||
result.Value("progress").IsEqual(0)
|
result.Value("progress").IsEqual(0)
|
||||||
@ -508,12 +508,33 @@ func TestGetUserByAllowanceByIdBadAllowanceId(t *testing.T) {
|
|||||||
e.GET("/user/1/allowance/bad").Expect().Status(400)
|
e.GET("/user/1/allowance/bad").Expect().Status(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostAllowance(t *testing.T) {
|
||||||
|
e := startServer(t)
|
||||||
|
|
||||||
|
// Create a new allowance
|
||||||
|
requestBody := map[string]interface{}{
|
||||||
|
"name": TestHistoryName,
|
||||||
|
"target": 5000,
|
||||||
|
"weight": 10,
|
||||||
|
"colour": "#FF5733",
|
||||||
|
}
|
||||||
|
resp := e.POST("/user/1/allowance").WithJSON(requestBody).Expect().Status(201).JSON().Object()
|
||||||
|
resp.Value("id").Number().IsEqual(1)
|
||||||
|
|
||||||
|
result := e.GET("/user/1/allowance/1").Expect().Status(200).JSON().Object()
|
||||||
|
result.Value("id").IsEqual(1)
|
||||||
|
result.Value("name").IsEqual("Test History")
|
||||||
|
result.Value("target").IsEqual(5000)
|
||||||
|
result.Value("weight").IsEqual(10)
|
||||||
|
result.Value("colour").IsEqual("#FF5733")
|
||||||
|
}
|
||||||
|
|
||||||
func TestPutAllowanceById(t *testing.T) {
|
func TestPutAllowanceById(t *testing.T) {
|
||||||
e := startServer(t)
|
e := startServer(t)
|
||||||
|
|
||||||
// Create a new allowance
|
// Create a new allowance
|
||||||
requestBody := map[string]interface{}{
|
requestBody := map[string]interface{}{
|
||||||
"name": TestAllowanceName,
|
"name": TestHistoryName,
|
||||||
"target": 5000,
|
"target": 5000,
|
||||||
"weight": 10,
|
"weight": 10,
|
||||||
"colour": "#FF5733",
|
"colour": "#FF5733",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user