github.com/bitfinexcom/bitfinex-api-go@v0.0.0-20210608095005-9e0b26f200fb/pkg/models/pulse/pulse_test.go (about) 1 package pulse_test 2 3 import ( 4 "testing" 5 6 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/pulse" 7 "github.com/bitfinexcom/bitfinex-api-go/pkg/models/pulseprofile" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestNewPulseFromRaw(t *testing.T) { 13 t.Run("insufficient arguments", func(t *testing.T) { 14 payload := []interface{}{ 15 []interface{}{"abc123"}, 16 } 17 18 pm, err := pulse.SnapshotFromRaw(payload) 19 require.NotNil(t, err) 20 require.Nil(t, pm) 21 }) 22 23 t.Run("missing pulse profile", func(t *testing.T) { 24 payload := []interface{}{ 25 []interface{}{ 26 "d139512a-6558-431a-a6aa-69646fc97d55", 27 1593608548140, 28 nil, 29 "bf324e24-5a09-4317-b418-6c37281ab855", 30 nil, 31 "Take an active role in the discussion with the Comment feature!", 32 "Bitfinex Pulse, the social trading you were waiting for, keeps improving to give you a complete social trading experience.", 33 nil, 34 nil, 35 1, 36 1, 37 nil, 38 []interface{}{"BitfinexPulse", "PulseFeatures", "PulseUpdates", "L_EN", "N_Bitfinex"}, 39 []interface{}{"image-a55eda4c-4f5a-4609-abf0-7bdfca1a8911-1593608547535-size.jpg"}, 40 []interface{}{}, 41 1, 42 nil, 43 nil, 44 nil, 45 1, 46 nil, 47 nil, 48 }, 49 } 50 51 pm, err := pulse.SnapshotFromRaw(payload) 52 require.Nil(t, err) 53 54 expected := &pulse.Pulse{ 55 ID: "d139512a-6558-431a-a6aa-69646fc97d55", 56 MTS: 1593608548140, 57 UserID: "bf324e24-5a09-4317-b418-6c37281ab855", 58 Title: "Take an active role in the discussion with the Comment feature!", 59 Content: "Bitfinex Pulse, the social trading you were waiting for, keeps improving to give you a complete social trading experience.", 60 IsPin: 1, 61 IsPublic: 1, 62 CommentsDisabled: 0, 63 Tags: []string{"BitfinexPulse", "PulseFeatures", "PulseUpdates", "L_EN", "N_Bitfinex"}, 64 Attachments: []string{"image-a55eda4c-4f5a-4609-abf0-7bdfca1a8911-1593608547535-size.jpg"}, 65 Likes: 1, 66 Comments: 1, 67 } 68 69 assert.Equal(t, expected, pm[0]) 70 }) 71 72 t.Run("has pulse profile", func(t *testing.T) { 73 payload := []interface{}{ 74 []interface{}{ 75 "d139512a-6558-431a-a6aa-69646fc97d55", 76 1593608548140, 77 nil, 78 "bf324e24-5a09-4317-b418-6c37281ab855", 79 nil, 80 "Take an active role in the discussion with the Comment feature!", 81 "Bitfinex Pulse, the social trading you were waiting for, keeps improving to give you a complete social trading experience.", 82 nil, 83 nil, 84 1, 85 1, 86 nil, 87 []interface{}{"BitfinexPulse", "PulseFeatures", "PulseUpdates", "L_EN", "N_Bitfinex"}, 88 []interface{}{"image-a55eda4c-4f5a-4609-abf0-7bdfca1a8911-1593608547535-size.jpg"}, 89 []interface{}{}, 90 1, 91 nil, 92 nil, 93 []interface{}{ 94 []interface{}{ 95 "bf324e24-5a09-4317-b418-6c37281ab855", 96 1591614631576, 97 nil, 98 "Bitfinex", 99 nil, 100 "image-33533a4d-a796-4afe-9b8b-690bc7075e05-1587476823358-size.png", 101 "Bitfinex is the world’s leading digital asset trading platform.", 102 nil, 103 nil, 104 "bitfinex", 105 nil, 106 40, 107 5, 108 nil, 109 nil, 110 nil, 111 0, 112 }, 113 }, 114 1, 115 nil, 116 nil, 117 }, 118 } 119 120 pm, err := pulse.SnapshotFromRaw(payload) 121 require.Nil(t, err) 122 123 expected := &pulse.Pulse{ 124 ID: "d139512a-6558-431a-a6aa-69646fc97d55", 125 MTS: 1593608548140, 126 UserID: "bf324e24-5a09-4317-b418-6c37281ab855", 127 Title: "Take an active role in the discussion with the Comment feature!", 128 Content: "Bitfinex Pulse, the social trading you were waiting for, keeps improving to give you a complete social trading experience.", 129 IsPin: 1, 130 IsPublic: 1, 131 CommentsDisabled: 0, 132 Tags: []string{"BitfinexPulse", "PulseFeatures", "PulseUpdates", "L_EN", "N_Bitfinex"}, 133 Attachments: []string{"image-a55eda4c-4f5a-4609-abf0-7bdfca1a8911-1593608547535-size.jpg"}, 134 Likes: 1, 135 Comments: 1, 136 PulseProfile: &pulseprofile.PulseProfile{ 137 ID: "bf324e24-5a09-4317-b418-6c37281ab855", 138 MTS: 1591614631576, 139 Nickname: "Bitfinex", 140 Picture: "image-33533a4d-a796-4afe-9b8b-690bc7075e05-1587476823358-size.png", 141 Text: "Bitfinex is the world’s leading digital asset trading platform.", 142 TwitterHandle: "bitfinex", 143 Followers: 40, 144 Following: 5, 145 TippingStatus: 0, 146 }, 147 } 148 149 assert.Equal(t, expected, pm[0]) 150 }) 151 }