retrieving pending card in test

This commit is contained in:
Roland Osborne 2022-01-21 00:39:43 -08:00
parent e427f1c302
commit 718d726eab
4 changed files with 46 additions and 10 deletions

View File

@ -23,11 +23,6 @@ func ClearCardNotes(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
} }
func GetCard(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}
func GetCardData(w http.ResponseWriter, r *http.Request) { func GetCardData(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@ -0,0 +1,32 @@
package databag
import (
"errors"
"net/http"
"gorm.io/gorm"
"github.com/gorilla/mux"
"databag/internal/store"
)
func GetCard(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false);
if err != nil {
ErrResponse(w, code, err)
return
}
cardId := mux.Vars(r)["cardId"]
var card store.Card
if err := store.DB.Where("account_id = ? AND card_id = ?", account.ID, cardId).First(&card).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusNotFound, err)
} else {
ErrResponse(w, http.StatusInternalServerError, err)
}
return
}
WriteResponse(w, getCardModel(&card))
}

View File

@ -31,10 +31,10 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
// load referenced account // load referenced account
var account store.Account var account store.Account
if err := store.DB.Where("guid = ?", connect.Contact).First(&account).Error; err != nil { if err := store.DB.Where("guid = ?", connect.Contact).First(&account).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusInternalServerError, err)
} else {
ErrResponse(w, http.StatusNotFound, err) ErrResponse(w, http.StatusNotFound, err)
} else {
ErrResponse(w, http.StatusInternalServerError, err)
} }
return return
} }

View File

@ -74,13 +74,22 @@ func TestConnectContact(t *testing.T) {
assert.NoError(t, ReadResponse(w, &contactStatus)) assert.NoError(t, ReadResponse(w, &contactStatus))
// get view of cards in A // get view of cards in A
r, w, _ = NewRequest("GET", "/contact/card/view", nil) r, w, _ = NewRequest("GET", "/contact/cards/view", nil)
SetBearerAuth(r, access[0]) SetBearerAuth(r, access[0])
GetCardView(w, r) GetCardView(w, r)
var views []CardView var views []CardView
assert.NoError(t, ReadResponse(w, &views)) assert.NoError(t, ReadResponse(w, &views))
assert.Equal(t, len(views), 1)
PrintMsg(views); // get B card in A
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
vars = map[string]string{ "cardId": views[0].CardId }
r = mux.SetURLVars(r, vars)
SetBearerAuth(r, access[0])
GetCard(w, r)
assert.NoError(t, ReadResponse(w, &card))
PrintMsg(card);
// get new card // get new card