mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
adding messanger app use case
This commit is contained in:
parent
3c2a9f8550
commit
ae506a4df5
@ -47,10 +47,6 @@ func GetChannel(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if slot.Channel == nil {
|
|
||||||
ErrResponse(w, http.StatusNotFound, errors.New("referenced channel missing"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// return model data
|
// return model data
|
||||||
if guid != "" {
|
if guid != "" {
|
||||||
|
@ -33,8 +33,8 @@ type TestContactData struct {
|
|||||||
channelRevision int64
|
channelRevision int64
|
||||||
cardDetailRevision int64
|
cardDetailRevision int64
|
||||||
cardProfileRevision int64
|
cardProfileRevision int64
|
||||||
articles map[string]Article
|
articles map[string]*Article
|
||||||
channels map[string]TestChannel
|
channels map[string]*TestChannel
|
||||||
offsync bool
|
offsync bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func (c *TestContactData) UpdateContactArticle() (err error) {
|
|||||||
if err = TestApiRequest(GetArticles, params, response); err != nil {
|
if err = TestApiRequest(GetArticles, params, response); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.articles = make(map[string]Article)
|
c.articles = make(map[string]*Article)
|
||||||
} else {
|
} else {
|
||||||
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
|
||||||
viewRevision := strconv.FormatInt(c.viewRevision, 10)
|
viewRevision := strconv.FormatInt(c.viewRevision, 10)
|
||||||
@ -142,7 +142,7 @@ func (c *TestContactData) UpdateContactArticle() (err error) {
|
|||||||
if article.Data == nil {
|
if article.Data == nil {
|
||||||
delete(c.articles, article.Id)
|
delete(c.articles, article.Id)
|
||||||
} else {
|
} else {
|
||||||
c.articles[article.Id] = article
|
c.articles[article.Id] = &article
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -178,9 +178,9 @@ func (c *TestContactData) UpdateContactCardProfile() (err error) {
|
|||||||
|
|
||||||
func NewTestApp() *TestApp {
|
func NewTestApp() *TestApp {
|
||||||
return &TestApp{
|
return &TestApp{
|
||||||
groups: make(map[string]Group),
|
groups: make(map[string]*Group),
|
||||||
articles: make(map[string]Article),
|
articles: make(map[string]*Article),
|
||||||
channels: make(map[string]TestChannel),
|
channels: make(map[string]*TestChannel),
|
||||||
contacts: make(map[string]*TestContactData),
|
contacts: make(map[string]*TestContactData),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -189,9 +189,9 @@ type TestApp struct {
|
|||||||
name string
|
name string
|
||||||
revision Revision
|
revision Revision
|
||||||
profile Profile
|
profile Profile
|
||||||
groups map[string]Group
|
groups map[string]*Group
|
||||||
articles map[string]Article
|
articles map[string]*Article
|
||||||
channels map[string]TestChannel
|
channels map[string]*TestChannel
|
||||||
contacts map[string]*TestContactData
|
contacts map[string]*TestContactData
|
||||||
|
|
||||||
token string
|
token string
|
||||||
@ -207,7 +207,7 @@ func (a *TestApp) UpdateProfile() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) UpdateGroup() (err error) {
|
func (a *TestApp) UpdateGroups() (err error) {
|
||||||
var groups []Group
|
var groups []Group
|
||||||
if a.revision.Group == 0 {
|
if a.revision.Group == 0 {
|
||||||
params := &TestApiParams{ query: "/groups", tokenType: APP_TOKENAPP, token: a.token }
|
params := &TestApiParams{ query: "/groups", tokenType: APP_TOKENAPP, token: a.token }
|
||||||
@ -227,13 +227,13 @@ func (a *TestApp) UpdateGroup() (err error) {
|
|||||||
if group.Data == nil {
|
if group.Data == nil {
|
||||||
delete(a.groups, group.Id)
|
delete(a.groups, group.Id)
|
||||||
} else {
|
} else {
|
||||||
a.groups[group.Id] = group
|
a.groups[group.Id] = &group
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) UpdateArticle() (err error) {
|
func (a *TestApp) UpdateArticles() (err error) {
|
||||||
var articles []Article
|
var articles []Article
|
||||||
if a.revision.Article == 0 {
|
if a.revision.Article == 0 {
|
||||||
params := &TestApiParams{ query: "/articles", tokenType: APP_TOKENAPP, token: a.token }
|
params := &TestApiParams{ query: "/articles", tokenType: APP_TOKENAPP, token: a.token }
|
||||||
@ -253,17 +253,76 @@ func (a *TestApp) UpdateArticle() (err error) {
|
|||||||
if article.Data == nil {
|
if article.Data == nil {
|
||||||
delete(a.articles, article.Id)
|
delete(a.articles, article.Id)
|
||||||
} else {
|
} else {
|
||||||
a.articles[article.Id] = article
|
a.articles[article.Id] = &article
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) UpdateChannel() (err error) {
|
func (a *TestApp) UpdateChannels() (err error) {
|
||||||
|
var channels []Channel
|
||||||
|
if a.revision.Channel == 0 {
|
||||||
|
params := &TestApiParams{ query: "/channels", tokenType: APP_TOKENAPP, token: a.token }
|
||||||
|
response := &TestApiResponse{ data: &channels }
|
||||||
|
if err = TestApiRequest(GetChannels, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
revision := strconv.FormatInt(a.revision.Channel, 10)
|
||||||
|
params := &TestApiParams{ query: "/channels?channelRevision=" + revision, tokenType: APP_TOKENAPP, token: a.token }
|
||||||
|
response := &TestApiResponse{ data: &channels }
|
||||||
|
if err = TestApiRequest(GetChannels, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, channel := range channels {
|
||||||
|
if channel.Data == nil {
|
||||||
|
delete(a.channels, channel.Id)
|
||||||
|
} else {
|
||||||
|
c, set := a.channels[channel.Id]
|
||||||
|
if set {
|
||||||
|
if channel.Revision != c.channel.Revision {
|
||||||
|
if err = a.UpdateChannel(c, &channel); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.channel.Revision = channel.Revision
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c := &TestChannel{ channel: Channel{ Id: channel.Id }, topics: map[string]Topic{} }
|
||||||
|
a.channels[channel.Id] = c
|
||||||
|
if err = a.UpdateChannel(c, &channel); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.channel.Revision = channel.Revision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *TestApp) UpdateCard() (err error) {
|
func (a *TestApp) UpdateChannel(testChannel *TestChannel, channel *Channel) (err error) {
|
||||||
|
if testChannel.channel.Revision != channel.Revision {
|
||||||
|
if channel.Data.ChannelDetail != nil {
|
||||||
|
testChannel.channel = *channel
|
||||||
|
} else if testChannel.channel.Data == nil || testChannel.channel.Data.DetailRevision != channel.Data.DetailRevision {
|
||||||
|
c := Channel{}
|
||||||
|
params := &TestApiParams{ query: "/channel/{channelId}", path: map[string]string{ "channelId": channel.Id }, tokenType: APP_TOKENAPP, token: a.token }
|
||||||
|
response := &TestApiResponse{ data: &c }
|
||||||
|
if err = TestApiRequest(GetChannel, params, response); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if c.Data == nil {
|
||||||
|
delete(a.channels, channel.Id)
|
||||||
|
}
|
||||||
|
testChannel.channel = c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO update topics
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *TestApp) UpdateCards() (err error) {
|
||||||
var cards []Card
|
var cards []Card
|
||||||
if a.revision.Card == 0 {
|
if a.revision.Card == 0 {
|
||||||
params := &TestApiParams{ query: "/cards", tokenType: APP_TOKENAPP, token: a.token }
|
params := &TestApiParams{ query: "/cards", tokenType: APP_TOKENAPP, token: a.token }
|
||||||
@ -276,7 +335,7 @@ func (a *TestApp) UpdateCard() (err error) {
|
|||||||
delete(a.contacts, card.Id)
|
delete(a.contacts, card.Id)
|
||||||
} else {
|
} else {
|
||||||
// set new card
|
// set new card
|
||||||
contactData := &TestContactData{ card: card, articles: make(map[string]Article), channels: make(map[string]TestChannel),
|
contactData := &TestContactData{ card: card, articles: make(map[string]*Article), channels: make(map[string]*TestChannel),
|
||||||
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
||||||
profileRevision: card.Data.ProfileRevision, token: a.token }
|
profileRevision: card.Data.ProfileRevision, token: a.token }
|
||||||
a.contacts[card.Id] = contactData
|
a.contacts[card.Id] = contactData
|
||||||
@ -306,7 +365,7 @@ func (a *TestApp) UpdateCard() (err error) {
|
|||||||
if err = TestApiRequest(GetCard, params, response); err != nil {
|
if err = TestApiRequest(GetCard, params, response); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
contactData := &TestContactData{ card: card, articles: make(map[string]Article), channels: make(map[string]TestChannel),
|
contactData := &TestContactData{ card: card, articles: make(map[string]*Article), channels: make(map[string]*TestChannel),
|
||||||
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
|
||||||
profileRevision: card.Data.ProfileRevision, token: a.token }
|
profileRevision: card.Data.ProfileRevision, token: a.token }
|
||||||
a.contacts[card.Id] = contactData
|
a.contacts[card.Id] = contactData
|
||||||
@ -346,7 +405,7 @@ func (a *TestApp) UpdateApp(rev *Revision) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rev.Group != a.revision.Group {
|
if rev.Group != a.revision.Group {
|
||||||
if err := a.UpdateGroup(); err != nil {
|
if err := a.UpdateGroups(); err != nil {
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
} else {
|
} else {
|
||||||
a.revision.Group = rev.Group
|
a.revision.Group = rev.Group
|
||||||
@ -354,7 +413,7 @@ func (a *TestApp) UpdateApp(rev *Revision) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rev.Article != a.revision.Article {
|
if rev.Article != a.revision.Article {
|
||||||
if err := a.UpdateArticle(); err != nil {
|
if err := a.UpdateArticles(); err != nil {
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
} else {
|
} else {
|
||||||
a.revision.Article = rev.Article
|
a.revision.Article = rev.Article
|
||||||
@ -362,7 +421,7 @@ func (a *TestApp) UpdateApp(rev *Revision) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rev.Card != a.revision.Card {
|
if rev.Card != a.revision.Card {
|
||||||
if err := a.UpdateCard(); err != nil {
|
if err := a.UpdateCards(); err != nil {
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
} else {
|
} else {
|
||||||
a.revision.Card = rev.Card
|
a.revision.Card = rev.Card
|
||||||
@ -370,7 +429,7 @@ func (a *TestApp) UpdateApp(rev *Revision) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if rev.Channel != a.revision.Channel {
|
if rev.Channel != a.revision.Channel {
|
||||||
if err := a.UpdateChannel(); err != nil {
|
if err := a.UpdateChannels(); err != nil {
|
||||||
PrintMsg(err)
|
PrintMsg(err)
|
||||||
} else {
|
} else {
|
||||||
a.revision.Channel = rev.Channel
|
a.revision.Channel = rev.Channel
|
||||||
|
3
net/server/internal/testscripts/transform_copy.sh
Executable file
3
net/server/internal/testscripts/transform_copy.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cp $1 $2
|
76
net/server/internal/ucMessangerApp_test.go
Normal file
76
net/server/internal/ucMessangerApp_test.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package databag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMessangerApp(t *testing.T) {
|
||||||
|
var params *TestApiParams
|
||||||
|
var response *TestApiResponse
|
||||||
|
|
||||||
|
// 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{
|
||||||
|
Data: "channeldata",
|
||||||
|
DataType: "channeldatatype",
|
||||||
|
},
|
||||||
|
tokenType: APP_TOKENAPP,
|
||||||
|
token: set.A.Token,
|
||||||
|
}
|
||||||
|
response = &TestApiResponse{}
|
||||||
|
assert.NoError(t, TestApiRequest(AddChannel, params, response))
|
||||||
|
|
||||||
|
// wait for test
|
||||||
|
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool{
|
||||||
|
for _, c := range testApp.channels {
|
||||||
|
if c.channel.Data.ChannelDetail.Data == "channeldata" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user