Skip to content

Commit

Permalink
Merge branch 'main' into feature/get_image_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusgomes28 authored Mar 29, 2024
2 parents 4fa835b + cf04c2f commit d8a25ab
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker/start-app.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#!/usr/bin/env bash

set -euo pipefail

Expand Down
79 changes: 79 additions & 0 deletions tests/app_tests/endpoint_tests/posts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/matheusgomes28/urchin/common"
"github.com/matheusgomes28/urchin/tests/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestPostSuccess(t *testing.T) {
Expand Down Expand Up @@ -40,3 +41,81 @@ func TestPostSuccess(t *testing.T) {
assert.Equal(t, http.StatusOK, w.Code)
assert.Contains(t, w.Body.String(), "TestPost")
}

func TestPostFailureStringKey(t *testing.T) {

app_settings := common.AppSettings{
DatabaseAddress: "localhost",
DatabasePort: 3006,
DatabaseUser: "root",
DatabasePassword: "root",
DatabaseName: "urchin",
WebserverPort: 8080,
}

database_mock := mocks.DatabaseMock{}

router := app.SetupRoutes(app_settings, database_mock)
responseRecorder := httptest.NewRecorder()

request, err := http.NewRequest("GET", "/post/sampleString", nil)

require.Nil(t, err)

router.ServeHTTP(responseRecorder, request)

require.Equal(t, http.StatusInternalServerError, responseRecorder.Code)

}

func TestPostFailurePostDoesntExist(t *testing.T) {

app_settings := common.AppSettings{
DatabaseAddress: "localhost",
DatabasePort: 3006,
DatabaseUser: "root",
DatabasePassword: "root",
DatabaseName: "urchin",
WebserverPort: 8080,
}

database_mock := mocks.DatabaseMock{}

router := app.SetupRoutes(app_settings, database_mock)
responseRecorder := httptest.NewRecorder()

request, err := http.NewRequest("GET", "/post/-1", nil)

require.Nil(t, err)

router.ServeHTTP(responseRecorder, request)

require.Equal(t, http.StatusInternalServerError, responseRecorder.Code)

}

func TestPostFailureNegativeInvalidKey(t *testing.T) {

app_settings := common.AppSettings{
DatabaseAddress: "localhost",
DatabasePort: 3006,
DatabaseUser: "root",
DatabasePassword: "root",
DatabaseName: "urchin",
WebserverPort: 8080,
}

database_mock := mocks.DatabaseMock{}

router := app.SetupRoutes(app_settings, database_mock)
responseRecorder := httptest.NewRecorder()

request, err := http.NewRequest("GET", "/post/10000", nil)

require.Nil(t, err)

router.ServeHTTP(responseRecorder, request)

require.Equal(t, http.StatusInternalServerError, responseRecorder.Code)

}

0 comments on commit d8a25ab

Please sign in to comment.