Skip to content

Commit

Permalink
test: add *testing.T as first argument for createTestTransactionV3 (#868
Browse files Browse the repository at this point in the history
)
  • Loading branch information
morremeyer authored Dec 1, 2023
1 parent bcc9209 commit d7dcd75
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions pkg/controllers/import_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ func (suite *TestSuiteStandard) TestImportYnabImportPreviewV3DuplicateDetection(
// Get the import hash of the first transaction and create one with the same import hash
preview := suite.parseCsvV3(suite.T(), account.Data.ID, "comdirect-ynap.csv")

transaction := suite.createTestTransactionV3(models.TransactionCreate{
transaction := suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
SourceAccountID: account.Data.ID,
ImportHash: preview.Data[0].Transaction.ImportHash,
Amount: decimal.NewFromFloat(1.13),
})

_ = suite.createTestTransactionV3(models.TransactionCreate{
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
SourceAccountID: suite.createTestAccountV3(suite.T(), models.AccountCreate{Note: "This account is in a different Budget, but has the same ImportHash", Name: "TestYnabImportPreviewDuplicateDetection Different Budget"}).Data.ID,
ImportHash: preview.Data[0].Transaction.ImportHash,
Amount: decimal.NewFromFloat(42.23),
Expand Down Expand Up @@ -194,7 +194,7 @@ func (suite *TestSuiteStandard) TestImportYnabImportPreviewV3FindAccounts() {
// Test envelope and test transaction to the Edeka account with an envelope to test the envelope prefill
envelope := suite.createTestEnvelope(models.EnvelopeCreate{CategoryID: suite.createTestCategory(models.CategoryCreate{BudgetID: budget.Data.ID}).Data.ID})
envelopeID := envelope.Data.ID
_ = suite.createTestTransactionV3(models.TransactionCreate{BudgetID: budget.Data.ID, SourceAccountID: internalAccount.Data.ID, DestinationAccountID: edeka.Data.ID, EnvelopeID: &envelopeID, Amount: decimal.NewFromFloat(12.00)})
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{BudgetID: budget.Data.ID, SourceAccountID: internalAccount.Data.ID, DestinationAccountID: edeka.Data.ID, EnvelopeID: &envelopeID, Amount: decimal.NewFromFloat(12.00)})

tests := []struct {
name string // Name of the test
Expand Down Expand Up @@ -251,7 +251,7 @@ func (suite *TestSuiteStandard) TestImportYnabImportPreviewV3Match() {
// Test envelope and test transaction to the Edeka account with an envelope to test the envelope prefill
envelope := suite.createTestEnvelope(models.EnvelopeCreate{CategoryID: suite.createTestCategory(models.CategoryCreate{BudgetID: budget.Data.ID}).Data.ID})
envelopeID := envelope.Data.ID
_ = suite.createTestTransactionV3(models.TransactionCreate{BudgetID: budget.Data.ID, SourceAccountID: internalAccount.Data.ID, DestinationAccountID: edeka.Data.ID, EnvelopeID: &envelopeID, Amount: decimal.NewFromFloat(12.00)})
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{BudgetID: budget.Data.ID, SourceAccountID: internalAccount.Data.ID, DestinationAccountID: edeka.Data.ID, EnvelopeID: &envelopeID, Amount: decimal.NewFromFloat(12.00)})

tests := []struct {
name string // Name of the test
Expand Down
28 changes: 14 additions & 14 deletions pkg/controllers/transaction_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

// createTestTransactionV3 creates a test transactions via the v3 API.
func (suite *TestSuiteStandard) createTestTransactionV3(c models.TransactionCreate, expectedStatus ...int) controllers.TransactionResponseV3 {
func (suite *TestSuiteStandard) createTestTransactionV3(t *testing.T, c models.TransactionCreate, expectedStatus ...int) controllers.TransactionResponseV3 {
c = suite.defaultTransactionCreate(c)

// Default to 201 Created as expected status
Expand All @@ -26,8 +26,8 @@ func (suite *TestSuiteStandard) createTestTransactionV3(c models.TransactionCrea

reqBody := []models.TransactionCreate{c}

r := test.Request(suite.controller, suite.T(), http.MethodPost, "http://example.com/v3/transactions", reqBody)
assertHTTPStatus(suite.T(), &r, expectedStatus...)
r := test.Request(suite.controller, t, http.MethodPost, "http://example.com/v3/transactions", reqBody)
assertHTTPStatus(t, &r, expectedStatus...)

var tr controllers.TransactionCreateResponseV3
suite.decodeResponse(&r, &tr)
Expand Down Expand Up @@ -60,7 +60,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3Options() {
http.StatusNoContent,
"",
func() string {
return suite.createTestTransactionV3(models.TransactionCreate{Amount: decimal.NewFromFloat(31)}).Data.Links.Self
return suite.createTestTransactionV3(suite.T(), models.TransactionCreate{Amount: decimal.NewFromFloat(31)}).Data.Links.Self
},
},
}
Expand Down Expand Up @@ -118,20 +118,20 @@ func (suite *TestSuiteStandard) TestTransactionsV3DatabaseError() {
// not correctly sorted when multiple transactions occurred on a day. In that case, the
// oldest transaction would be at the bottom and not at the top.
func (suite *TestSuiteStandard) TestTransactionsV3Get() {
t1 := suite.createTestTransactionV3(models.TransactionCreate{
t1 := suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Amount: decimal.NewFromFloat(17.23),
Date: time.Date(2023, 11, 10, 10, 11, 12, 0, time.UTC),
})

_ = suite.createTestTransactionV3(models.TransactionCreate{
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Amount: decimal.NewFromFloat(23.42),
Date: time.Date(2023, 11, 10, 11, 12, 13, 0, time.UTC),
})

// Need to sleep 1 second because SQLite datetime only has second precision
time.Sleep(1 * time.Second)

t3 := suite.createTestTransactionV3(models.TransactionCreate{
t3 := suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Amount: decimal.NewFromFloat(44.05),
Date: time.Date(2023, 11, 10, 10, 11, 12, 0, time.UTC),
})
Expand Down Expand Up @@ -168,7 +168,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3GetFilter() {
e1ID := &e1.Data.ID
e2ID := &e2.Data.ID

_ = suite.createTestTransactionV3(models.TransactionCreate{
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Date: time.Date(2018, 9, 5, 17, 13, 29, 45256, time.UTC),
Amount: decimal.NewFromFloat(2.718),
Note: "This was an important expense",
Expand All @@ -181,7 +181,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3GetFilter() {
ReconciledDestination: false,
})

_ = suite.createTestTransactionV3(models.TransactionCreate{
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Date: time.Date(2016, 5, 1, 14, 13, 25, 584575, time.UTC),
Amount: decimal.NewFromFloat(11235.813),
Note: "Not important",
Expand All @@ -194,7 +194,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3GetFilter() {
ReconciledDestination: true,
})

_ = suite.createTestTransactionV3(models.TransactionCreate{
_ = suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Date: time.Date(2021, 2, 6, 5, 1, 0, 585, time.UTC),
Amount: decimal.NewFromFloat(2.718),
Note: "",
Expand Down Expand Up @@ -401,7 +401,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3GetSingle() {
http.StatusOK,
"",
func() string {
return suite.createTestTransactionV3(models.TransactionCreate{Amount: decimal.NewFromFloat(13.71)}).Data.Links.Self
return suite.createTestTransactionV3(suite.T(), models.TransactionCreate{Amount: decimal.NewFromFloat(13.71)}).Data.Links.Self
},
},
{
Expand Down Expand Up @@ -438,7 +438,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3Delete() {
{
"Standard deletion",
http.StatusNoContent,
suite.createTestTransactionV3(models.TransactionCreate{Amount: decimal.NewFromFloat(123.12)}).Data.ID.String(),
suite.createTestTransactionV3(suite.T(), models.TransactionCreate{Amount: decimal.NewFromFloat(123.12)}).Data.ID.String(),
},
{
"Does not exist",
Expand All @@ -464,7 +464,7 @@ func (suite *TestSuiteStandard) TestTransactionsV3Delete() {

// TestTransactionsV3UpdateFail verifies that transaction updates fail where they should.
func (suite *TestSuiteStandard) TestTransactionsV3UpdateFail() {
transaction := suite.createTestTransactionV3(models.TransactionCreate{Amount: decimal.NewFromFloat(584.42), Note: "Test note for transaction"})
transaction := suite.createTestTransactionV3(suite.T(), models.TransactionCreate{Amount: decimal.NewFromFloat(584.42), Note: "Test note for transaction"})

tests := []struct {
name string // Name for the test
Expand Down Expand Up @@ -534,7 +534,7 @@ func (suite *TestSuiteStandard) TestUpdateNonExistingTransactionV3() {
// TestTransactionsV3Update verifies that transaction updates are successful.
func (suite *TestSuiteStandard) TestTransactionsV3Update() {
envelope := suite.createTestEnvelope(models.EnvelopeCreate{})
transaction := suite.createTestTransactionV3(models.TransactionCreate{
transaction := suite.createTestTransactionV3(suite.T(), models.TransactionCreate{
Amount: decimal.NewFromFloat(23.14),
Note: "Test note for transaction",
BudgetID: suite.createTestBudgetV3(suite.T(), models.BudgetCreate{Name: "Testing budget for updating of outgoing transfer"}).Data.ID,
Expand Down

0 comments on commit d7dcd75

Please sign in to comment.