Skip to content

Commit

Permalink
fix: 🐛 test の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoha000 committed Dec 18, 2023
1 parent 3f2e4a8 commit 93ba154
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions router/items_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func TestPostItems(t *testing.T) {
ImgURL: "http://example.com/testKojin.jpg",
}

testValidBodies := []model.Item{
{
Name: "testPostInvalidItem3",
Type: 0,
Code: "",
Description: "これはバリデーションのテスト3です",
ImgURL: "http://example.com/testInvalid3.jpg",
},
}

testInvalidBodies := []model.Item{
{
Name: "",
Expand All @@ -49,13 +59,6 @@ func TestPostItems(t *testing.T) {
Description: "これはバリデーションのテスト2です",
ImgURL: "http://example.com/testInvalid2.jpg",
},
{
Name: "testPostInvalidItem3",
Type: 0,
Code: "",
Description: "これはバリデーションのテスト3です",
ImgURL: "http://example.com/testInvalid3.jpg",
},
{
Name: "testPostInvalidItem4",
Type: 0,
Expand All @@ -67,7 +70,7 @@ func TestPostItems(t *testing.T) {
Name: "testPostInvalidItem5",
Type: 0,
Code: "3575736936335",
Description: "これはバリデーションのテスト5です",
Description: "これはバリデーションのテスト4です",
ImgURL: "not a url",
},
}
Expand Down Expand Up @@ -138,6 +141,21 @@ func TestPostItems(t *testing.T) {
assert.Equal(http.StatusBadRequest, rec.Code)
})
}

for _, body := range testValidBodies {
t.Run("admin user/validation pass", func(t *testing.T) {
assert := assert.New(t)
e := echoSetupWithAdminUser()

reqBody, _ := json.Marshal(body)
req := httptest.NewRequest(echo.POST, "/api/items", bytes.NewReader(reqBody))
req.Header.Set("Content-Type", "application/json")
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)

assert.Equal(http.StatusCreated, rec.Code)
})
}
}

func TestPutItem(t *testing.T) {
Expand Down

0 comments on commit 93ba154

Please sign in to comment.