github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/trades/authfundingtrades_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 TestAuthFundingTradeFromRaw(t *testing.T) {
    11  	cases := map[string]struct {
    12  		pld      []interface{}
    13  		expected trades.AuthFundingTrade
    14  		err      func(*testing.T, error)
    15  	}{
    16  		"invalid payload": {
    17  			pld:      []interface{}{636854},
    18  			expected: trades.AuthFundingTrade{},
    19  			err: func(t *testing.T, err error) {
    20  				assert.Error(t, err)
    21  			},
    22  		},
    23  		"valid payload": {
    24  			pld: []interface{}{636854, "fUSD", 1575282446000, 41238905, -1000, 0.002, 7, nil},
    25  			expected: trades.AuthFundingTrade{
    26  				ID:         636854,
    27  				Symbol:     "fUSD",
    28  				MTSCreated: 1575282446000,
    29  				OfferID:    41238905,
    30  				Amount:     -1000,
    31  				Rate:       0.002,
    32  				Period:     7,
    33  				Maker:      0,
    34  			},
    35  			err: func(t *testing.T, err error) {
    36  				assert.NoError(t, err)
    37  			},
    38  		},
    39  	}
    40  
    41  	for k, v := range cases {
    42  		t.Run(k, func(t *testing.T) {
    43  			got, err := trades.AFTFromRaw(v.pld)
    44  			v.err(t, err)
    45  			assert.Equal(t, v.expected, got)
    46  		})
    47  	}
    48  }
    49  
    50  func TestAuthFundingTradeUpdateFromRaw(t *testing.T) {
    51  	cases := map[string]struct {
    52  		pld      []interface{}
    53  		expected trades.AuthFundingTradeUpdate
    54  		err      func(*testing.T, error)
    55  	}{
    56  		"invalid payload": {
    57  			pld:      []interface{}{636854},
    58  			expected: trades.AuthFundingTradeUpdate{},
    59  			err: func(t *testing.T, err error) {
    60  				assert.Error(t, err)
    61  			},
    62  		},
    63  		"valid payload": {
    64  			pld: []interface{}{636854, "fUSD", 1575282446000, 41238905, -1000, 0.002, 7, nil},
    65  			expected: trades.AuthFundingTradeUpdate{
    66  				ID:         636854,
    67  				Symbol:     "fUSD",
    68  				MTSCreated: 1575282446000,
    69  				OfferID:    41238905,
    70  				Amount:     -1000,
    71  				Rate:       0.002,
    72  				Period:     7,
    73  				Maker:      0,
    74  			},
    75  			err: func(t *testing.T, err error) {
    76  				assert.NoError(t, err)
    77  			},
    78  		},
    79  	}
    80  
    81  	for k, v := range cases {
    82  		t.Run(k, func(t *testing.T) {
    83  			got, err := trades.AFTUFromRaw(v.pld)
    84  			v.err(t, err)
    85  			assert.Equal(t, v.expected, got)
    86  		})
    87  	}
    88  }
    89  
    90  func TestAuthFundingTradeExecutionFromRaw(t *testing.T) {
    91  	cases := map[string]struct {
    92  		pld      []interface{}
    93  		expected trades.AuthFundingTradeExecuted
    94  		err      func(*testing.T, error)
    95  	}{
    96  		"invalid payload": {
    97  			pld:      []interface{}{636854},
    98  			expected: trades.AuthFundingTradeExecuted{},
    99  			err: func(t *testing.T, err error) {
   100  				assert.Error(t, err)
   101  			},
   102  		},
   103  		"valid payload": {
   104  			pld: []interface{}{636854, "fUSD", 1575282446000, 41238905, -1000, 0.002, 7, nil},
   105  			expected: trades.AuthFundingTradeExecuted{
   106  				ID:         636854,
   107  				Symbol:     "fUSD",
   108  				MTSCreated: 1575282446000,
   109  				OfferID:    41238905,
   110  				Amount:     -1000,
   111  				Rate:       0.002,
   112  				Period:     7,
   113  				Maker:      0,
   114  			},
   115  			err: func(t *testing.T, err error) {
   116  				assert.NoError(t, err)
   117  			},
   118  		},
   119  	}
   120  
   121  	for k, v := range cases {
   122  		t.Run(k, func(t *testing.T) {
   123  			got, err := trades.AFTEFromRaw(v.pld)
   124  			v.err(t, err)
   125  			assert.Equal(t, v.expected, got)
   126  		})
   127  	}
   128  }
   129  
   130  func TestAuthFundingTradeSnapshotFromRaw(t *testing.T) {
   131  	cases := map[string]struct {
   132  		pld      [][]interface{}
   133  		expected trades.AuthFundingTradeSnapshot
   134  		err      func(*testing.T, error)
   135  	}{
   136  		"invalid payload": {
   137  			pld:      [][]interface{}{},
   138  			expected: trades.AuthFundingTradeSnapshot{},
   139  			err: func(t *testing.T, err error) {
   140  				assert.Error(t, err)
   141  			},
   142  		},
   143  		"valid payload": {
   144  			pld: [][]interface{}{{
   145  				636854, "fUSD", 1575282446000, 41238905, -1000, 0.002, 7, nil,
   146  			}},
   147  			expected: trades.AuthFundingTradeSnapshot{
   148  				Snapshot: []trades.AuthFundingTrade{
   149  					{
   150  						ID:         636854,
   151  						Symbol:     "fUSD",
   152  						MTSCreated: 1575282446000,
   153  						OfferID:    41238905,
   154  						Amount:     -1000,
   155  						Rate:       0.002,
   156  						Period:     7,
   157  						Maker:      0,
   158  					},
   159  				},
   160  			},
   161  			err: func(t *testing.T, err error) {
   162  				assert.NoError(t, err)
   163  			},
   164  		},
   165  	}
   166  
   167  	for k, v := range cases {
   168  		t.Run(k, func(t *testing.T) {
   169  			got, err := trades.AFTSnapshotFromRaw(v.pld)
   170  			v.err(t, err)
   171  			assert.Equal(t, v.expected, got)
   172  		})
   173  	}
   174  }