status-go/multiaccounts/settings/sync_protobuf_factories_test.go
Sale Djenic 1340a55c1d feat: backup profile data to waku and sync them from waku
Changes applied here introduce backing up profile data (display name and identity
images) to waku and fetch them from waku. Information about those data is sent
as a separate signal to a client via `sync.from.waku.profile` signal.

New signal `sync.from.waku.progress` is introduced which will be used to notify a client
about the progress of fetching data from waku.
2022-12-23 15:07:14 +01:00

59 lines
1.5 KiB
Go

package settings
import (
"encoding/json"
"testing"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/protocol/protobuf"
)
type testCriteria struct {
Name string
Input inputCriteria
Expected expectedCriteria
}
type inputCriteria struct {
Value interface{}
Clock uint64
}
type expectedCriteria struct {
Value int64
Clock uint64
AMT protobuf.ApplicationMetadataMessage_Type
}
func TestProfilePicturesVisibilityProtobufFactory(t *testing.T) {
var v interface{}
err := json.Unmarshal([]byte(`3`), &v)
require.NoError(t, err)
expected := expectedCriteria{3, 123, protobuf.ApplicationMetadataMessage_SYNC_SETTING}
cs := []testCriteria{
{"json.Unmarshal int into interface{}", inputCriteria{Value: v, Clock: 123}, expected},
{"ProfilePicturesVisibilityType", inputCriteria{Value: ProfilePicturesVisibilityNone, Clock: 123}, expected},
{"int64", inputCriteria{Value: int64(3), Clock: 123}, expected},
}
for _, c := range cs {
a := require.New(t)
rm, _, err := profilePicturesVisibilityProtobufFactory(c.Input.Value, c.Input.Clock, "0x123def")
a.NoError(err, c.Name)
ppvp := new(protobuf.SyncSetting)
err = proto.Unmarshal(rm.Payload, ppvp)
a.NoError(err, c.Name)
a.Equal(protobuf.SyncSetting_PROFILE_PICTURES_VISIBILITY, ppvp.Type, c.Name)
a.Equal(c.Expected.Value, ppvp.GetValueInt64(), c.Name)
a.Equal(c.Expected.Clock, ppvp.Clock, c.Name)
a.Equal(c.Expected.AMT, rm.MessageType, c.Name)
}
}