fixing unti test, caught many issues

This commit is contained in:
Roland Osborne 2022-11-15 10:04:45 -08:00
parent 53f947d675
commit df64fef322
12 changed files with 21 additions and 23 deletions

View File

@ -7,7 +7,7 @@ import (
//Authorize confirm account authorization with signed data message //Authorize confirm account authorization with signed data message
func Authorize(w http.ResponseWriter, r *http.Request) { func Authorize(w http.ResponseWriter, r *http.Request) {
account, code, res := BearerAppToken(r, true) account, code, res := ParamAgentToken(r, true)
if res != nil { if res != nil {
ErrResponse(w, code, res) ErrResponse(w, code, res)
return return

View File

@ -11,7 +11,7 @@ import (
//ClearCardGroup removes card from sharing group //ClearCardGroup removes card from sharing group
func ClearCardGroup(w http.ResponseWriter, r *http.Request) { func ClearCardGroup(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false) account, code, err := ParamAgentToken(r, false)
if err != nil { if err != nil {
ErrResponse(w, code, err) ErrResponse(w, code, err)
return return

View File

@ -11,7 +11,7 @@ import (
//ClearCardNotes clear notes assigned to card //ClearCardNotes clear notes assigned to card
func ClearCardNotes(w http.ResponseWriter, r *http.Request) { func ClearCardNotes(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false) account, code, err := ParamAgentToken(r, false)
if err != nil { if err != nil {
ErrResponse(w, code, err) ErrResponse(w, code, err)
return return

View File

@ -11,7 +11,7 @@ import (
//ClearChannelGroup removes sharing group from channel //ClearChannelGroup removes sharing group from channel
func ClearChannelGroup(w http.ResponseWriter, r *http.Request) { func ClearChannelGroup(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false) account, code, err := ParamAgentToken(r, false)
if err != nil { if err != nil {
ErrResponse(w, code, err) ErrResponse(w, code, err)
return return
@ -24,7 +24,7 @@ func ClearChannelGroup(w http.ResponseWriter, r *http.Request) {
// load referenced channel // load referenced channel
var channelSlot store.ChannelSlot var channelSlot store.ChannelSlot
if err := store.DB.Preload("Channel.Cards.CardSlot").Preload("Channel.Groups.GroupSlot").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_slot_id = ?", account.ID, channelID).First(&channelSlot).Error; err != nil { if err := store.DB.Preload("Channel.Members.Card.CardSlot").Preload("Channel.Groups.GroupSlot").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_slot_id = ?", account.ID, channelID).First(&channelSlot).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusInternalServerError, err) ErrResponse(w, http.StatusInternalServerError, err)
} else { } else {

View File

@ -73,9 +73,9 @@ func RemoveChannel(w http.ResponseWriter, r *http.Request) {
return res return res
} }
slot.Channel.Groups = []store.Group{} slot.Channel.Groups = []store.Group{}
if res := tx.Model(&slot.Channel).Association("Cards").Clear(); res != nil { if res := tx.Where("channel_id = ?", slot.Channel.ID).Delete(&store.Member{}).Error; res != nil {
return res return res
} }
slot.Channel.Members = []store.Member{} slot.Channel.Members = []store.Member{}
if res := tx.Where("channel_id = ?", slot.Channel.ID).Delete(&store.Tag{}).Error; res != nil { if res := tx.Where("channel_id = ?", slot.Channel.ID).Delete(&store.Tag{}).Error; res != nil {
return res return res

View File

@ -10,7 +10,7 @@ import (
//SetCardGroup assigns contact to sharing group //SetCardGroup assigns contact to sharing group
func SetCardGroup(w http.ResponseWriter, r *http.Request) { func SetCardGroup(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false) account, code, err := ParamAgentToken(r, false)
if err != nil { if err != nil {
ErrResponse(w, code, err) ErrResponse(w, code, err)
return return

View File

@ -11,7 +11,7 @@ import (
//SetCardNotes assignes notes to contact in account //SetCardNotes assignes notes to contact in account
func SetCardNotes(w http.ResponseWriter, r *http.Request) { func SetCardNotes(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false) account, code, err := ParamAgentToken(r, false)
if err != nil { if err != nil {
ErrResponse(w, code, err) ErrResponse(w, code, err)
return return

View File

@ -11,7 +11,7 @@ import (
//SetChannelGroup adds sharing group to channel //SetChannelGroup adds sharing group to channel
func SetChannelGroup(w http.ResponseWriter, r *http.Request) { func SetChannelGroup(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false) account, code, err := ParamAgentToken(r, false)
if err != nil { if err != nil {
ErrResponse(w, code, err) ErrResponse(w, code, err)
return return
@ -24,7 +24,7 @@ func SetChannelGroup(w http.ResponseWriter, r *http.Request) {
// load referenced channel // load referenced channel
var channelSlot store.ChannelSlot var channelSlot store.ChannelSlot
if err := store.DB.Preload("Channel.Cards.CardSlot").Preload("Channel.Groups.GroupSlot").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_slot_id = ?", account.ID, channelID).First(&channelSlot).Error; err != nil { if err := store.DB.Preload("Channel.Members.Card.CardSlot").Preload("Channel.Groups.GroupSlot").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_slot_id = ?", account.ID, channelID).First(&channelSlot).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusInternalServerError, err) ErrResponse(w, http.StatusInternalServerError, err)
} else { } else {

View File

@ -29,7 +29,7 @@ func SetChannelSubject(w http.ResponseWriter, r *http.Request) {
// load referenced channel // load referenced channel
var slot store.ChannelSlot var slot store.ChannelSlot
if err := store.DB.Preload("Channel.Cards").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_slot_id = ?", account.ID, channelID).First(&slot).Error; err != nil { if err := store.DB.Preload("Channel.Members.Card").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_slot_id = ?", account.ID, channelID).First(&slot).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusInternalServerError, err) ErrResponse(w, http.StatusInternalServerError, err)
} else { } else {

View File

@ -95,7 +95,7 @@ func ParamAdminToken(r *http.Request) (int, error) {
return http.StatusOK, nil return http.StatusOK, nil
} }
//ParamAgentToken retrieves account specified by agent query param //GetSession retrieves account specified by agent query param
func GetSession(r *http.Request) (*store.Session, int, error) { func GetSession(r *http.Request) (*store.Session, int, error) {
// parse authentication token // parse authentication token

View File

@ -513,13 +513,12 @@ func groupTestCard(account string, cardID string) (groupID string, err error) {
groupID = group.ID groupID = group.ID
// set contact group // set contact group
if r, w, err = NewRequest("PUT", "/contact/cards/{cardID}/groups/{groupID}", nil); err != nil { if r, w, err = NewRequest("PUT", "/contact/cards/{cardID}/groups/{groupID}?agent="+account, nil); err != nil {
return return
} }
vars["groupID"] = group.ID vars["groupID"] = group.ID
vars["cardID"] = cardID vars["cardID"] = cardID
r = mux.SetURLVars(r, vars) r = mux.SetURLVars(r, vars)
SetBearerAuth(r, account)
SetCardGroup(w, r) SetCardGroup(w, r)
if err = ReadResponse(w, &cardData); err != nil { if err = ReadResponse(w, &cardData); err != nil {
return return
@ -653,10 +652,9 @@ func addTestAccount(username string) (guid string, token string, err error) {
token = access.AppToken token = access.AppToken
// authorize claim // authorize claim
if r, w, err = NewRequest("PUT", "/authorize", "1234abcd"); err != nil { if r, w, err = NewRequest("PUT", "/authorize?agent="+token, "1234abcd"); err != nil {
return return
} }
SetBearerAuth(r, token)
Authorize(w, r) Authorize(w, r)
if err = ReadResponse(w, &msg); err != nil { if err = ReadResponse(w, &msg); err != nil {
return return

View File

@ -30,7 +30,7 @@ func transcodeVideo() {
defer videoSync.Unlock() defer videoSync.Unlock()
for { for {
var asset store.Asset var asset store.Asset
if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Cards").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue = ? AND status = ?", APPQueueVideo, APPAssetWaiting).First(&asset).Error; err != nil { if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Members.Card").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue = ? AND status = ?", APPQueueVideo, APPAssetWaiting).First(&asset).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrMsg(err) ErrMsg(err)
} }
@ -45,7 +45,7 @@ func transcodeAudio() {
defer audioSync.Unlock() defer audioSync.Unlock()
for { for {
var asset store.Asset var asset store.Asset
if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Cards").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue = ? AND status = ?", APPQueueAudio, APPAssetWaiting).First(&asset).Error; err != nil { if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Members.Card").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue = ? AND status = ?", APPQueueAudio, APPAssetWaiting).First(&asset).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrMsg(err) ErrMsg(err)
} }
@ -60,7 +60,7 @@ func transcodePhoto() {
defer photoSync.Unlock() defer photoSync.Unlock()
for { for {
var asset store.Asset var asset store.Asset
if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Cards").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue = ? AND status = ?", APPQueuePhoto, APPAssetWaiting).First(&asset).Error; err != nil { if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Members.Card").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue = ? AND status = ?", APPQueuePhoto, APPAssetWaiting).First(&asset).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrMsg(err) ErrMsg(err)
} }
@ -75,7 +75,7 @@ func transcodeDefault() {
defer defaultSync.Unlock() defer defaultSync.Unlock()
for { for {
var asset store.Asset var asset store.Asset
if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Cards").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue != ? AND transform_queue != ? AND transform_queue != ? AND status = ?", APPQueueVideo, APPQueueAudio, APPQueuePhoto, APPAssetWaiting).First(&asset).Error; err != nil { if err := store.DB.Order("created asc").Preload("Account").Preload("Channel.Members.Card").Preload("Channel.Groups.Cards").Preload("Channel.ChannelSlot").Preload("Topic.TopicSlot").Where("transform_queue != ? AND transform_queue != ? AND transform_queue != ? AND status = ?", APPQueueVideo, APPQueueAudio, APPQueuePhoto, APPAssetWaiting).First(&asset).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
ErrMsg(err) ErrMsg(err)
} }
@ -147,7 +147,7 @@ func updateAsset(asset *store.Asset, status string, crc uint32, size int64) (err
if asset.Topic == nil { if asset.Topic == nil {
return errors.New("asset not found") return errors.New("asset not found")
} }
if res := tx.Preload("Account").Preload("TopicSlot").Preload("Channel.Groups").Preload("Channel.Cards").Preload("Channel.ChannelSlot").First(&topic, asset.Topic.ID).Error; res != nil { if res := tx.Preload("Account").Preload("TopicSlot").Preload("Channel.Groups").Preload("Channel.Members.Card").Preload("Channel.ChannelSlot").First(&topic, asset.Topic.ID).Error; res != nil {
return res return res
} }
if res := tx.Model(&topic).Update("detail_revision", topic.Account.ChannelRevision+1).Error; res != nil { if res := tx.Model(&topic).Update("detail_revision", topic.Account.ChannelRevision+1).Error; res != nil {