diff --git a/models/album.go b/models/album.go index 9842864..0bf8f0f 100644 --- a/models/album.go +++ b/models/album.go @@ -8,8 +8,3 @@ type Album struct { Artist string `json:"artist,omitempty" validate:"required"` Price float64 `json:"price,omitempty" validate:"required"` } - -func getAlbumStruct() Album { - var album Album - return album -} diff --git a/routes/albums_test.go b/routes/albums_test.go index 337c7ed..c1ec375 100644 --- a/routes/albums_test.go +++ b/routes/albums_test.go @@ -1,31 +1,29 @@ package routes import ( - "ginapi/models" - "github.com/mjarkk/mongomock" + "fmt" "github.com/stretchr/testify/assert" - "log" "net/http" "net/http/httptest" "testing" ) -func TestAlbumsRoute(t *testing.T) { - db := mongomock.NewDB() - collection := db.Collection("Albums") - err := collection.Insert(models.Album{ - Title: "Let it Be", - Artist: "The Beatles", - Price: 12.99, - }) - if err != nil { - log.Fatal(err) - } +func TestGetAlbumsRoute(t *testing.T) { router := SetupRouter() w := httptest.NewRecorder() req, _ := http.NewRequest("GET", "/albums", nil) router.ServeHTTP(w, req) assert.Equal(t, 200, w.Code) - //assert.Equal(t, "pong", w.Body.String()) + fmt.Println(w.Body.String()) +} + +func TestGetAlbumRoute(t *testing.T) { + router := SetupRouter() + w := httptest.NewRecorder() + req, _ := http.NewRequest("GET", "/albums/66053fd1e9647c9e6a7d8a25", nil) + router.ServeHTTP(w, req) + + assert.Equal(t, 200, w.Code) + assert.Equal(t, `{"status":200,"message":"success","data":{"data":{"_id":"66053fd1e9647c9e6a7d8a25","artist":"Beatles","id":"66053fd1e9647c9e6a7d8a24","price":12.99,"title":"Abbey Road"}}}`, w.Body.String()) } diff --git a/routes/artist_test.go b/routes/artist_test.go new file mode 100644 index 0000000..2e257b5 --- /dev/null +++ b/routes/artist_test.go @@ -0,0 +1,29 @@ +package routes + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "net/http" + "net/http/httptest" + "testing" +) + +func TestGetArtistsRoute(t *testing.T) { + router := SetupRouter() + w := httptest.NewRecorder() + req, _ := http.NewRequest("GET", "/artists", nil) + router.ServeHTTP(w, req) + + assert.Equal(t, 200, w.Code) + fmt.Println(w.Body.String()) +} + +func TestGetArtistRoute(t *testing.T) { + router := SetupRouter() + w := httptest.NewRecorder() + req, _ := http.NewRequest("GET", "/artists/6606e636ea20581b675f6cdf", nil) + router.ServeHTTP(w, req) + fmt.Println(w.Body.String()) + assert.Equal(t, 200, w.Code) + assert.Equal(t, `{"status":200,"message":"success","data":{"data":{"_id":"6606e636ea20581b675f6cdf","id":"6606e636ea20581b675f6cde","name":"Lennon","surname":"John"}}}`, w.Body.String()) +}