mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
testing batch of attributes
This commit is contained in:
parent
a47d936a70
commit
44d590f139
@ -109,9 +109,13 @@ func GetArticles(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, slot := range slots {
|
for _, slot := range slots {
|
||||||
shared := isArticleShared(card.Guid, slot.Article)
|
|
||||||
if !typesSet || hasArticleType(types, 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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, slot := range slots {
|
for _, slot := range slots {
|
||||||
shared := isChannelShared(card.Guid, slot.Channel)
|
|
||||||
if !typesSet || hasChannelType(types, slot.Channel) {
|
if !typesSet || hasChannelType(types, slot.Channel) {
|
||||||
|
shared := isChannelShared(card.Guid, slot.Channel)
|
||||||
if channelRevisionSet {
|
if channelRevisionSet {
|
||||||
response = append(response, getChannelRevisionModel(&slot, shared))
|
response = append(response, getChannelRevisionModel(&slot, shared))
|
||||||
} else if shared {
|
} else if shared {
|
||||||
|
@ -39,13 +39,21 @@ type TestContactData struct {
|
|||||||
func (c *TestContactData) UpdateContact() (err error) {
|
func (c *TestContactData) UpdateContact() (err error) {
|
||||||
|
|
||||||
if c.detailRevision != c.card.Data.DetailRevision {
|
if c.detailRevision != c.card.Data.DetailRevision {
|
||||||
if err = c.UpdateContactDetail(); err != nil {
|
if err = c.UpdateContactCardDetail(); err != nil {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
c.detailRevision = c.card.Data.DetailRevision
|
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
|
// sync rest only if connected
|
||||||
if c.card.Data.CardDetail.Status != APP_CARDCONNECTED {
|
if c.card.Data.CardDetail.Status != APP_CARDCONNECTED {
|
||||||
return
|
return
|
||||||
@ -103,6 +111,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)
|
||||||
} 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)
|
||||||
@ -128,7 +137,11 @@ func (c *TestContactData) UpdateContactChannel() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *TestContactData) UpdateContactDetail() (err error) {
|
func (c *TestContactData) UpdateContactCardDetail() (err error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *TestContactData) UpdateContactCardProfile() (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +346,10 @@ func (a *TestApp) UpdateApp(rev *Revision) {
|
|||||||
|
|
||||||
if a.condition != nil {
|
if a.condition != nil {
|
||||||
if a.condition.check(a) {
|
if a.condition.check(a) {
|
||||||
a.condition.channel <- true
|
select {
|
||||||
|
case a.condition.channel <- true:
|
||||||
|
default:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,13 +90,104 @@ func TestContactApp(t *testing.T) {
|
|||||||
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
|
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
|
||||||
contact, contactSet := testApp.contacts[set.A.B.CardId]
|
contact, contactSet := testApp.contacts[set.A.B.CardId]
|
||||||
if contactSet {
|
if contactSet {
|
||||||
article, articleSet := contact.articles[articleId]
|
_, articleSet := contact.articles[articleId]
|
||||||
if articleSet {
|
if articleSet {
|
||||||
PrintMsg(article)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
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
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user