rename star -> ForgeLike

This commit is contained in:
Michael Jerger 2024-01-03 18:29:12 +01:00
parent 4473fb788a
commit 3ab2d9a449
6 changed files with 46 additions and 43 deletions

View file

@ -0,0 +1,34 @@
// Copyright 2023 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgefed
import (
"code.gitea.io/gitea/modules/validation"
ap "github.com/go-ap/activitypub"
)
// ForgeLike activity data type
// swagger:model
type ForgeLike struct {
// swagger:ignore
ap.Activity
}
func (s ForgeLike) MarshalJSON() ([]byte, error) {
return s.Activity.MarshalJSON()
}
func (s *ForgeLike) UnmarshalJSON(data []byte) error {
return s.Activity.UnmarshalJSON(data)
}
func (s ForgeLike) Validate() []string {
var result []string
result = append(result, validation.ValidateNotEmpty(string(s.Type), "type")...)
result = append(result, validation.ValidateNotEmpty(s.Actor.GetID().String(), "actor")...)
result = append(result, validation.ValidateNotEmpty(s.Object.GetID().String(), "object")...)
result = append(result, validation.ValidateNotEmpty(s.StartTime.String(), "startTime")...)
return result
}

View file

@ -12,18 +12,18 @@ import (
func Test_StarMarshalJSON(t *testing.T) {
type testPair struct {
item Star
item ForgeLike
want []byte
wantErr error
}
tests := map[string]testPair{
"empty": {
item: Star{},
item: ForgeLike{},
want: nil,
},
"with ID": {
item: Star{
item: ForgeLike{
Activity: ap.Activity{
Actor: ap.IRI("https://repo.prod.meissa.de/api/v1/activitypub/user-id/1"),
Type: "Like",
@ -51,17 +51,17 @@ func Test_StarMarshalJSON(t *testing.T) {
func Test_StarUnmarshalJSON(t *testing.T) {
type testPair struct {
item []byte
want *Star
want *ForgeLike
wantErr error
}
tests := map[string]testPair{
"with ID": {
item: []byte(`{"source":"forgejo","type":"Star","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"}`),
want: &Star{
item: []byte(`{"type":"Like","actor":"https://repo.prod.meissa.de/api/activitypub/user-id/1","object":"https://codeberg.org/api/activitypub/repository-id/1"}`),
want: &ForgeLike{
Activity: ap.Activity{
Actor: ap.IRI("https://repo.prod.meissa.de/api/activitypub/user-id/1"),
Type: "Star",
Type: "Like",
Object: ap.IRI("https://codeberg.org/api/activitypub/repository-id/1"),
},
},
@ -70,7 +70,7 @@ func Test_StarUnmarshalJSON(t *testing.T) {
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
got := new(Star)
got := new(ForgeLike)
err := got.UnmarshalJSON(tt.item)
if (err != nil || tt.wantErr != nil) && tt.wantErr.Error() != err.Error() {
t.Errorf("UnmarshalJSON() error = \"%v\", wantErr \"%v\"", err, tt.wantErr)

View file

@ -1,31 +0,0 @@
// Copyright 2023 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgefed
import (
"code.gitea.io/gitea/modules/validation"
ap "github.com/go-ap/activitypub"
)
// Star activity data type
// swagger:model
type Star struct {
// swagger:ignore
ap.Activity
}
func (a Star) MarshalJSON() ([]byte, error) {
return a.Activity.MarshalJSON()
}
func (s *Star) UnmarshalJSON(data []byte) error {
return s.UnmarshalJSON(data)
}
func (s Star) Validate() []string {
var result []string
result = append(result, validation.ValidateNotEmpty(string(s.Type), "type")...)
return result
}