github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/trades/authtradeexecution_test.go (about)

     1  package trades_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/trades"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestAuthenticatedTradeExecutionFromRaw(t *testing.T) {
    11  	cases := map[string]struct {
    12  		pld      []interface{}
    13  		expected trades.AuthTradeExecution
    14  		err      func(*testing.T, error)
    15  	}{
    16  		"invalid payload": {
    17  			pld:      []interface{}{402088407},
    18  			expected: trades.AuthTradeExecution{},
    19  			err: func(t *testing.T, err error) {
    20  				assert.Error(t, err)
    21  			},
    22  		},
    23  		"valid payload": {
    24  			pld: []interface{}{
    25  				402088407, "tETHUST", 1574963975602, 34938060782,
    26  				-0.2, 153.57, "MARKET", 0, -1, nil, nil, 0,
    27  			},
    28  			expected: trades.AuthTradeExecution{
    29  				ID:            402088407,
    30  				Pair:          "tETHUST",
    31  				MTS:           1574963975602,
    32  				OrderID:       34938060782,
    33  				ExecAmount:    -0.2,
    34  				ExecPrice:     153.57,
    35  				OrderType:     "MARKET",
    36  				OrderPrice:    0,
    37  				Maker:         -1,
    38  				ClientOrderID: 0,
    39  			},
    40  			err: func(t *testing.T, err error) {
    41  				assert.NoError(t, err)
    42  			},
    43  		},
    44  	}
    45  
    46  	for k, v := range cases {
    47  		t.Run(k, func(t *testing.T) {
    48  			got, err := trades.ATEFromRaw(v.pld)
    49  			v.err(t, err)
    50  			assert.Equal(t, v.expected, got)
    51  		})
    52  	}
    53  }