6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-30 18:51:03 +00:00
prologic-saltyim/client_test.go
mlctrez 504c66f7c1 make outbox.state same as client.state to allow persisting last message retrieved (#168)
After testing quite a bit on the saltyim/app client, I tracked down why all outbox messages were being pulled every time a new client starts up.

I believe the outbox client state should be shared with the parent client to allow the last message retrieved from the oubox to be persisted.

Co-authored-by: mlctrez <mlctrez@gmail.com>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/168
Reviewed-by: James Mills <james@mills.io>
Co-authored-by: mlctrez <mlctrez@noreply@mills.io>
Co-committed-by: mlctrez <mlctrez@noreply@mills.io>
2022-04-29 21:59:40 +00:00

47 lines
1.3 KiB
Go

package saltyim
import (
"crypto/sha256"
"fmt"
"net/url"
"testing"
"github.com/keys-pub/keys"
"github.com/stretchr/testify/require"
)
func TestClient_Outbox(t *testing.T) {
test := require.New(t)
endpoint := &url.URL{Host: "example.com", Path: "/path", Scheme: "https"}
key := keys.GenerateEdX25519Key()
client := &Client{me: &Addr{endpoint: endpoint}, id: &Identity{key: key}}
outbox := client.Outbox()
test.True(endpoint.Path == "/path",
"endpoint.Path should not be modified after call to client.Outbox()")
test.False(*endpoint == *outbox,
"endpoint and outbox should not point to the same *url.URL")
expected := fmt.Sprintf("/%x", sha256.Sum256(key.Private()))
test.True(outbox.Path == expected, "expected %s but got %s", expected, outbox.Path)
}
func TestClient_Outbox_State(t *testing.T) {
req := require.New(t)
endpoint := &url.URL{Host: "example.com", Path: "/path", Scheme: "https"}
key := keys.GenerateEdX25519Key()
state := NewState()
var testIndex int64 = 100
state.SetIndex("testIndex", testIndex)
client := &Client{me: &Addr{endpoint: endpoint}, id: &Identity{key: key}, state: state}
outboxClient := client.OutboxClient(nil)
req.Equal(state, outboxClient.state)
req.Equal(testIndex, outboxClient.state.GetIndex("testIndex"))
}