mirror of
				https://github.com/aclindsa/moneygo.git
				synced 2025-11-03 18:13:27 -05:00 
			
		
		
		
	testing: Add test for fetching transactions/splits
This commit is contained in:
		@@ -53,6 +53,86 @@ func TestCreateTransaction(t *testing.T) {
 | 
				
			|||||||
			if transaction.Date != orig.Date {
 | 
								if transaction.Date != orig.Date {
 | 
				
			||||||
				t.Errorf("Date doesn't match")
 | 
									t.Errorf("Date doesn't match")
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if len(transaction.Splits) != len(orig.Splits) {
 | 
				
			||||||
 | 
									t.Fatalf("Expected %d splits, received %d", len(orig.Splits), len(transaction.Splits))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								foundIds := make(map[int64]bool)
 | 
				
			||||||
 | 
								for j := 0; j < len(orig.Splits); j++ {
 | 
				
			||||||
 | 
									origsplit := orig.Splits[j]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if transaction.Splits[j].TransactionId != transaction.TransactionId {
 | 
				
			||||||
 | 
										t.Fatalf("Split TransactionId doesn't match transaction's")
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									found := false
 | 
				
			||||||
 | 
									for _, s := range transaction.Splits {
 | 
				
			||||||
 | 
										if origsplit.Status == s.Status && origsplit.ImportSplitType == s.ImportSplitType && s.AccountId == d.accounts[origsplit.AccountId].AccountId && s.SecurityId == -1 && origsplit.RemoteId == origsplit.RemoteId && origsplit.Number == s.Number && origsplit.Memo == s.Memo && origsplit.Amount == s.Amount {
 | 
				
			||||||
 | 
											if _, ok := foundIds[s.SplitId]; ok {
 | 
				
			||||||
 | 
												continue
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											foundIds[s.SplitId] = true
 | 
				
			||||||
 | 
											found = true
 | 
				
			||||||
 | 
											break
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if !found {
 | 
				
			||||||
 | 
										t.Errorf("Unable to find matching split: %+v", origsplit)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestGetTransaction(t *testing.T) {
 | 
				
			||||||
 | 
						RunWith(t, &data[0], func(t *testing.T, d *TestData) {
 | 
				
			||||||
 | 
							for i := 0; i < len(data[0].transactions); i++ {
 | 
				
			||||||
 | 
								orig := data[0].transactions[i]
 | 
				
			||||||
 | 
								curr := d.transactions[i]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								tran, err := getTransaction(d.clients[orig.UserId], curr.TransactionId)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									t.Fatalf("Error fetching transaction: %s\n", err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if tran.TransactionId != curr.TransactionId {
 | 
				
			||||||
 | 
									t.Errorf("TransactionId doesn't match")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if tran.Description != orig.Description {
 | 
				
			||||||
 | 
									t.Errorf("Description doesn't match")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								if tran.Date != orig.Date {
 | 
				
			||||||
 | 
									t.Errorf("Date doesn't match")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if len(tran.Splits) != len(orig.Splits) {
 | 
				
			||||||
 | 
									t.Fatalf("Expected %d splits, received %d", len(orig.Splits), len(tran.Splits))
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								foundIds := make(map[int64]bool)
 | 
				
			||||||
 | 
								for j := 0; j < len(orig.Splits); j++ {
 | 
				
			||||||
 | 
									origsplit := orig.Splits[j]
 | 
				
			||||||
 | 
									currsplit := curr.Splits[j]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if tran.Splits[j].TransactionId != tran.TransactionId {
 | 
				
			||||||
 | 
										t.Fatalf("Split TransactionId doesn't match transaction's")
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									found := false
 | 
				
			||||||
 | 
									for _, s := range tran.Splits {
 | 
				
			||||||
 | 
										if origsplit.Status == s.Status && origsplit.ImportSplitType == s.ImportSplitType && currsplit.AccountId == s.AccountId && currsplit.SecurityId == s.SecurityId && origsplit.RemoteId == origsplit.RemoteId && origsplit.Number == s.Number && origsplit.Memo == s.Memo && origsplit.Amount == s.Amount {
 | 
				
			||||||
 | 
											if _, ok := foundIds[s.SplitId]; ok {
 | 
				
			||||||
 | 
												continue
 | 
				
			||||||
 | 
											}
 | 
				
			||||||
 | 
											foundIds[s.SplitId] = true
 | 
				
			||||||
 | 
											found = true
 | 
				
			||||||
 | 
											break
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									if !found {
 | 
				
			||||||
 | 
										t.Errorf("Unable to find matching split: %+v", curr)
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user