2024-10-29 12:30:14 +00:00
|
|
|
package statusgo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2024-11-29 10:33:36 +00:00
|
|
|
"github.com/brianvoe/gofakeit/v6"
|
|
|
|
|
2024-10-29 12:30:14 +00:00
|
|
|
"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")
|
|
|
|
}
|
2024-11-29 10:33:36 +00:00
|
|
|
|
|
|
|
func TestIntendedPanic(t *testing.T) {
|
|
|
|
message := gofakeit.LetterN(5)
|
|
|
|
require.PanicsWithError(t, message, func() {
|
|
|
|
IntendedPanic(message)
|
|
|
|
})
|
|
|
|
}
|