Skip to content

Commit

Permalink
test: Update the HandleRoutes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobefu committed Dec 29, 2024
1 parent e1579bc commit 5de4d27
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cmd/server/handle-routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,54 @@ func TestHandleRoutes(t *testing.T) {
assert.NotEqual(t, nil, body["error"])

os.Setenv("DB_CONN", oldDb)
err = database.Connect()
assert.Equal(t, nil, err)

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "translations"),
true,
)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, body["error"])

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "translations?locale=en"),
true,
)
assert.Equal(t, nil, err)
assert.Equal(t, nil, body["error"])

oldApiKey = os.Getenv("CS_API_KEY")
os.Setenv("CS_API_KEY", "bogus")

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "translations?locale=en"),
true,
)
assert.Equal(t, nil, err)
assert.Equal(t, nil, body["error"])

os.Setenv("CS_API_KEY", oldApiKey)

oldDb = os.Getenv("DB_CONN")
os.Setenv("DB_CONN", "file:/")
err = database.Connect()
assert.Equal(t, nil, err)

body, err = request(
"GET",
fmt.Sprintf("%s/%s", server.URL, "translations?locale=en"),
true,
)
assert.Equal(t, nil, err)
assert.NotEqual(t, nil, body["error"])

os.Setenv("DB_CONN", oldDb)
err = database.Connect()
assert.Equal(t, nil, err)
}

func request(method string, path string, withAuthToken bool) (body map[string]interface{}, err error) {
Expand Down

0 comments on commit 5de4d27

Please sign in to comment.