syncing groups in test app

This commit is contained in:
Roland Osborne 2022-02-21 22:47:23 -08:00
parent 187452727b
commit d6aac227ae
2 changed files with 43 additions and 18 deletions

View File

@ -35,6 +35,7 @@ type TestContactData struct {
func NewTestApp() *TestApp {
return &TestApp{
groups: make(map[string]Group),
articles: make(map[string]Article),
channels: make(map[string]TestChannel),
contacts: make(map[string]TestContactData),
@ -45,6 +46,7 @@ type TestApp struct {
name string
revision Revision
profile Profile
groups map[string]Group
articles map[string]Article
channels map[string]TestChannel
contacts map[string]TestContactData
@ -62,6 +64,32 @@ func (a *TestApp) UpdateProfile() (err error) {
return
}
func (a *TestApp) UpdateGroup() (err error) {
var groups []Group
if a.revision.Group == 0 {
params := &TestApiParams{ query: "/groups", tokenType: APP_TOKENAPP, token: a.token }
response := &TestApiResponse{ data: &groups }
if err = TestApiRequest(GetGroups, params, response); err != nil {
return
}
} else {
revision := strconv.FormatInt(a.revision.Group, 10)
params := &TestApiParams{ query: "/groups?revision=" + revision, tokenType: APP_TOKENAPP, token: a.token }
response := &TestApiResponse{ data: &groups }
if err = TestApiRequest(GetGroups, params, response); err != nil {
return
}
}
for _, group := range groups {
if group.Data == nil {
delete(a.groups, group.Id)
} else {
a.groups[group.Id] = group
}
}
return
}
func (a *TestApp) UpdateArticle() (err error) {
var articles []Article
if a.revision.Article == 0 {
@ -88,11 +116,6 @@ func (a *TestApp) UpdateArticle() (err error) {
return
}
func (a *TestApp) UpdateGroup() (err error) {
PrintMsg("update group")
return
}
func (a *TestApp) UpdateChannel() (err error) {
PrintMsg("update channel")
return
@ -115,14 +138,6 @@ func (a *TestApp) UpdateApp(rev *Revision) {
}
}
if rev.Article != a.revision.Article {
if err := a.UpdateArticle(); err != nil {
PrintMsg(err)
} else {
a.revision.Article = rev.Article
}
}
if rev.Group != a.revision.Group {
if err := a.UpdateGroup(); err != nil {
PrintMsg(err)
@ -131,11 +146,11 @@ func (a *TestApp) UpdateApp(rev *Revision) {
}
}
if rev.Channel != a.revision.Channel {
if err := a.UpdateChannel(); err != nil {
if rev.Article != a.revision.Article {
if err := a.UpdateArticle(); err != nil {
PrintMsg(err)
} else {
a.revision.Channel = rev.Channel
a.revision.Article = rev.Article
}
}
@ -147,6 +162,14 @@ func (a *TestApp) UpdateApp(rev *Revision) {
}
}
if rev.Channel != a.revision.Channel {
if err := a.UpdateChannel(); err != nil {
PrintMsg(err)
} else {
a.revision.Channel = rev.Channel
}
}
if a.condition != nil {
if a.condition.check(a) {
a.condition.channel <- true

View File

@ -6,6 +6,8 @@ import (
)
func TestContactApp(t *testing.T) {
var params *TestApiParams
var response *TestApiResponse
// allocate test accounts
set, err := AddTestGroup("contactapp")
@ -42,8 +44,8 @@ func TestContactApp(t *testing.T) {
// add a new article
article := &Article{}
subject := &Subject{ Data: "subjectdata", DataType: "subjectdatatype" }
params := &TestApiParams{ restType: "POST", query: "/articles", tokenType: APP_TOKENAPP, token: set.A.Token, body: subject }
response := &TestApiResponse{ data: article }
params = &TestApiParams{ restType: "POST", query: "/articles", tokenType: APP_TOKENAPP, token: set.A.Token, body: subject }
response = &TestApiResponse{ data: article }
assert.NoError(t, TestApiRequest(AddArticle, params, response))
// wait for a