sync contact profile in app test

This commit is contained in:
Roland Osborne 2022-02-23 15:00:11 -08:00
parent b0b752ee24
commit 16faf5eaf9
2 changed files with 52 additions and 31 deletions

View File

@ -25,12 +25,14 @@ type TestChannel struct {
} }
type TestContactData struct { type TestContactData struct {
token string
card Card card Card
profileRevision int64
viewRevision int64 viewRevision int64
articleRevision int64 articleRevision int64
channelRevision int64 channelRevision int64
detailRevision int64 cardDetailRevision int64
profileRevision int64 cardProfileRevision int64
articles map[string]Article articles map[string]Article
channels map[string]TestChannel channels map[string]TestChannel
offsync bool offsync bool
@ -38,19 +40,19 @@ type TestContactData struct {
func (c *TestContactData) UpdateContact() (err error) { func (c *TestContactData) UpdateContact() (err error) {
if c.detailRevision != c.card.Data.DetailRevision { if c.cardDetailRevision != c.card.Data.DetailRevision {
if err = c.UpdateContactCardDetail(); err != nil { if err = c.UpdateContactCardDetail(); err != nil {
return return
} else { } else {
c.detailRevision = c.card.Data.DetailRevision c.cardDetailRevision = c.card.Data.DetailRevision
} }
} }
if c.profileRevision != c.card.Data.ProfileRevision { if c.cardProfileRevision != c.card.Data.ProfileRevision {
if err = c.UpdateContactCardProfile(); err != nil { if err = c.UpdateContactCardProfile(); err != nil {
return return
} else { } else {
c.profileRevision = c.card.Data.ProfileRevision c.cardProfileRevision = c.card.Data.ProfileRevision
} }
} }
@ -99,7 +101,20 @@ func (c *TestContactData) UpdateContact() (err error) {
} }
func (c *TestContactData) UpdateContactProfile() (err error) { func (c *TestContactData) UpdateContactProfile() (err error) {
return nil var msg DataMessage
token := c.card.Data.CardProfile.Guid + "." + c.card.Data.CardDetail.Token
params := &TestApiParams{ query: "/profile/message", tokenType: APP_TOKENCONTACT, token: token }
response := &TestApiResponse{ data: &msg }
if err = TestApiRequest(GetProfileMessage, params, response); err != nil {
return
}
params = &TestApiParams{ restType: "PUT", query: "/contact/cards/{cardId}/profile", tokenType: APP_TOKENAPP, token: c.token,
path: map[string]string{ "cardId": c.card.Id }, body: &msg }
response = &TestApiResponse{}
if err = TestApiRequest(SetCardProfile, params, response); err != nil {
return
}
return
} }
func (c *TestContactData) UpdateContactArticle() (err error) { func (c *TestContactData) UpdateContactArticle() (err error) {
@ -138,11 +153,27 @@ func (c *TestContactData) UpdateContactChannel() (err error) {
} }
func (c *TestContactData) UpdateContactCardDetail() (err error) { func (c *TestContactData) UpdateContactCardDetail() (err error) {
return nil var cardDetail CardDetail
params := &TestApiParams{ query: "/contact/cards/{cardId}/detail", tokenType: APP_TOKENAPP, token: c.token,
path: map[string]string{ "cardId": c.card.Id } }
response := &TestApiResponse{ data: &cardDetail }
if err = TestApiRequest(GetCardDetail, params, response); err != nil {
return
}
c.card.Data.CardDetail = &cardDetail
return
} }
func (c *TestContactData) UpdateContactCardProfile() (err error) { func (c *TestContactData) UpdateContactCardProfile() (err error) {
return nil var cardProfile CardProfile
params := &TestApiParams{ query: "/contact/cards/{cardId}/profile", tokenType: APP_TOKENAPP, token: c.token,
path: map[string]string{ "cardId": c.card.Id } }
response := &TestApiResponse{ data: &cardProfile }
if err = TestApiRequest(GetCardProfile, params, response); err != nil {
return
}
c.card.Data.CardProfile = &cardProfile
return
} }
func NewTestApp() *TestApp { func NewTestApp() *TestApp {
@ -246,7 +277,8 @@ func (a *TestApp) UpdateCard() (err error) {
} 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),
detailRevision: card.Data.DetailRevision, profileRevision: card.Data.ProfileRevision } cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
profileRevision: card.Data.ProfileRevision, token: a.token }
a.contacts[card.Id] = contactData a.contacts[card.Id] = contactData
if err = contactData.UpdateContact(); err != nil { if err = contactData.UpdateContact(); err != nil {
contactData.offsync = true contactData.offsync = true
@ -275,7 +307,8 @@ func (a *TestApp) UpdateCard() (err error) {
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),
detailRevision: card.Data.DetailRevision, profileRevision: card.Data.ProfileRevision } cardDetailRevision: card.Data.DetailRevision, cardProfileRevision: card.Data.ProfileRevision,
profileRevision: card.Data.ProfileRevision, token: a.token }
a.contacts[card.Id] = contactData a.contacts[card.Id] = contactData
if err = contactData.UpdateContact(); err != nil { if err = contactData.UpdateContact(); err != nil {
contactData.offsync = true contactData.offsync = true

View File

@ -163,28 +163,16 @@ func TestContactApp(t *testing.T) {
return false return false
})) }))
for i := 0; i < 64; i++ { // update Bs profile
// add a new article in contact profileData = &ProfileData{ Name: "contactappname" }
article = &Article{} params = &TestApiParams{ restType: "PUT", query: "/profile/data", tokenType: APP_TOKENAPP, token: set.B.Token, body: profileData }
subject = &Subject{ Data: "subjectdataC", DataType: "subjectdatatypeC" } response = &TestApiResponse{}
params = &TestApiParams{ restType: "POST", query: "/articles", tokenType: APP_TOKENAPP, token: set.C.Token, body: subject } assert.NoError(t, TestApiRequest(SetProfile, params, response))
response = &TestApiResponse{ data: article }
assert.NoError(t, TestApiRequest(AddArticle, params, response))
articleId = article.Id
// share article // wait for
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 { assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.C.CardId] for _, contact := range testApp.contacts {
if contactSet { if contact.card.Data.CardProfile.Name == "contactappname" {
if len(contact.articles) == 64 {
return true return true
} }
} }