Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayswind committed Oct 28, 2024
1 parent a1b7c8a commit bde0b01
Showing 1 changed file with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func TestGnuCashTransactionDatabaseFileParseImportedData_ParseValidAccountCurren
assert.Equal(t, "EUR", allNewAccounts[1].Currency)
}

func TestGnuCashTransactionDatabaseFileParseImportedData_ParseAmount(t *testing.T) {
func TestGnuCashTransactionDatabaseFileParseImportedData_ParseValidAmount(t *testing.T) {
converter := GnuCashTransactionDataImporter
context := core.NewNullContext()

Expand Down Expand Up @@ -629,6 +629,76 @@ func TestGnuCashTransactionDatabaseFileParseImportedData_ParseAmount(t *testing.
assert.Equal(t, int64(1234), allNewTransactions[0].Amount)
}

func TestGnuCashTransactionDatabaseFileParseImportedData_ParseInvalidAmount(t *testing.T) {
converter := GnuCashTransactionDataImporter
context := core.NewNullContext()

user := &models.User{
Uid: 1234567890,
DefaultCurrency: "CNY",
}

_, _, _, _, _, _, err := converter.ParseImportedData(context, user, []byte(
gnucashCommonValidDataCaseHeader+
"<gnc:transaction version=\"2.0.0\">\n"+
" <trn:date-posted>\n"+
" <ts:date>2024-09-01 12:34:56 +0000</ts:date>\n"+
" </trn:date-posted>\n"+
" <trn:splits>\n"+
" <trn:split>\n"+
" <split:quantity>/</split:quantity>\n"+
" <split:account type=\"guid\">00000000000000000000000000001000</split:account>\n"+
" </trn:split>\n"+
" <trn:split>\n"+
" <split:quantity>/</split:quantity>\n"+
" <split:account type=\"guid\">00000000000000000000000000000010</split:account>\n"+
" </trn:split>\n"+
" </trn:splits>\n"+
"</gnc:transaction>\n"+
gnucashCommonValidDataCaseFooter), 0, nil, nil, nil, nil, nil)
assert.EqualError(t, err, errs.ErrAmountInvalid.Message)

_, _, _, _, _, _, err = converter.ParseImportedData(context, user, []byte(
gnucashCommonValidDataCaseHeader+
"<gnc:transaction version=\"2.0.0\">\n"+
" <trn:date-posted>\n"+
" <ts:date>2024-09-01 12:34:56 +0000</ts:date>\n"+
" </trn:date-posted>\n"+
" <trn:splits>\n"+
" <trn:split>\n"+
" <split:quantity>12345</split:quantity>\n"+
" <split:account type=\"guid\">00000000000000000000000000001000</split:account>\n"+
" </trn:split>\n"+
" <trn:split>\n"+
" <split:quantity>-12345</split:quantity>\n"+
" <split:account type=\"guid\">00000000000000000000000000000010</split:account>\n"+
" </trn:split>\n"+
" </trn:splits>\n"+
"</gnc:transaction>\n"+
gnucashCommonValidDataCaseFooter), 0, nil, nil, nil, nil, nil)
assert.EqualError(t, err, errs.ErrAmountInvalid.Message)

_, _, _, _, _, _, err = converter.ParseImportedData(context, user, []byte(
gnucashCommonValidDataCaseHeader+
"<gnc:transaction version=\"2.0.0\">\n"+
" <trn:date-posted>\n"+
" <ts:date>2024-09-01 12:34:56 +0000</ts:date>\n"+
" </trn:date-posted>\n"+
" <trn:splits>\n"+
" <trn:split>\n"+
" <split:quantity>12345/</split:quantity>\n"+
" <split:account type=\"guid\">00000000000000000000000000001000</split:account>\n"+
" </trn:split>\n"+
" <trn:split>\n"+
" <split:quantity>-12345/</split:quantity>\n"+
" <split:account type=\"guid\">00000000000000000000000000000010</split:account>\n"+
" </trn:split>\n"+
" </trn:splits>\n"+
"</gnc:transaction>\n"+
gnucashCommonValidDataCaseFooter), 0, nil, nil, nil, nil, nil)
assert.EqualError(t, err, errs.ErrAmountInvalid.Message)
}

func TestGnuCashTransactionDatabaseFileParseImportedData_ParseDescription(t *testing.T) {
converter := GnuCashTransactionDataImporter
context := core.NewNullContext()
Expand Down

0 comments on commit bde0b01

Please sign in to comment.