@@ -321,6 +321,75 @@ func TestUpdateTransaction(t *testing.T) {
321321 assert .EqualValues (t , "-20.5" , updatedAccounts [1 ].CurrentBalance .String ())
322322}
323323
324+ func TestBasicIncome (t * testing.T ) {
325+ assert .NoError (t , testingutils .FlushAllTables (cfg .Db ))
326+
327+ statsSvc := transactions .NewStatService ()
328+ mapper := NewMockMapperSvc (gomock .NewController (t ))
329+
330+ mapper .EXPECT ().MapTransaction (gomock .Any (), gomock .Any ()).
331+ Return (& gomoneypbv1.Transaction {})
332+
333+ ruleEngine := NewMockRuleSvc (gomock .NewController (t ))
334+ ruleEngine .EXPECT ().ProcessTransactions (gomock .Any (), gomock .Any ()).
335+ DoAndReturn (func (ctx context.Context , i []* database.Transaction ) ([]* database.Transaction , error ) {
336+ assert .Len (t , i , 1 )
337+ return i , nil
338+ })
339+
340+ baseCurrency := transactions .NewBaseAmountService ("USD" )
341+ accountSvc := NewMockAccountSvc (gomock .NewController (t ))
342+ validationSvc := NewMockValidationSvc (gomock .NewController (t ))
343+ doubleEntry := NewMockDoubleEntrySvc (gomock .NewController (t ))
344+
345+ srv := transactions .NewService (& transactions.ServiceConfig {
346+ StatsSvc : statsSvc ,
347+ MapperSvc : mapper ,
348+ BaseAmountService : baseCurrency ,
349+ RuleSvc : ruleEngine ,
350+ AccountSvc : accountSvc ,
351+ ValidationSvc : validationSvc ,
352+ DoubleEntry : doubleEntry ,
353+ })
354+
355+ accounts := []* database.Account {
356+ {
357+ Name : "Asset 1" ,
358+ Currency : "USD" ,
359+ Extra : map [string ]string {},
360+ },
361+ {
362+ Name : "Income 1" ,
363+ Currency : "USD" ,
364+ Extra : map [string ]string {},
365+ },
366+ }
367+ assert .NoError (t , gormDB .Create (& accounts ).Error )
368+
369+ accountSvc .EXPECT ().GetAllAccounts (gomock .Any ()).Return (accounts , nil )
370+ validationSvc .EXPECT ().Validate (gomock .Any (), gomock .Any (), gomock .Any ()).
371+ Return (nil )
372+ doubleEntry .EXPECT ().Record (gomock .Any (), gomock .Any (), gomock .Any (), gomock .Any ()).
373+ Return (nil )
374+
375+ depositDate2 := time .Date (2025 , 6 , 7 , 0 , 0 , 0 , 0 , time .UTC )
376+ _ , err := srv .Create (context .TODO (), & transactionsv1.CreateTransactionRequest {
377+ TransactionDate : timestamppb .New (depositDate2 ),
378+ Transaction : & transactionsv1.CreateTransactionRequest_Income {
379+ Income : & transactionsv1.Income {
380+ DestinationAmount : "100" ,
381+ DestinationCurrency : "USD" ,
382+ DestinationAccountId : accounts [0 ].ID ,
383+
384+ SourceAmount : "-100" ,
385+ SourceCurrency : "USD" ,
386+ SourceAccountId : accounts [1 ].ID ,
387+ },
388+ },
389+ })
390+ assert .NoError (t , err )
391+ }
392+
324393func TestBasicCalc (t * testing.T ) {
325394 assert .NoError (t , testingutils .FlushAllTables (cfg .Db ))
326395
0 commit comments