databag/net/server/internal/ucMessangerApp_test.go

184 lines
4.5 KiB
Go
Raw Normal View History

2022-03-03 19:34:07 +00:00
package databag
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMessangerApp(t *testing.T) {
var params *TestApiParams
var response *TestApiResponse
2022-03-04 19:44:55 +00:00
var channel *Channel
var topic *Topic
2022-03-03 19:34:07 +00:00
// allocate test accounts
set, err := AddTestGroup("messangerapp")
assert.NoError(t, err)
// allocate new test app
app := NewTestApp()
go app.Connect(set.A.Token)
// wait for test
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
if testApp.profile.Handle == "messangerappA" {
return true
}
return false
}))
// set profile
params = &TestApiParams{
restType: "PUT",
query: "/profile/data",
body: &ProfileData{
Name: "Roland",
Location: "The City",
},
tokenType: APP_TOKENAPP,
token: set.A.Token,
}
response = &TestApiResponse{}
assert.NoError(t, TestApiRequest(SetProfile, params, response))
// wait for test
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
if testApp.profile.Location == "The City" {
return true
}
return false
}))
// add a channel
params = &TestApiParams{
restType: "POST",
query: "/content/channels",
body: &Subject{
2022-03-04 19:44:55 +00:00
Data: "channeldataA",
DataType: "channeldatatypeA",
2022-03-03 19:34:07 +00:00
},
tokenType: APP_TOKENAPP,
token: set.A.Token,
}
2022-03-04 19:44:55 +00:00
channel = &Channel{}
response = &TestApiResponse{ data: channel }
2022-03-03 19:34:07 +00:00
assert.NoError(t, TestApiRequest(AddChannel, params, response))
// wait for test
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
for _, c := range testApp.channels {
2022-03-04 19:44:55 +00:00
if c.channel.Id == channel.Id {
2022-03-03 19:34:07 +00:00
return true
}
}
return false
}))
2022-03-04 19:44:55 +00:00
// add a topic to channel
params = &TestApiParams{
restType: "POST",
query: "/content/channels/{channelId}/topics",
path: map[string]string{ "channelId": channel.Id },
body: &Subject{
Data: "channeltopicdataA",
DataType: "channeltopicdatatypeA",
},
tokenType: APP_TOKENAPP,
token: set.A.Token,
}
topic = &Topic{}
response = &TestApiResponse{ data: topic }
assert.NoError(t, TestApiRequest(AddChannelTopic, params, response))
// wait for test
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
for _, c := range testApp.channels {
if c.channel.Id == channel.Id {
for _, t := range c.topics {
if t.Id == topic.Id {
return true
}
}
}
}
return false
}))
// add a channel
params = &TestApiParams{
restType: "POST",
query: "/content/channels",
body: &Subject{
Data: "channeldataB",
DataType: "channeldatatypeB",
},
tokenType: APP_TOKENAPP,
token: set.B.Token,
}
channel = &Channel{}
response = &TestApiResponse{ data: channel }
assert.NoError(t, TestApiRequest(AddChannel, params, response))
2022-03-03 19:34:07 +00:00
2022-03-04 19:44:55 +00:00
// share channel with A
params = &TestApiParams{
restType: "PUT",
query: "/content/channels/{channelId}/cards/{cardId}",
path: map[string]string{ "cardId": set.B.A.CardId, "channelId": channel.Id },
tokenType: APP_TOKENAPP,
token: set.B.Token,
}
response = &TestApiResponse{}
assert.NoError(t, TestApiRequest(SetChannelCard, params, response))
// wait for test
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
for _, testContact := range testApp.contacts {
if testContact.card.Id == set.A.B.CardId {
for _, testChannel := range testContact.channels {
if testChannel.channel.Id == channel.Id {
return true
}
}
}
}
return false
}))
// add a topic to channel
params = &TestApiParams{
restType: "POST",
query: "/content/channels/{channelId}/topics",
path: map[string]string{ "channelId": channel.Id },
body: &Subject{
Data: "channeltopicdataB",
DataType: "channeltopicdatatypeB",
},
tokenType: APP_TOKENCONTACT,
token: set.A.B.Token,
}
topic = &Topic{}
response = &TestApiResponse{ data: topic }
assert.NoError(t, TestApiRequest(AddChannelTopic, params, response))
// wait for test
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
for _, testContact := range testApp.contacts {
if testContact.card.Id == set.A.B.CardId {
for _, testChannel := range testContact.channels {
if testChannel.channel.Id == channel.Id {
for _, t := range testChannel.topics {
if t.Id == topic.Id {
PrintMsg(t)
PrintMsg(topic)
return true
}
}
}
}
}
}
return false
}))
2022-03-03 19:34:07 +00:00
}