meowlib/contactcard_test.go

66 lines
4.9 KiB
Go
Raw Normal View History

package meowlib
import (
2024-01-03 23:11:23 +01:00
"encoding/json"
"testing"
2023-12-31 23:28:10 +01:00
"github.com/stretchr/testify/assert"
)
2024-01-03 23:11:23 +01:00
func TestCompressAndJson(t *testing.T) {
kp1 := NewKeyPair()
kp2 := NewKeyPair()
kp3 := NewKeyPair()
var cc ContactCard
cc.Name = "My Full Name And It's loooong"
cc.ContactPublicKey = kp1.Public
cc.EncryptionPublicKey = kp2.Public
cc.LookupPublicKey = kp3.Public
2024-01-01 22:45:54 +01:00
cc.InvitationMessage = "hello, it's me"
cc.AddUrls([]string{"https://meow.myfirstdomain.com/services/meow:8080", "https://meow.myseconddomain.com/services/meow:8080", "http://meow.mythirddomain.com/services/meow:8080"})
serialized, _ := cc.Serialize()
println(len(serialized))
compressed, _ := cc.Compress()
println(len(compressed))
2023-12-31 23:28:10 +01:00
ncc, err := NewContactCardFromCompressed(compressed)
if err != nil {
println(err)
}
assert.Equal(t, ncc.Name, cc.Name)
2024-01-03 23:11:23 +01:00
if err != nil {
println(err)
}
jsoncc, err := json.Marshal(cc)
var cc1 ContactCard
err = json.Unmarshal(jsoncc, &cc1)
if err != nil {
println(err)
}
}
func TestStaticJson(t *testing.T) {
ccsrt := `
{
"contact_public_key": "LS0tLS1CRUdJTiBQR1AgUFVCTElDIEtFWSBCTE9DSy0tLS0tClZlcnNpb246IEdvcGVuUEdQIDIuNy40CkNvbW1lbnQ6IGh0dHBzOi8vZ29wZW5wZ3Aub3JnCgp4ak1FWlpST1pCWUpLd1lCQkFIYVJ3OEJBUWRBZy9iRnR4WG5hRjZLOFEzdGVWcmt3Y3YvRTV6TE94WnVZaXVvCm5MVkdtdWZOQzI1aGJXVWdQRzFoYVd3K3dvOEVFeFlJQUVFRkFtV1VUbVFKRUhmcmlVWXZsWnhyRmlFRXFFMDIKVVRmOTRTY1hJWVdjZCt1SlJpK1ZuR3NDR3dNQ0hnRUNHUUVEQ3drSEFoV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VpVKzRHClQwUmQxU2VNUXpzNndCUU9ZejEwQkVMWEFRQ3hTQ2kvN2RqRjZUWFl0SFpBSytrVUEvUHpYaW14bnRvVFpKbjMKV3l1Z0NnPT0KPTFjU20KLS0tLS1FTkQgUEdQIFBVQkxJQyBLRVkgQkxPQ0stLS0tLQ==",
"url": "http://localhost:8080"
}
]
}
`
var cc1 ContactCard
jsoncc := []byte(ccsrt)
err := json.Unmarshal(jsoncc, &cc1)
if err != nil {
println(err)
}
}