databag/net/server/internal/ucConnectContact_test.go

59 lines
1.3 KiB
Go
Raw Normal View History

2022-01-19 23:03:06 +00:00
package databag
import (
"testing"
2022-01-21 00:26:59 +00:00
"github.com/gorilla/mux"
2022-01-20 04:25:20 +00:00
"github.com/stretchr/testify/assert"
2022-01-19 23:03:06 +00:00
)
func TestConnectContact(t *testing.T) {
2022-01-21 00:26:59 +00:00
var card Card
2022-01-21 01:01:02 +00:00
var msg DataMessage
var vars map[string]string
2022-01-19 23:03:06 +00:00
2022-01-20 23:19:26 +00:00
// create some contacts for this test
access := AddTestContacts(t, "connect", 2)
2022-01-19 23:03:06 +00:00
2022-01-21 01:01:02 +00:00
// get A identity message
2022-01-20 23:19:26 +00:00
r, w, _ := NewRequest("GET", "/profile/message", nil)
SetBearerAuth(r, access[0])
2022-01-20 08:05:12 +00:00
GetProfileMessage(w, r)
assert.NoError(t, ReadResponse(w, &msg))
2022-01-21 01:01:02 +00:00
// add A card in B
2022-01-20 23:19:26 +00:00
r, w, _ = NewRequest("POST", "/contact/cards", &msg)
SetBearerAuth(r, access[1])
AddCard(w, r)
2022-01-21 00:26:59 +00:00
assert.NoError(t, ReadResponse(w, &card))
2022-01-21 01:01:02 +00:00
// update A status to connecting
2022-01-21 00:26:59 +00:00
r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status", APP_CARDCONNECTING)
2022-01-21 01:01:02 +00:00
vars = map[string]string{ "cardId": card.CardId }
2022-01-21 00:26:59 +00:00
r = mux.SetURLVars(r, vars)
SetBearerAuth(r, access[1])
SetCardStatus(w, r)
2022-01-20 23:19:26 +00:00
assert.NoError(t, ReadResponse(w, &card))
2022-01-21 01:01:02 +00:00
// 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, access[1])
GetOpenMessage(w, r)
assert.NoError(t, ReadResponse(w, &msg))
PrintMsg(msg)
2022-01-20 08:05:12 +00:00
2022-01-20 23:19:26 +00:00
// A request B
2022-01-19 23:03:06 +00:00
// set B card in A
// get A open message
// set A card in B
// accept A
}