moonmath/bitcoinity/model_test.go
Sam Fredrickson ac1a4bc16c
All checks were successful
Build & Test / Main (push) Successful in 57s
Move Bitcoinity websocket capture, and test it.
2024-03-21 12:31:40 -07:00

45 lines
1012 B
Go

package bitcoinity_test
import (
_ "embed"
"encoding/json"
"testing"
"code.humancabbage.net/sam/moonmath/bitcoinity"
)
func TestUnmarshalGetTickerResponse(t *testing.T) {
var resp bitcoinity.GetTickerResponse
err := json.Unmarshal(getTickerJson, &resp)
if err != nil {
t.Errorf("failed to unmarshal get_ticker JSON: %v", err)
}
if resp.TickerLife != 604800 {
t.Errorf("expected TickerLife == 604800, not %v", resp.TickerLife)
}
}
//go:embed get_ticker.json
var getTickerJson []byte
func TestUnmarshalWebhookMessages(t *testing.T) {
var msgs []bitcoinity.Message
err := json.Unmarshal(capturedJson, &msgs)
if err != nil {
t.Errorf("failed to unmarshal webhook messages JSON: %v", err)
}
for _, msg := range msgs {
if msg.Event != "new_msg" {
continue
}
var payload bitcoinity.MarketPayload
err := json.Unmarshal(msg.Payload, &payload)
if err != nil {
t.Errorf("failed to unmarshal market payload JSON: %v", err)
}
}
}
//go:embed captured.json
var capturedJson []byte