testing searchable flag

This commit is contained in:
Roland Osborne 2022-03-08 22:39:02 -08:00
parent dde82cd37b
commit d82cc5009b
5 changed files with 45 additions and 8 deletions

View File

@ -63,8 +63,4 @@ func GetAccountListing(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
func SetAccountSeachable(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
}

View File

@ -7,9 +7,9 @@ import (
func GetAccountStatus(w http.ResponseWriter, r *http.Request) {
account, err := AccountLogin(r)
account, code, err := BearerAppToken(r, false)
if err != nil {
ErrResponse(w, http.StatusUnauthorized, err)
ErrResponse(w, code, err)
return
}

View File

@ -0,0 +1,29 @@
package databag
import (
"net/http"
"databag/internal/store"
)
func SetAccountSearchable(w http.ResponseWriter, r *http.Request) {
account, code, err := BearerAppToken(r, false)
if err != nil {
ErrResponse(w, code, err)
return
}
var flag bool
if err := ParseRequest(r, w, &flag); err != nil {
ErrResponse(w, http.StatusBadRequest, err)
return
}
if err = store.DB.Model(account).Update("searchable", flag).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
WriteResponse(w, nil)
}

View File

@ -180,6 +180,13 @@ var routes = Routes{
SetAccountNode,
},
Route{
"SetAccountSerchable",
strings.ToUpper("Put"),
"/account/searchable",
SetAccountSearchable,
},
Route{
"AddNodeAccount",
strings.ToUpper("Post"),

View File

@ -92,12 +92,17 @@ func TestAccountConfig(t *testing.T) {
return false
}))
// set to searchable
searchable := true
params = &TestApiParams{ query: "/account/searchable", tokenType: APP_TOKENAPP, token: set.A.Token, body: &searchable }
assert.NoError(t, TestApiRequest(SetAccountSearchable, params, nil))
// get account status
accountStatus := &AccountStatus{}
params = &TestApiParams{ query: "/account/status", authorization: "newguy:ssap",
path: map[string]string{ "channelId": channel.Id, "topicId": topic.Id } }
params = &TestApiParams{ query: "/account/status", tokenType: APP_TOKENAPP, token: set.A.Token }
response = &TestApiResponse{ data: accountStatus }
assert.NoError(t, TestApiRequest(GetAccountStatus, params, response))
assert.True(t, accountStatus.Searchable)
// add asset to topic
assets = &[]Asset{}