forked from dmjones/qif
-
Notifications
You must be signed in to change notification settings - Fork 0
/
investment_transaction_test.go
43 lines (32 loc) · 1.02 KB
/
investment_transaction_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: Apache-2.0
package qif
import (
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)
func TestCheckAction(t *testing.T) {
tx := &investmentTransaction{}
const action = "Sell"
err := tx.parseInvestmentTransactionField("N"+action, Config{})
require.NoError(t, err)
assert.Equal(t, action, tx.ActionString())
assert.Equal(t, ActionSell, tx.Action())
}
func TestCheckPrice(t *testing.T) {
tx := &investmentTransaction{}
const price = "23.49"
err := tx.parseInvestmentTransactionField("I"+price, Config{})
require.NoError(t, err)
priceDecimal, _ := decimal.NewFromString(price)
assert.Equal(t, true, priceDecimal.Equal(tx.Price()))
}
func TestCheckShares(t *testing.T) {
tx := &investmentTransaction{}
const shares = "401"
err := tx.parseInvestmentTransactionField("Q"+shares, Config{})
require.NoError(t, err)
sharesDecimal, _ := decimal.NewFromString(shares)
assert.Equal(t, true, sharesDecimal.Equal(tx.Shares()))
}