feat: Authors feature backend (and upgraded deprecated mods)
This commit is contained in:
1 parent
a11338094e
commit
b34a173d83
103 files changed
+6454
-240
No files matched your search
@@ -27,7 +27,7 @@ func newDisplayNameRouter(userRepo *mockUserRepo, token *jwtauth.JWTAuth) *chi.M
|
||||
getUser := useCases.NewGetUserUseCase(userRepo)
|
||||
update := useCases.NewUpdateUserProfileUseCase(userRepo, discardRecorder)
|
||||
handler := userhandler.NewHandler(update)
|
||||
meHandler := auth.NewMeHandler(getUser)
|
||||
meHandler := auth.NewMeHandler(getUser, useCases.NewGetMyAuthorUseCase(plainAuthors()))
|
||||
loginHandler := auth.NewLoginHandler(
|
||||
token,
|
||||
useCases.NewCreateUserUseCase(userRepo, hasher, newMockMailRepo(), "https://cms.example.com", discardRecorder),
|
||||
@@ -120,6 +120,22 @@ func assertSevenKeys(t *testing.T, body []byte) map[string]json.RawMessage {
|
||||
return decoded
|
||||
}
|
||||
|
||||
func assertMeKeys(t *testing.T, body []byte) map[string]json.RawMessage {
|
||||
t.Helper()
|
||||
decoded := decodeKeys(t, body)
|
||||
expected := append(append([]string{}, displayNameResponseKeys...), "author")
|
||||
if len(decoded) != len(expected) {
|
||||
t.Errorf("expected exactly %d keys, got %d: %s", len(expected), len(decoded), string(body))
|
||||
}
|
||||
for _, key := range expected {
|
||||
if _, present := decoded[key]; !present {
|
||||
t.Errorf("expected key %q in body %s", key, string(body))
|
||||
}
|
||||
}
|
||||
assertNoForbiddenKeys(t, body)
|
||||
return decoded
|
||||
}
|
||||
|
||||
func decodedString(t *testing.T, decoded map[string]json.RawMessage, key string) string {
|
||||
t.Helper()
|
||||
var value string
|
||||
@@ -368,7 +384,7 @@ func TestUserDisplayNameHttp(t *testing.T) {
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d", rec.Code)
|
||||
}
|
||||
decoded := assertSevenKeys(t, rec.Body.Bytes())
|
||||
decoded := assertMeKeys(t, rec.Body.Bytes())
|
||||
if decodedString(t, decoded, "display_name") != "Marta Alves" || decodedString(t, decoded, "username") != "marta" {
|
||||
t.Errorf("unexpected body: %s", rec.Body.String())
|
||||
}
|
||||
@@ -382,7 +398,7 @@ func TestUserDisplayNameHttp(t *testing.T) {
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d", rec.Code)
|
||||
}
|
||||
decoded := assertSevenKeys(t, rec.Body.Bytes())
|
||||
decoded := assertMeKeys(t, rec.Body.Bytes())
|
||||
if decodedString(t, decoded, "display_name") != "" {
|
||||
t.Errorf("expected empty display_name")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user