-
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.
Added tests for all funcs in accounts curd
- Loading branch information
1 parent
084441b
commit 3821832
Showing
5 changed files
with
104 additions
and
7 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
DROP TABLE IF EXISTS accounts; | ||
DROP TABLE IF EXISTS entries; | ||
DROP TABLE IF EXISTS transfers; | ||
DROP TABLE IF EXISTS accounts CASCADE; | ||
DROP TABLE IF EXISTS entries CASCADE; | ||
DROP TABLE IF EXISTS transfers CASCADE; |
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 |
---|---|---|
@@ -1,7 +1,83 @@ | ||
package db | ||
|
||
import "testing" | ||
import ( | ||
"context" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestCreateAccount(T *testing.T) { | ||
|
||
func TestCreateAccount(t *testing.T) { | ||
args := CreateAccountParams{ | ||
Owner: "Test", | ||
Balance: 100, | ||
Currency: "USD", | ||
} | ||
account, err := testQueries.CreateAccount(context.Background(), args) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, account) | ||
require.Equal(t, args.Owner, account.Owner) | ||
require.Equal(t, args.Balance, account.Balance) | ||
require.Equal(t, args.Currency, account.Currency) | ||
require.NotZero(t, account.ID) | ||
require.NotZero(t, account.CreatedAt) | ||
} | ||
|
||
func TestGetAccount(t *testing.T) { | ||
getAccount, err := testQueries.GetAccount(context.Background(), 1) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, getAccount) | ||
require.Equal(t, getAccount.ID, int64(1)) | ||
require.Equal(t, getAccount.Owner, "Test") | ||
require.Equal(t, getAccount.Balance, int64(100)) | ||
require.Equal(t, getAccount.Currency, "USD") | ||
require.NotZero(t, getAccount.ID) | ||
require.NotZero(t, getAccount.CreatedAt) | ||
} | ||
|
||
func TestListAccounts(t *testing.T) { | ||
arg := ListAccountsParams{ | ||
Limit: 5, | ||
Offset: 0, | ||
} | ||
|
||
accounts, err := testQueries.ListAccounts(context.Background(), arg) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, accounts) | ||
|
||
for _, account := range accounts { | ||
require.NotEmpty(t, account) | ||
require.Equal(t, "Test", account.Owner) | ||
} | ||
} | ||
|
||
func TestUpdateAccount(t *testing.T) { | ||
args := UpdateAccountParams{ | ||
ID: 1, | ||
Balance: 200, | ||
} | ||
account, err := testQueries.UpdateAccount(context.Background(), args) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, account) | ||
require.Equal(t, args.ID, account.ID) | ||
require.Equal(t, args.Balance, account.Balance) | ||
require.NotZero(t, account.ID) | ||
require.NotZero(t, account.CreatedAt) | ||
} | ||
|
||
func TestDeleteAccount(t *testing.T) { | ||
account, err := testQueries.CreateAccount(context.Background(), CreateAccountParams{ | ||
Owner: "Test_DELETE", | ||
Balance: 100, | ||
Currency: "USD", | ||
}) | ||
getAccount, err := testQueries.GetAccount(context.Background(), account.ID) | ||
err = testQueries.DeleteAccount(context.Background(), getAccount.ID) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, account) | ||
require.NotEmpty(t, getAccount) | ||
require.Equal(t, getAccount.ID, account.ID) | ||
require.Equal(t, getAccount.Owner, account.Owner) | ||
require.Equal(t, getAccount.Balance, account.Balance) | ||
require.NotZero(t, account.ID) | ||
require.NotZero(t, account.CreatedAt) | ||
} |
File renamed without changes.
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