status-go/mobile/status_test.go

50 lines
1.3 KiB
Go

package statusgo
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/brianvoe/gofakeit/v6"
"github.com/status-im/status-go/multiaccounts"
"github.com/status-im/status-go/multiaccounts/settings"
"github.com/status-im/status-go/signal"
)
type testSignalHandler struct {
receivedSignal string
}
func (t *testSignalHandler) HandleSignal(data string) {
t.receivedSignal = data
}
func TestSetMobileSignalHandler(t *testing.T) {
// Setup
handler := &testSignalHandler{}
SetMobileSignalHandler(handler)
t.Cleanup(signal.ResetMobileSignalHandler)
// Test data
testAccount := &multiaccounts.Account{Name: "test"}
testSettings := &settings.Settings{KeyUID: "0x1"}
testEnsUsernames := json.RawMessage(`{"test": "test"}`)
// Action
signal.SendLoggedIn(testAccount, testSettings, testEnsUsernames, nil)
// Assertions
require.Contains(t, handler.receivedSignal, `"key-uid":"0x1"`, "Signal should contain the correct KeyUID")
require.Contains(t, handler.receivedSignal, `"name":"test"`, "Signal should contain the correct account name")
require.Contains(t, handler.receivedSignal, `"ensUsernames":{"test":"test"}`, "Signal should contain the correct ENS usernames")
}
func TestIntendedPanic(t *testing.T) {
message := gofakeit.LetterN(5)
require.PanicsWithError(t, message, func() {
IntendedPanic(message)
})
}