testing card disconnection

This commit is contained in:
Roland Osborne 2022-02-23 23:18:23 -08:00
parent 16faf5eaf9
commit 6deaeba63d
3 changed files with 28 additions and 0 deletions

View File

@ -108,6 +108,7 @@ func SetCardStatus(w http.ResponseWriter, r *http.Request) {
slot.Card.NotifiedArticle = articleRevision
slot.Card.NotifiedChannel = channelRevision
slot.Card.NotifiedProfile = profileRevision
slot.Card.DetailRevision += 1
// save and update contact revision
err = store.DB.Transaction(func(tx *gorm.DB) error {

View File

@ -63,6 +63,9 @@ func SetCloseMessage(w http.ResponseWriter, r *http.Request) {
return res
}
}
if res := tx.Model(&card).Update("detail_revision", account.CardRevision + 1).Error; res != nil {
return res
}
if res := tx.Model(&slot).Update("revision", account.CardRevision + 1).Error; res != nil {
return res
}

View File

@ -178,4 +178,28 @@ func TestContactApp(t *testing.T) {
}
return false
}))
// disconnect from B
card := &Card{}
params = &TestApiParams{ restType: "PUT", query: "/contact/cards/{cardId}/status", tokenType: APP_TOKENAPP, token: set.B.Token,
path: map[string]string{ "cardId": set.B.A.CardId }, body: APP_CARDCONFIRMED }
response = &TestApiResponse{ data: card }
assert.NoError(t, TestApiRequest(SetCardStatus, params, response))
msg := &DataMessage{}
params = &TestApiParams { query: "/contact/cards/{cardId}/closeMessage", tokenType: APP_TOKENAPP, token: set.B.Token,
path: map[string]string{ "cardId": set.B.A.CardId } }
response = &TestApiResponse{ data: msg }
assert.NoError(t, TestApiRequest(GetCloseMessage, params, response))
params = &TestApiParams { restType: "PUT", query: "/contact/closeMessage", body: msg }
response = &TestApiResponse{}
assert.NoError(t, TestApiRequest(SetCloseMessage, params, response))
// wait for
assert.NoError(t, app.WaitFor(func(testApp *TestApp)bool {
contact, contactSet := testApp.contacts[set.A.B.CardId]
if contactSet && contact.card.Data.CardDetail.Status == APP_CARDCONFIRMED {
return true
}
return false
}))
}