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

     1  package fundingtrade_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/bitfinexcom/bitfinex-api-go/pkg/models/fundingtrade"
     7  	"github.com/stretchr/testify/assert"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func TestNewFundingTradeFromRaw(t *testing.T) {
    12  	t.Run("invalid arguments", func(t *testing.T) {
    13  		payload := []interface{}{636040}
    14  
    15  		got, err := fundingtrade.FromRaw(payload)
    16  		require.NotNil(t, err)
    17  		require.Nil(t, got)
    18  	})
    19  
    20  	t.Run("valid arguments", func(t *testing.T) {
    21  		payload := []interface{}{
    22  			636040,
    23  			"fUST",
    24  			1574077528000,
    25  			41237922,
    26  			-100,
    27  			0.0024,
    28  			2,
    29  			nil,
    30  		}
    31  
    32  		got, err := fundingtrade.FromRaw(payload)
    33  		require.Nil(t, err)
    34  
    35  		expected := &fundingtrade.FundingTrade{
    36  			ID:         636040,
    37  			Symbol:     "fUST",
    38  			MTSCreated: 1574077528000,
    39  			OfferID:    41237922,
    40  			Amount:     -100,
    41  			Rate:       0.0024,
    42  			Period:     2,
    43  			Maker:      0,
    44  		}
    45  		assert.Equal(t, expected, got)
    46  	})
    47  }
    48  
    49  func TestFundingTradeSnapshotFromRaw(t *testing.T) {
    50  	t.Run("invalid arguments", func(t *testing.T) {
    51  		payload := []interface{}{}
    52  		got, err := fundingtrade.SnapshotFromRaw(payload)
    53  		require.NotNil(t, err)
    54  		require.Nil(t, got)
    55  	})
    56  
    57  	t.Run("partially valid arguments", func(t *testing.T) {
    58  		payload := []interface{}{
    59  			[]interface{}{
    60  				636040,
    61  				"fUST",
    62  				1574077528000,
    63  				41237922,
    64  				-100,
    65  				0.0024,
    66  				2,
    67  				nil,
    68  			},
    69  			[]interface{}{636041},
    70  		}
    71  		got, err := fundingtrade.SnapshotFromRaw(payload)
    72  		require.NotNil(t, err)
    73  		require.Nil(t, got)
    74  	})
    75  
    76  	t.Run("valid arguments", func(t *testing.T) {
    77  		payload := []interface{}{
    78  			[]interface{}{
    79  				636040,
    80  				"fUST",
    81  				1574077528000,
    82  				41237922,
    83  				-100,
    84  				0.0024,
    85  				2,
    86  				nil,
    87  			},
    88  			[]interface{}{
    89  				636041,
    90  				"fUST",
    91  				1574077528000,
    92  				41237922,
    93  				-100,
    94  				0.0025,
    95  				2,
    96  				nil,
    97  			},
    98  		}
    99  
   100  		got, err := fundingtrade.SnapshotFromRaw(payload)
   101  		require.Nil(t, err)
   102  
   103  		expected := &fundingtrade.Snapshot{
   104  			Snapshot: []*fundingtrade.FundingTrade{
   105  				{
   106  					ID:         636040,
   107  					Symbol:     "fUST",
   108  					MTSCreated: 1574077528000,
   109  					OfferID:    41237922,
   110  					Amount:     -100,
   111  					Rate:       0.0024,
   112  					Period:     2,
   113  					Maker:      0,
   114  				},
   115  				{
   116  					ID:         636041,
   117  					Symbol:     "fUST",
   118  					MTSCreated: 1574077528000,
   119  					OfferID:    41237922,
   120  					Amount:     -100,
   121  					Rate:       0.0025,
   122  					Period:     2,
   123  					Maker:      0,
   124  				},
   125  			},
   126  		}
   127  
   128  		assert.Equal(t, expected, got)
   129  	})
   130  }