41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
|
package statusgo
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
|
||
|
"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")
|
||
|
}
|