2022-01-21 23:08:52 +00:00
|
|
|
package databag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2022-01-22 07:00:47 +00:00
|
|
|
"encoding/json"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-01-21 23:08:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProfileNotification(t *testing.T) {
|
2022-01-22 07:00:47 +00:00
|
|
|
var views []CardView
|
|
|
|
var revision Revision
|
|
|
|
var data []byte
|
2022-01-21 23:08:52 +00:00
|
|
|
|
|
|
|
// start notifcation thread
|
|
|
|
go SendNotifications()
|
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// connect contacts
|
2022-01-21 23:08:52 +00:00
|
|
|
access := AddTestContacts(t, "profilenotification", 2);
|
2022-01-22 07:00:47 +00:00
|
|
|
ConnectTestContacts(t, access[0], access[1])
|
2022-01-21 23:08:52 +00:00
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// get views list of cards
|
|
|
|
r, w, _ := NewRequest("GET", "/contact/cards/view", nil)
|
|
|
|
SetBearerAuth(r, access[0])
|
|
|
|
GetCardView(w, r)
|
|
|
|
assert.NoError(t, ReadResponse(w, &views))
|
|
|
|
assert.Equal(t, len(views), 1)
|
|
|
|
profileRevision := views[0].RemoteProfile
|
2022-01-21 23:08:52 +00:00
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// app connects websocket
|
|
|
|
ws := getTestWebsocket()
|
|
|
|
announce := Announce{ AppToken: access[0] }
|
|
|
|
data, _ = json.Marshal(&announce)
|
|
|
|
ws.WriteMessage(websocket.TextMessage, data)
|
2022-01-21 23:08:52 +00:00
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// receive revision
|
|
|
|
_, data, _ = ws.ReadMessage()
|
|
|
|
assert.NoError(t, json.Unmarshal(data, &revision))
|
|
|
|
cardRevision := revision.Card
|
2022-01-21 23:08:52 +00:00
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// update B profile
|
|
|
|
profileData := ProfileData{
|
|
|
|
Name: "Namer",
|
|
|
|
Location: "San Francisco",
|
|
|
|
Description: "databaggerr",
|
|
|
|
};
|
|
|
|
r, w, _ = NewRequest("PUT", "/profile/data", &profileData)
|
|
|
|
SetBearerAuth(r, access[1])
|
|
|
|
SetProfile(w, r)
|
|
|
|
assert.NoError(t, ReadResponse(w, nil))
|
2022-01-21 23:08:52 +00:00
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// receive revision
|
|
|
|
_, data, _ = ws.ReadMessage()
|
|
|
|
assert.NoError(t, json.Unmarshal(data, &revision))
|
|
|
|
assert.NotEqual(t, cardRevision, revision.Card)
|
2022-01-21 23:08:52 +00:00
|
|
|
|
2022-01-22 07:00:47 +00:00
|
|
|
// get views list of cards
|
|
|
|
r, w, _ = NewRequest("GET", "/contact/cards/view", nil)
|
|
|
|
SetBearerAuth(r, access[0])
|
|
|
|
GetCardView(w, r)
|
|
|
|
assert.NoError(t, ReadResponse(w, &views))
|
|
|
|
assert.Equal(t, len(views), 1)
|
|
|
|
assert.NotEqual(t, profileRevision, views[0].RemoteProfile)
|
2022-01-21 23:08:52 +00:00
|
|
|
|
|
|
|
// stop notification thread
|
|
|
|
ExitNotifications()
|
|
|
|
}
|