-
Notifications
You must be signed in to change notification settings - Fork 0
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 #40 from Zapharaos/3-tests
feat(#3 tests): backend api unit tests
- Loading branch information
Showing
120 changed files
with
15,432 additions
and
750 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
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
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,84 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/Zapharaos/fihub-backend/internal/auth/password" | ||
"github.com/Zapharaos/fihub-backend/internal/auth/permissions" | ||
"github.com/Zapharaos/fihub-backend/internal/auth/roles" | ||
"github.com/Zapharaos/fihub-backend/internal/auth/users" | ||
"github.com/Zapharaos/fihub-backend/internal/brokers" | ||
"github.com/Zapharaos/fihub-backend/internal/database" | ||
"github.com/Zapharaos/fihub-backend/internal/transactions" | ||
"github.com/Zapharaos/fihub-backend/pkg/email" | ||
"github.com/Zapharaos/fihub-backend/pkg/translation" | ||
"github.com/Zapharaos/fihub-backend/test" | ||
"github.com/stretchr/testify/assert" | ||
sqlmock "github.com/zhashkevych/go-sqlxmock" | ||
"go.uber.org/zap" | ||
"testing" | ||
) | ||
|
||
// TestInit tests the Init function to ensure that it correctly initializes the application. | ||
// This test only verifies : env, email, translation. | ||
// Any further function calls within Init are tested by their respective tests. | ||
func TestInit(t *testing.T) { | ||
// Create a full test suite | ||
ts := test.TestSuite{} | ||
_ = ts.CreateConfigTranslationsFullTestSuite(t) | ||
defer ts.CleanTestSuite(t) | ||
|
||
// Call Init function | ||
Init() | ||
|
||
// Assertions to verify initialization | ||
assert.NotNil(t, email.S(), "Email service should be initialized") | ||
assert.NotNil(t, translation.S(), "Translation service should be initialized") | ||
} | ||
|
||
// TestInitLogger tests the initLogger function to ensure that it correctly initializes the logger. | ||
func TestInitLogger(t *testing.T) { | ||
// Create a full test suite | ||
ts := test.TestSuite{} | ||
_ = ts.CreateFullTestSuite(t) | ||
defer ts.CleanTestSuite(t) | ||
|
||
// Call initLogger function | ||
initLogger() | ||
|
||
// Assertions to verify logger configuration | ||
assert.NotNil(t, zap.L(), "Logger should be initialized") | ||
} | ||
|
||
// TestInit tests the initDatabase function to ensure that it correctly initializes the database. | ||
// This test only verifies the database. | ||
// Any further function calls within initDatabase are tested by their respective tests. | ||
func TestInitDatabase(t *testing.T) { | ||
// Create a full test suite | ||
ts := test.TestSuite{} | ||
_ = ts.CreateFullTestSuite(t) | ||
defer ts.CleanTestSuite(t) | ||
|
||
// Call initDatabase function | ||
initDatabase() | ||
|
||
// Assertions to verify Database initialization | ||
assert.NotNil(t, database.DB()) | ||
} | ||
|
||
// TestInitPostgres tests the initPostgres function to ensure that it correctly initializes the repositories. | ||
func TestInitPostgres(t *testing.T) { | ||
// Simulate a successful connection | ||
sqlxMock, _, err := sqlmock.Newx() | ||
assert.NoError(t, err) | ||
defer sqlxMock.Close() | ||
|
||
// Call initPostgres function with the mock connection | ||
initPostgres(sqlxMock) | ||
|
||
// Assertions to verify repositories initialization | ||
assert.NotNil(t, users.R(), "Users repository should be initialized") | ||
assert.NotNil(t, password.R(), "Password repository should be initialized") | ||
assert.NotNil(t, roles.R(), "Roles repository should be initialized") | ||
assert.NotNil(t, permissions.R(), "Permissions repository should be initialized") | ||
assert.NotNil(t, brokers.R(), "Brokers repository should be initialized") | ||
assert.NotNil(t, transactions.R(), "Transactions repository should be initialized") | ||
} |
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
Oops, something went wrong.