mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
test util cleanup
This commit is contained in:
parent
5b6673fc81
commit
ff5c34e0df
@ -37,20 +37,6 @@ func ReadResponse(w *httptest.ResponseRecorder, v interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewRequest(rest string, path string, obj interface{}) (*http.Request, *httptest.ResponseRecorder, error) {
|
||||
w := httptest.NewRecorder()
|
||||
if(obj != nil) {
|
||||
body, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
reader := strings.NewReader(string(body))
|
||||
return httptest.NewRequest(rest, path, reader), w, nil
|
||||
}
|
||||
|
||||
return httptest.NewRequest(rest, path, nil), w, nil
|
||||
}
|
||||
|
||||
func SetBasicAuth(r *http.Request, login string) {
|
||||
auth := base64.StdEncoding.EncodeToString([]byte(login))
|
||||
r.Header.Add("Authorization", "Basic " + auth)
|
||||
|
@ -2,12 +2,11 @@ package databag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"strconv"
|
||||
"strings"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type TestAccount struct {
|
||||
@ -156,6 +155,7 @@ func AddTestGroup(prefix string) (*TestGroup, error) {
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func GetCardToken(account string, cardId string) (token string, err error) {
|
||||
var r *http.Request
|
||||
var w *httptest.ResponseRecorder
|
||||
@ -179,6 +179,7 @@ func GetCardToken(account string, cardId string) (token string, err error) {
|
||||
token = card.CardProfile.Guid + "." + card.CardData.Token
|
||||
return
|
||||
}
|
||||
|
||||
func GroupTestCard(account string, cardId string) (groupId string, err error) {
|
||||
var r *http.Request
|
||||
var w *httptest.ResponseRecorder
|
||||
@ -216,6 +217,7 @@ func GroupTestCard(account string, cardId string) (groupId string, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func OpenTestCard(account string, cardId string) (err error) {
|
||||
var r *http.Request
|
||||
var w *httptest.ResponseRecorder
|
||||
@ -269,6 +271,7 @@ func OpenTestCard(account string, cardId string) (err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func AddTestCard(account string, contact string) (cardId string, err error) {
|
||||
var r *http.Request
|
||||
var w *httptest.ResponseRecorder
|
||||
@ -298,6 +301,7 @@ func AddTestCard(account string, contact string) (cardId string, err error) {
|
||||
cardId = card.CardId
|
||||
return
|
||||
}
|
||||
|
||||
func AddTestAccount(username string) (guid string, token string, err error) {
|
||||
var r *http.Request
|
||||
var w *httptest.ResponseRecorder
|
||||
@ -356,158 +360,17 @@ func AddTestAccount(username string) (guid string, token string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func AddTestContacts(t *testing.T, prefix string, count int) []string {
|
||||
|
||||
var access []string
|
||||
app := AppData{
|
||||
Name: "Appy",
|
||||
Description: "A test app",
|
||||
Url: "http://app.example.com",
|
||||
};
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
var token string
|
||||
var login = prefix + strconv.Itoa(i) + ":pass"
|
||||
|
||||
// get account token
|
||||
r, w, _ := NewRequest("POST", "/admin/accounts", nil)
|
||||
SetBasicAuth(r, "admin:pass")
|
||||
AddNodeAccount(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &token))
|
||||
|
||||
// set account profile
|
||||
r, w, _ = NewRequest("GET", "/account/profile", nil)
|
||||
SetBearerAuth(r, token);
|
||||
SetCredentials(r, login)
|
||||
AddAccount(w, r)
|
||||
var profile Profile
|
||||
assert.NoError(t, ReadResponse(w, &profile))
|
||||
|
||||
// acquire new token for attaching app
|
||||
r, w, _ = NewRequest("POST", "/account/apps", nil)
|
||||
SetBasicAuth(r, login);
|
||||
AddAccountApp(w, r);
|
||||
assert.NoError(t, ReadResponse(w, &token))
|
||||
|
||||
// attach app with token
|
||||
r, w, _ = NewRequest("PUT", "/account/apps", &app)
|
||||
SetBearerAuth(r, token)
|
||||
SetAccountApp(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &token))
|
||||
|
||||
access = append(access, profile.Guid + "." + token)
|
||||
func NewRequest(rest string, path string, obj interface{}) (*http.Request, *httptest.ResponseRecorder, error) {
|
||||
w := httptest.NewRecorder()
|
||||
if(obj != nil) {
|
||||
body, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
reader := strings.NewReader(string(body))
|
||||
return httptest.NewRequest(rest, path, reader), w, nil
|
||||
}
|
||||
|
||||
return access
|
||||
return httptest.NewRequest(rest, path, nil), w, nil
|
||||
}
|
||||
|
||||
func ConnectTestContacts(t *testing.T, accessA string, accessB string) (contact [2]TestAccount) {
|
||||
var card Card
|
||||
var msg DataMessage
|
||||
var vars map[string]string
|
||||
var contactStatus ContactStatus
|
||||
var id string
|
||||
contact[0].AppToken = accessA
|
||||
contact[1].AppToken = accessB
|
||||
|
||||
// get A identity message
|
||||
r, w, _ := NewRequest("GET", "/profile/message", nil)
|
||||
r.Header.Add("TokenType", APP_TOKENAPP)
|
||||
SetBearerAuth(r, accessA)
|
||||
GetProfileMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
|
||||
// add A card in B
|
||||
r, w, _ = NewRequest("POST", "/contact/cards", &msg)
|
||||
SetBearerAuth(r, accessB)
|
||||
AddCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
contact[1].ContactCardId = card.CardId
|
||||
contact[1].ContactGuid = card.CardProfile.Guid
|
||||
|
||||
// update A status to connecting
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status", APP_CARDCONNECTING)
|
||||
vars = map[string]string{ "cardId": card.CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessB)
|
||||
SetCardStatus(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
// get open message to A
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}/openMessage", nil)
|
||||
vars = map[string]string{ "cardId": card.CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessB)
|
||||
GetOpenMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
id = card.CardId
|
||||
|
||||
// set open message in A
|
||||
r, w, _ = NewRequest("PUT", "/contact/openMessage", msg)
|
||||
SetOpenMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &contactStatus))
|
||||
|
||||
// get view of cards in A
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/view", nil)
|
||||
SetBearerAuth(r, accessA)
|
||||
GetCardView(w, r)
|
||||
var views []CardView
|
||||
assert.NoError(t, ReadResponse(w, &views))
|
||||
assert.Equal(t, len(views), 1)
|
||||
|
||||
// get B card in A
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessA)
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
contact[0].ContactCardId = card.CardId
|
||||
contact[0].ContactGuid = card.CardProfile.Guid
|
||||
|
||||
// update B status to connecting
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status", APP_CARDCONNECTING)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessA)
|
||||
SetCardStatus(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
// get open message to B
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}/openMessage", nil)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessA)
|
||||
GetOpenMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
|
||||
// set open message in B
|
||||
r, w, _ = NewRequest("PUT", "/contact/openMessage", msg)
|
||||
SetOpenMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &contactStatus))
|
||||
assert.Equal(t, APP_CARDCONNECTED, contactStatus.Status)
|
||||
|
||||
// update B status to connected
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status?token=" + contactStatus.Token, APP_CARDCONNECTED)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessA)
|
||||
SetCardStatus(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
// extract contact tokens
|
||||
contact[0].ContactToken = card.CardData.Token
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": id }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, accessB)
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
contact[1].ContactToken = card.CardData.Token
|
||||
|
||||
return
|
||||
}
|
@ -6,8 +6,10 @@ import (
|
||||
)
|
||||
|
||||
func TestAddArticle(t *testing.T) {
|
||||
var set *TestGroup
|
||||
var err error
|
||||
|
||||
set, err := AddTestGroup("addaccount")
|
||||
assert.NoError(t, err)
|
||||
PrintMsg(set)
|
||||
set, err = AddTestGroup("addaccount1")
|
||||
assert.NoError(t, err)
|
||||
PrintMsg(set)
|
||||
}
|
||||
|
@ -18,18 +18,19 @@ func TestConnectContact(t *testing.T) {
|
||||
var contactStatus ContactStatus
|
||||
|
||||
// create some contacts for this test
|
||||
access := AddTestContacts(t, "connect", 2)
|
||||
_, a, _ := AddTestAccount("connect0")
|
||||
_, b, _ := AddTestAccount("connect1")
|
||||
|
||||
// get A identity message
|
||||
r, w, _ := NewRequest("GET", "/profile/message", nil)
|
||||
r.Header.Add("TokenType", APP_TOKENAPP)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetProfileMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
|
||||
// app connects websocket
|
||||
ws := getTestWebsocket()
|
||||
announce := Announce{ AppToken: access[1] }
|
||||
announce := Announce{ AppToken: b }
|
||||
data, _ := json.Marshal(&announce)
|
||||
ws.WriteMessage(websocket.TextMessage, data)
|
||||
ws.SetReadDeadline(time.Now().Add(2 * time.Second))
|
||||
@ -39,7 +40,7 @@ func TestConnectContact(t *testing.T) {
|
||||
|
||||
// add A card in B
|
||||
r, w, _ = NewRequest("POST", "/contact/cards", &msg)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
AddCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
@ -54,7 +55,7 @@ func TestConnectContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status", APP_CARDCONNECTING)
|
||||
vars = map[string]string{ "cardId": card.CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
SetCardStatus(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
@ -69,7 +70,7 @@ func TestConnectContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}/openMessage", nil)
|
||||
vars = map[string]string{ "cardId": card.CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
GetOpenMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
|
||||
@ -80,7 +81,7 @@ func TestConnectContact(t *testing.T) {
|
||||
|
||||
// get view of cards in A
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/view", nil)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetCardView(w, r)
|
||||
var views []CardView
|
||||
assert.NoError(t, ReadResponse(w, &views))
|
||||
@ -90,7 +91,7 @@ func TestConnectContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
@ -98,7 +99,7 @@ func TestConnectContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status", APP_CARDCONNECTING)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
SetCardStatus(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
@ -106,7 +107,7 @@ func TestConnectContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}/openMessage", nil)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetOpenMessage(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &msg))
|
||||
|
||||
@ -127,7 +128,7 @@ func TestConnectContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status?token=" + contactStatus.Token, APP_CARDCONNECTED)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
SetCardStatus(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
|
@ -26,16 +26,20 @@ func TestGroupContact(t *testing.T) {
|
||||
go SendNotifications()
|
||||
|
||||
// connect contacts
|
||||
access := AddTestContacts(t, "groupcontact", 2);
|
||||
contact := ConnectTestContacts(t, access[0], access[1])
|
||||
_, a, _ := AddTestAccount("groupcontact0")
|
||||
_, b, _ := AddTestAccount("groupcontact1")
|
||||
aCard, _ := AddTestCard(a, b)
|
||||
bCard, _ := AddTestCard(b, a)
|
||||
OpenTestCard(a, aCard)
|
||||
OpenTestCard(b, bCard)
|
||||
|
||||
// app connects websocket
|
||||
wsA := getTestWebsocket()
|
||||
announce := Announce{ AppToken: access[0] }
|
||||
announce := Announce{ AppToken: a }
|
||||
data, _ := json.Marshal(&announce)
|
||||
wsA.WriteMessage(websocket.TextMessage, data)
|
||||
wsB := getTestWebsocket()
|
||||
announce = Announce{ AppToken: access[1] }
|
||||
announce = Announce{ AppToken: b }
|
||||
data, _ = json.Marshal(&announce)
|
||||
wsB.WriteMessage(websocket.TextMessage, data)
|
||||
|
||||
@ -55,7 +59,7 @@ func TestGroupContact(t *testing.T) {
|
||||
Data: "group data with name and logo",
|
||||
}
|
||||
r, w, _ := NewRequest("POST", "/share/groups", subject)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
AddGroup(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &group))
|
||||
|
||||
@ -68,9 +72,9 @@ func TestGroupContact(t *testing.T) {
|
||||
|
||||
// get contact revision
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": contact[1].ContactCardId }
|
||||
vars = map[string]string{ "cardId": bCard }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
contactCardRevision = card.ContentRevision
|
||||
@ -79,18 +83,18 @@ func TestGroupContact(t *testing.T) {
|
||||
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/groups/{groupId}", nil)
|
||||
vars = make(map[string]string)
|
||||
vars["groupId"] = group.GroupId
|
||||
vars["cardId"] = contact[0].ContactCardId
|
||||
vars["cardId"] = aCard
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
SetCardGroup(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &cardData))
|
||||
assert.Equal(t, 1, len(cardData.Groups))
|
||||
|
||||
// get contact revision
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": contact[0].ContactCardId }
|
||||
vars = map[string]string{ "cardId": aCard }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetCard(w, r)
|
||||
card = Card{}
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
@ -110,9 +114,9 @@ func TestGroupContact(t *testing.T) {
|
||||
|
||||
// get contact revision
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": contact[1].ContactCardId }
|
||||
vars = map[string]string{ "cardId": bCard }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
assert.NotEqual(t, contactCardRevision, card.ContentRevision)
|
||||
@ -120,7 +124,7 @@ func TestGroupContact(t *testing.T) {
|
||||
|
||||
// show group view
|
||||
r, w, _ = NewRequest("GET", "/share/groups", nil)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetGroups(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &groups))
|
||||
assert.Equal(t, 1, len(groups))
|
||||
@ -134,7 +138,7 @@ func TestGroupContact(t *testing.T) {
|
||||
vars = make(map[string]string)
|
||||
vars["groupId"] = group.GroupId
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
UpdateGroup(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &group))
|
||||
assert.Equal(t, group.DataType, "imagroupEDIT")
|
||||
@ -151,15 +155,15 @@ func TestGroupContact(t *testing.T) {
|
||||
vars = make(map[string]string)
|
||||
vars["groupId"] = group.GroupId
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
RemoveGroup(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &group))
|
||||
|
||||
// get contact revision
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": contact[0].ContactCardId }
|
||||
vars = map[string]string{ "cardId": aCard }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetCard(w, r)
|
||||
card = Card{}
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
@ -177,16 +181,16 @@ func TestGroupContact(t *testing.T) {
|
||||
|
||||
// get contact revision
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": contact[1].ContactCardId }
|
||||
vars = map[string]string{ "cardId": bCard }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
assert.NotEqual(t, contactCardRevision, card.ContentRevision)
|
||||
|
||||
// show group view
|
||||
r, w, _ = NewRequest("GET", "/share/groups", nil)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetGroups(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &groups))
|
||||
assert.Equal(t, 0, len(groups))
|
||||
|
@ -17,12 +17,16 @@ func TestProfileNotification(t *testing.T) {
|
||||
go SendNotifications()
|
||||
|
||||
// connect contacts
|
||||
access := AddTestContacts(t, "profilenotification", 2);
|
||||
ConnectTestContacts(t, access[0], access[1])
|
||||
_, a, _ := AddTestAccount("profilenotification0")
|
||||
_, b, _ := AddTestAccount("profilenotification1")
|
||||
aCard, _ := AddTestCard(a, b)
|
||||
bCard, _ := AddTestCard(b, a)
|
||||
OpenTestCard(a, aCard)
|
||||
OpenTestCard(b, bCard)
|
||||
|
||||
// get views list of cards
|
||||
r, w, _ := NewRequest("GET", "/contact/cards/view", nil)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetCardView(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &views))
|
||||
assert.Equal(t, len(views), 1)
|
||||
@ -30,7 +34,7 @@ func TestProfileNotification(t *testing.T) {
|
||||
|
||||
// app connects websocket
|
||||
ws := getTestWebsocket()
|
||||
announce := Announce{ AppToken: access[0] }
|
||||
announce := Announce{ AppToken: a }
|
||||
data, _ = json.Marshal(&announce)
|
||||
ws.WriteMessage(websocket.TextMessage, data)
|
||||
|
||||
@ -47,7 +51,7 @@ func TestProfileNotification(t *testing.T) {
|
||||
Description: "databaggerr",
|
||||
};
|
||||
r, w, _ = NewRequest("PUT", "/profile/data", &profileData)
|
||||
SetBearerAuth(r, access[1])
|
||||
SetBearerAuth(r, b)
|
||||
SetProfile(w, r)
|
||||
assert.NoError(t, ReadResponse(w, nil))
|
||||
|
||||
@ -59,7 +63,7 @@ func TestProfileNotification(t *testing.T) {
|
||||
|
||||
// get views list of cards
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/view", nil)
|
||||
SetBearerAuth(r, access[0])
|
||||
SetBearerAuth(r, a)
|
||||
GetCardView(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &views))
|
||||
assert.Equal(t, len(views), 1)
|
||||
|
Loading…
Reference in New Issue
Block a user