testing batch of attributes

This commit is contained in:
Roland Osborne 2022-02-22 22:11:56 -08:00
parent a47d936a70
commit 44d590f139
4 changed files with 119 additions and 8 deletions

View File

@ -109,9 +109,13 @@ func GetArticles(w http.ResponseWriter, r *http.Request) {
}
for _, slot := range slots {
shared := isArticleShared(card.Guid, slot.Article)
if !typesSet || hasArticleType(types, slot.Article) {
response = append(response, getArticleModel(&slot, shared, false))
shared := isArticleShared(card.Guid, slot.Article)
if articleRevisionSet {
response = append(response, getArticleModel(&slot, shared, false))
} else if shared {
response = append(response, getArticleModel(&slot, true, false))
}
}
}

View File

@ -113,8 +113,8 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
}
for _, slot := range slots {
shared := isChannelShared(card.Guid, slot.Channel)
if !typesSet || hasChannelType(types, slot.Channel) {
shared := isChannelShared(card.Guid, slot.Channel)
if channelRevisionSet {
response = append(response, getChannelRevisionModel(&slot, shared))
} else if shared {

View File

@ -39,13 +39,21 @@ type TestContactData struct {
func (c *TestContactData) UpdateContact() (err error) {
if c.detailRevision != c.card.Data.DetailRevision {
if err = c.UpdateContactDetail(); err != nil {
if err = c.UpdateContactCardDetail(); err != nil {
return
} else {
c.detailRevision = c.card.Data.DetailRevision
}
}
if c.profileRevision != c.card.Data.ProfileRevision {
if err = c.UpdateContactCardProfile(); err != nil {
return
} else {
c.profileRevision = c.card.Data.ProfileRevision
}
}
// sync rest only if connected
if c.card.Data.CardDetail.Status != APP_CARDCONNECTED {
return
@ -103,6 +111,7 @@ func (c *TestContactData) UpdateContactArticle() (err error) {
if err = TestApiRequest(GetArticles, params, response); err != nil {
return
}
c.articles = make(map[string]Article)
} else {
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
viewRevision := strconv.FormatInt(c.viewRevision, 10)
@ -128,7 +137,11 @@ func (c *TestContactData) UpdateContactChannel() (err error) {
return nil
}
func (c *TestContactData) UpdateContactDetail() (err error) {
func (c *TestContactData) UpdateContactCardDetail() (err error) {
return nil
}
func (c *TestContactData) UpdateContactCardProfile() (err error) {
return nil
}
@ -333,7 +346,10 @@ func (a *TestApp) UpdateApp(rev *Revision) {
if a.condition != nil {
if a.condition.check(a) {
a.condition.channel <- true
select {
case a.condition.channel <- true:
default:
}
}
}
}

View File

@ -90,13 +90,104 @@ func TestContactApp(t *testing.T) {
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.B.CardId]
if contactSet {
article, articleSet := contact.articles[articleId]
_, articleSet := contact.articles[articleId]
if articleSet {
PrintMsg(article)
return true
}
}
return false
}))
// remove new article in contact
article = &Article{}
params = &TestApiParams{ restType: "DELETE", query: "/articles/{articleId}", tokenType: APP_TOKENAPP, token: set.B.Token,
path: map[string]string{ "articleId": articleId }}
response = &TestApiResponse{ }
assert.NoError(t, TestApiRequest(RemoveArticle, params, response))
// wait for
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.B.CardId]
if contactSet {
_, articleSet := contact.articles[articleId]
if !articleSet {
return true
}
}
return false
}))
// add a new article in contact
article = &Article{}
subject = &Subject{ Data: "subjectdataB", DataType: "subjectdatatypeB" }
params = &TestApiParams{ restType: "POST", query: "/articles", tokenType: APP_TOKENAPP, token: set.B.Token, body: subject }
response = &TestApiResponse{ data: article }
assert.NoError(t, TestApiRequest(AddArticle, params, response))
articleId = article.Id
// share article
article = &Article{}
params = &TestApiParams{ restType: "POST", query: "/articles/{articleId}/groups/{groupId}", tokenType: APP_TOKENAPP, token: set.B.Token,
path: map[string]string{ "articleId": articleId, "groupId": set.B.A.GroupId }}
response = &TestApiResponse{ data: article }
assert.NoError(t, TestApiRequest(SetArticleGroup, params, response))
// wait for
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.B.CardId]
if contactSet {
_, articleSet := contact.articles[articleId]
if articleSet {
return true
}
}
return false
}))
// remove group in contact
article = &Article{}
params = &TestApiParams{ restType: "DELETE", query: "/groups/{groupId}", tokenType: APP_TOKENAPP, token: set.B.Token,
path: map[string]string{ "groupId": set.B.A.GroupId }}
response = &TestApiResponse{ }
assert.NoError(t, TestApiRequest(RemoveGroup, params, response))
// wait for
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.B.CardId]
if contactSet {
_, articleSet := contact.articles[articleId]
if !articleSet {
return true
}
}
return false
}))
for i := 0; i < 64; i++ {
// add a new article in contact
article = &Article{}
subject = &Subject{ Data: "subjectdataC", DataType: "subjectdatatypeC" }
params = &TestApiParams{ restType: "POST", query: "/articles", tokenType: APP_TOKENAPP, token: set.C.Token, body: subject }
response = &TestApiResponse{ data: article }
assert.NoError(t, TestApiRequest(AddArticle, params, response))
articleId = article.Id
// share article
article = &Article{}
params = &TestApiParams{ restType: "POST", query: "/articles/{articleId}/groups/{groupId}", tokenType: APP_TOKENAPP, token: set.C.Token,
path: map[string]string{ "articleId": articleId, "groupId": set.C.A.GroupId }}
response = &TestApiResponse{ data: article }
assert.NoError(t, TestApiRequest(SetArticleGroup, params, response))
}
// wait for
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.C.CardId]
if contactSet {
if len(contact.articles) == 64 {
return true
}
}
return false
}))
}