testing accont listing

This commit is contained in:
Roland Osborne 2022-03-08 23:05:04 -08:00
parent d82cc5009b
commit 2ae2f857f8
4 changed files with 41 additions and 9 deletions

View File

@ -300,8 +300,6 @@ paths:
- account
description: Get profile of searchable accounts. Endpoint is publically accessible.
operationId: get-account-listing
security:
- bearerAuth: []
parameters:
- name: guid
in: query
@ -351,7 +349,7 @@ paths:
description: Get disabled status of account. Authorized to account username and password.
operationId: get-account-status
security:
- basicAuth: []
- bearerAuth: []
responses:
'200':
description: successful operation
@ -371,7 +369,7 @@ paths:
description: Set whether account is publicly listed.
operationId: set-account-seachable
security:
- basicAuth: []
- bearerAuth: []
responses:
'201':
description: success

View File

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

View File

@ -0,0 +1,32 @@
package databag
import (
"net/http"
"databag/internal/store"
)
func GetAccountListing(w http.ResponseWriter, r *http.Request) {
var accounts []store.Account
if err := store.DB.Preload("AccountDetail").Where("searchable = ? AND disabled = ?", true, false).Find(&accounts).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
}
profiles := []CardProfile{}
for _, account := range accounts {
profiles = append(profiles, CardProfile{
Guid: account.Guid,
Handle: account.Username,
Name: account.AccountDetail.Name,
Description: account.AccountDetail.Description,
Location: account.AccountDetail.Location,
ImageSet: account.AccountDetail.Image != "",
Version: APP_VERSION,
Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/",
})
}
WriteResponse(w, &profiles)
}

View File

@ -111,6 +111,12 @@ func TestAccountConfig(t *testing.T) {
"/content/channels/{channelId}/topics/{topicId}/assets?transforms=" + url.QueryEscape(string(transforms)),
pathParams, img, APP_TOKENAPP, set.A.Token, assets, nil))
PrintMsg(accountStatus)
// get list of accounts
profiles := []CardProfile{}
params = &TestApiParams{ query: "/account/listing" }
response = &TestApiResponse{ data: &profiles }
assert.NoError(t, TestApiRequest(GetAccountListing, params, response))
assert.Equal(t, 1, len(profiles))
assert.Equal(t, set.A.Guid, profiles[0].Guid);
}