-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from basemind-ai/BM-0001-tests
feat(infrastructure): setup mock db env
- Loading branch information
Showing
14 changed files
with
512 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ jobs: | |
id-token: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Golang | ||
uses: actions/setup-go@v4 | ||
with: | ||
|
@@ -41,7 +40,9 @@ jobs: | |
if: steps.cached-go-dependencies.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: go get -v -t ./... | ||
|
||
- name: Install Atlas | ||
shell: bash | ||
run: curl -sSf https://atlasgo.sh | sh | ||
- name: Authenticate with GCP | ||
id: auth | ||
uses: google-github-actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package api_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
dbTestUtils "github.com/basemind-ai/monorepo/go-shared/db/testutils" | ||
|
||
"github.com/basemind-ai/monorepo/go-services/dashboard-backend/api" | ||
|
||
"github.com/basemind-ai/monorepo/go-shared/serialization" | ||
|
||
"github.com/basemind-ai/monorepo/go-services/dashboard-backend/constants" | ||
firebaseTestUtils "github.com/basemind-ai/monorepo/go-shared/firebaseutils/testutils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHandleDashboardUserPostLogin(t *testing.T) { | ||
dbTestUtils.CreateTestDB(t) | ||
|
||
t.Run("Create New User tests", func(t *testing.T) { | ||
t.Run("success case", func(t *testing.T) { | ||
rr := httptest.NewRecorder() | ||
|
||
req, err := http.NewRequestWithContext(firebaseTestUtils.MockFirebaseContext(), http.MethodGet, constants.DashboardLoginEndpoint, nil) | ||
assert.Nil(t, err) | ||
|
||
api.HandleDashboardUserPostLogin(rr, req) | ||
res := rr.Result() | ||
|
||
assert.Equal(t, http.StatusCreated, res.StatusCode) | ||
|
||
var responseUser api.HandleDashboardUserPostLoginDTO | ||
err = serialization.DeserializeJson(res, &responseUser) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, "1", responseUser.User.FirebaseID) | ||
assert.Equal(t, "Default Project", responseUser.Projects[0].Name) | ||
assert.Equal(t, "Default Project", responseUser.Projects[0].Description) | ||
}) | ||
|
||
t.Run("failure case - failed to create user", func(t *testing.T) {}) | ||
t.Run("failure case - failed to create project", func(t *testing.T) {}) | ||
t.Run("failure case - failed to create user-project", func(t *testing.T) {}) | ||
}) | ||
|
||
t.Run("Retrieves a existing user tests", func(t *testing.T) { | ||
t.Run("success case", func(t *testing.T) { | ||
req, err := http.NewRequestWithContext(firebaseTestUtils.MockFirebaseContext(), http.MethodGet, constants.DashboardLoginEndpoint, nil) | ||
assert.Nil(t, err) | ||
api.HandleDashboardUserPostLogin(httptest.NewRecorder(), req) | ||
|
||
req, err = http.NewRequestWithContext(firebaseTestUtils.MockFirebaseContext(), http.MethodGet, constants.DashboardLoginEndpoint, nil) | ||
assert.Nil(t, err) | ||
|
||
rr := httptest.NewRecorder() | ||
api.HandleDashboardUserPostLogin(rr, req) | ||
|
||
res := rr.Result() | ||
assert.Equal(t, http.StatusOK, res.StatusCode) | ||
|
||
var responseUser api.HandleDashboardUserPostLoginDTO | ||
err = serialization.DeserializeJson(res, &responseUser) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, "1", responseUser.User.FirebaseID) | ||
assert.Equal(t, "Default Project", responseUser.Projects[0].Name) | ||
assert.Equal(t, "Default Project", responseUser.Projects[0].Description) | ||
}) | ||
|
||
t.Run("failure case - failed to retrieve user", func(t *testing.T) {}) | ||
t.Run("failure case - failed to retrieve user projects", func(t *testing.T) {}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,7 @@ func GetQueries() *Queries { | |
}) | ||
return queries | ||
} | ||
|
||
func SetConnection(conn *pgx.Conn) { | ||
connection = conn | ||
} |
Oops, something went wrong.