mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
testing channel sync
This commit is contained in:
parent
ae506a4df5
commit
31bb532470
@ -21,7 +21,7 @@ type TestCondition struct {
|
|||||||
|
|
||||||
type TestChannel struct {
|
type TestChannel struct {
|
||||||
channel Channel
|
channel Channel
|
||||||
topics map[string]Topic
|
topics map[string]*Topic
|
||||||
}
|
}
|
||||||
|
|
||||||
type TestContactData struct {
|
type TestContactData struct {
|
||||||
@ -72,7 +72,7 @@ func (c *TestContactData) UpdateContact() (err error) {
|
|||||||
if c.viewRevision != c.card.Data.NotifiedView {
|
if c.viewRevision != c.card.Data.NotifiedView {
|
||||||
if err = c.UpdateContactArticle(); err != nil {
|
if err = c.UpdateContactArticle(); err != nil {
|
||||||
return
|
return
|
||||||
} else if err = c.UpdateContactChannel(); err != nil {
|
} else if err = c.UpdateContactChannels(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.articleRevision = c.card.Data.NotifiedArticle
|
c.articleRevision = c.card.Data.NotifiedArticle
|
||||||
@ -90,7 +90,7 @@ func (c *TestContactData) UpdateContact() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.channelRevision != c.card.Data.NotifiedChannel {
|
if c.channelRevision != c.card.Data.NotifiedChannel {
|
||||||
if err = c.UpdateContactChannel(); err != nil {
|
if err = c.UpdateContactChannels(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.channelRevision = c.card.Data.NotifiedChannel
|
c.channelRevision = c.card.Data.NotifiedChannel
|
||||||
@ -148,7 +148,102 @@ func (c *TestContactData) UpdateContactArticle() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactChannel() (err error) {
|
func (c *TestContactData) UpdateContactChannels() (err error) {
|
||||||
|
var channels []Channel
|
||||||
|
if c.channelRevision == 0 || c.viewRevision != c.card.Data.NotifiedView {
|
||||||
|
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
||||||
|
params := &TestApiParams{ query: "/channels", tokenType: APP_TOKENCONTACT, token: token }
|
||||||
|
response := &TestApiResponse{ data: &channels }
|
||||||
|
if err = TestApiRequest(GetChannels, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
||||||
|
viewRevision := strconv.FormatInt(c.viewRevision, 10)
|
||||||
|
channelRevision := strconv.FormatInt(c.channelRevision, 10)
|
||||||
|
params := &TestApiParams{ query: "/channels?channelRevision=" + channelRevision + "&viewRevision=" + viewRevision,
|
||||||
|
tokenType: APP_TOKENCONTACT, token: token }
|
||||||
|
response := &TestApiResponse{ data: &channels }
|
||||||
|
if err = TestApiRequest(GetChannels, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, channel := range channels {
|
||||||
|
if channel.Data == nil {
|
||||||
|
delete(c.channels, channel.Id)
|
||||||
|
} else {
|
||||||
|
tc, set := c.channels[channel.Id]
|
||||||
|
if set {
|
||||||
|
if channel.Revision != tc.channel.Revision {
|
||||||
|
if err = c.UpdateContactChannel(tc, &channel); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tc.channel.Revision = channel.Revision
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tc := &TestChannel{ channel: Channel{ Id: channel.Id } }
|
||||||
|
c.channels[channel.Id] = tc
|
||||||
|
if err = c.UpdateContactChannel(tc, &channel); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tc.channel.Revision = channel.Revision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TestContactData) UpdateContactChannel(testChannel *TestChannel, channel *Channel) (err error) {
|
||||||
|
if testChannel.channel.Revision != channel.Revision {
|
||||||
|
if channel.Data.ChannelDetail != nil {
|
||||||
|
testChannel.channel.Data = channel.Data
|
||||||
|
} else if testChannel.channel.Data == nil || testChannel.channel.Data.DetailRevision != channel.Data.DetailRevision {
|
||||||
|
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
||||||
|
params := &TestApiParams{ query: "/channels/{channelId}", path: map[string]string{ "channelId": channel.Id }, tokenType: APP_TOKENCONTACT, token: token }
|
||||||
|
channel := Channel{}
|
||||||
|
response := &TestApiResponse{ data: &channel }
|
||||||
|
if err = TestApiRequest(GetChannel, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if channel.Data == nil {
|
||||||
|
delete(c.channels, channel.Id)
|
||||||
|
}
|
||||||
|
testChannel.channel.Data = channel.Data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = c.UpdateContactChannelTopics(testChannel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TestContactData) UpdateContactChannelTopics(testChannel *TestChannel) (err error) {
|
||||||
|
var topics []Topic
|
||||||
|
if testChannel.channel.Revision == 0 {
|
||||||
|
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
||||||
|
params := &TestApiParams{ query: "/channels/{channelId}/topics",
|
||||||
|
path: map[string]string{ "channelId": testChannel.channel.Id }, tokenType: APP_TOKENCONTACT, token: token }
|
||||||
|
response := &TestApiResponse{ data: &topics }
|
||||||
|
if err = TestApiRequest(GetChannelTopics, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
testChannel.topics = make(map[string]*Topic)
|
||||||
|
} else {
|
||||||
|
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
||||||
|
revision := strconv.FormatInt(testChannel.channel.Revision, 10)
|
||||||
|
params := &TestApiParams{ query: "/channels/{channelId}/topics?revision=" + revision,
|
||||||
|
path: map[string]string{ "channelId": testChannel.channel.Id }, tokenType: APP_TOKENCONTACT, token: token }
|
||||||
|
response := &TestApiResponse{ data: &topics }
|
||||||
|
if err = TestApiRequest(GetChannelTopics, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, topic := range topics {
|
||||||
|
if topic.Data == nil {
|
||||||
|
delete(testChannel.topics, topic.Id)
|
||||||
|
} else {
|
||||||
|
testChannel.topics[topic.Id] = &topic
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +384,7 @@ func (a *TestApp) UpdateChannels() (err error) {
|
|||||||
c.channel.Revision = channel.Revision
|
c.channel.Revision = channel.Revision
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c := &TestChannel{ channel: Channel{ Id: channel.Id }, topics: map[string]Topic{} }
|
c := &TestChannel{ channel: Channel{ Id: channel.Id } }
|
||||||
a.channels[channel.Id] = c
|
a.channels[channel.Id] = c
|
||||||
if err = a.UpdateChannel(c, &channel); err != nil {
|
if err = a.UpdateChannel(c, &channel); err != nil {
|
||||||
return
|
return
|
||||||
@ -304,7 +399,7 @@ func (a *TestApp) UpdateChannels() (err error) {
|
|||||||
func (a *TestApp) UpdateChannel(testChannel *TestChannel, channel *Channel) (err error) {
|
func (a *TestApp) UpdateChannel(testChannel *TestChannel, channel *Channel) (err error) {
|
||||||
if testChannel.channel.Revision != channel.Revision {
|
if testChannel.channel.Revision != channel.Revision {
|
||||||
if channel.Data.ChannelDetail != nil {
|
if channel.Data.ChannelDetail != nil {
|
||||||
testChannel.channel = *channel
|
testChannel.channel.Data = channel.Data
|
||||||
} else if testChannel.channel.Data == nil || testChannel.channel.Data.DetailRevision != channel.Data.DetailRevision {
|
} else if testChannel.channel.Data == nil || testChannel.channel.Data.DetailRevision != channel.Data.DetailRevision {
|
||||||
c := Channel{}
|
c := Channel{}
|
||||||
params := &TestApiParams{ query: "/channel/{channelId}", path: map[string]string{ "channelId": channel.Id }, tokenType: APP_TOKENAPP, token: a.token }
|
params := &TestApiParams{ query: "/channel/{channelId}", path: map[string]string{ "channelId": channel.Id }, tokenType: APP_TOKENAPP, token: a.token }
|
||||||
@ -315,13 +410,42 @@ func (a *TestApp) UpdateChannel(testChannel *TestChannel, channel *Channel) (err
|
|||||||
if c.Data == nil {
|
if c.Data == nil {
|
||||||
delete(a.channels, channel.Id)
|
delete(a.channels, channel.Id)
|
||||||
}
|
}
|
||||||
testChannel.channel = c
|
testChannel.channel.Data = c.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO update topics
|
err = a.UpdateChannelTopics(testChannel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *TestApp) UpdateChannelTopics(testChannel *TestChannel) (err error) {
|
||||||
|
var topics []Topic
|
||||||
|
if testChannel.channel.Revision == 0 {
|
||||||
|
params := &TestApiParams{ query: "/channels/{channelId}/topics",
|
||||||
|
path: map[string]string{ "channelId": testChannel.channel.Id }, tokenType: APP_TOKENAPP, token: a.token }
|
||||||
|
response := &TestApiResponse{ data: &topics }
|
||||||
|
if err = TestApiRequest(GetChannelTopics, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
testChannel.topics = make(map[string]*Topic)
|
||||||
|
} else {
|
||||||
|
revision := strconv.FormatInt(testChannel.channel.Revision, 10)
|
||||||
|
params := &TestApiParams{ query: "/channels/{channelId}/topics?revision=" + revision,
|
||||||
|
path: map[string]string{ "channelId": testChannel.channel.Id }, tokenType: APP_TOKENAPP, token: a.token }
|
||||||
|
response := &TestApiResponse{ data: &topics }
|
||||||
|
if err = TestApiRequest(GetChannelTopics, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, topic := range topics {
|
||||||
|
if topic.Data == nil {
|
||||||
|
delete(testChannel.topics, topic.Id)
|
||||||
|
} else {
|
||||||
|
testChannel.topics[topic.Id] = &topic
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *TestApp) UpdateCards() (err error) {
|
func (a *TestApp) UpdateCards() (err error) {
|
||||||
var cards []Card
|
var cards []Card
|
||||||
if a.revision.Card == 0 {
|
if a.revision.Card == 0 {
|
||||||
@ -396,6 +520,8 @@ func (a *TestApp) UpdateApp(rev *Revision) {
|
|||||||
a.mutex.Lock()
|
a.mutex.Lock()
|
||||||
defer a.mutex.Unlock()
|
defer a.mutex.Unlock()
|
||||||
|
|
||||||
|
PrintMsg(rev)
|
||||||
|
|
||||||
if rev.Profile != a.revision.Profile {
|
if rev.Profile != a.revision.Profile {
|
||||||
if err := a.UpdateProfile(); err != nil {
|
if err := a.UpdateProfile(); err != nil {
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
func TestMessangerApp(t *testing.T) {
|
func TestMessangerApp(t *testing.T) {
|
||||||
var params *TestApiParams
|
var params *TestApiParams
|
||||||
var response *TestApiResponse
|
var response *TestApiResponse
|
||||||
|
var channel *Channel
|
||||||
|
var topic *Topic
|
||||||
|
|
||||||
// allocate test accounts
|
// allocate test accounts
|
||||||
set, err := AddTestGroup("messangerapp")
|
set, err := AddTestGroup("messangerapp")
|
||||||
@ -52,25 +54,130 @@ func TestMessangerApp(t *testing.T) {
|
|||||||
restType: "POST",
|
restType: "POST",
|
||||||
query: "/content/channels",
|
query: "/content/channels",
|
||||||
body: &Subject{
|
body: &Subject{
|
||||||
Data: "channeldata",
|
Data: "channeldataA",
|
||||||
DataType: "channeldatatype",
|
DataType: "channeldatatypeA",
|
||||||
},
|
},
|
||||||
tokenType: APP_TOKENAPP,
|
tokenType: APP_TOKENAPP,
|
||||||
token: set.A.Token,
|
token: set.A.Token,
|
||||||
}
|
}
|
||||||
response = &TestApiResponse{}
|
channel = &Channel{}
|
||||||
|
response = &TestApiResponse{ data: channel }
|
||||||
assert.NoError(t, TestApiRequest(AddChannel, params, response))
|
assert.NoError(t, TestApiRequest(AddChannel, params, response))
|
||||||
|
|
||||||
// wait for test
|
// wait for test
|
||||||
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
|
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
|
||||||
for _, c := range testApp.channels {
|
for _, c := range testApp.channels {
|
||||||
if c.channel.Data.ChannelDetail.Data == "channeldata" {
|
if c.channel.Id == channel.Id {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
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: "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))
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user