diff --git a/models/forgefed/activity.go b/models/forgefed/activity.go index 4f5b1ddc65..19075a76b3 100644 --- a/models/forgefed/activity.go +++ b/models/forgefed/activity.go @@ -6,7 +6,6 @@ package forgefed import ( "time" - "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/validation" ap "github.com/go-ap/activitypub" @@ -19,17 +18,12 @@ type ForgeLike struct { ap.Activity } -// TODO: Use explicit values instead of ctx !! func NewForgeLike(actorIRI string, objectIRI string) (ForgeLike, error) { result := ForgeLike{} result.Type = ap.LikeType // ToDo: Would validating the source by Actor.Type field make sense? - object := new(ap.Object) - object.ID = ap.IRI(objectIRI) - - result.Actor = ap.ActorNew(ap.IRI(actorIRI), "ForgejoUser") // Thats us, a User - result.Object = object // Thats them, a Repository - log.Info("Object is: %v", object) + result.Actor = ap.IRI(actorIRI) // Thats us, a User + result.Object = ap.IRI(objectIRI) // Thats them, a Repository result.StartTime = time.Now() if valid, err := validation.IsValid(result); !valid { return ForgeLike{}, err diff --git a/models/forgefed/activity_test.go b/models/forgefed/activity_test.go index d4196cc972..6fb455db11 100644 --- a/models/forgefed/activity_test.go +++ b/models/forgefed/activity_test.go @@ -12,6 +12,30 @@ import ( ap "github.com/go-ap/activitypub" ) +// TODO: fix this test. mock time.Now? +func Test_NewForgeLike(t *testing.T) { + actorIRI := "https://repo.prod.meissa.de/api/v1/activitypub/user-id/1" + objectIRI := "https://codeberg.org/api/v1/activitypub/repository-id/1" + want := []byte(`{"type":"Like","actor":"https://repo.prod.meissa.de/api/v1/activitypub/user-id/1","object":"https://codeberg.org/api/v1/activitypub/repository-id/1"}`) + + sut, err := NewForgeLike(actorIRI, objectIRI) + if err != nil { + t.Errorf("unexpected error: %v\n", err) + } + if valid, _ := validation.IsValid(sut); !valid { + t.Errorf("sut expected to be valid: %v\n", sut.Validate()) + } + + got, err := sut.MarshalJSON() + if err != nil { + t.Errorf("MarshalJSON() error = \"%v\"", err) + return + } + if !reflect.DeepEqual(got, want) { + t.Errorf("MarshalJSON() got = %q, want %q", got, want) + } +} + func Test_StarMarshalJSON(t *testing.T) { type testPair struct { item ForgeLike