Files
archie/internal/webui/tasks_links_test.go
sam 184038a918
deploy / gate (push) Successful in 4m52s
deploy / archied-image (push) Successful in 3m2s
deploy / agent-image (push) Successful in 12s
deploy / dist-zip (push) Skipped
Quality / check (push) Successful in 44m46s
fix(webui): link tasks to their repository connection's forge
2026-11-08 06:42:38 +11:00

64 lines
2.0 KiB
Go

package webui
import (
"context"
"testing"
"google.golang.org/grpc"
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
)
// linkControl serves one repository policy on a Gitea connection.
type linkControl struct {
controlpb.ControlPlaneServiceClient
}
func (linkControl) Query(_ context.Context, r *controlpb.QueryRequest, _ ...grpc.CallOption) (*controlpb.QueryResponse, error) {
value := map[string]string{
"repository-policies": `[{"owner":"sam","name":"archie","connection":"home"}]`,
"forge-connections": `[{"id":"home","type":"gitea","host":"git.example.test"}]`,
}[r.Kind]
return &controlpb.QueryResponse{Resource: &controlpb.Resource{ValueJson: []byte(value)}}, nil
}
// A task links to the forge its repository's connection is on, not the
// instance's default forge, which is GitHub unless configured otherwise.
func TestTaskLinksFollowTheRepositoryConnection(t *testing.T) {
api := &tasksAPI{
controlPlane: linkControl{},
configSource: func() ConfigViewSource {
return func(context.Context) (ConfigView, bool, error) {
return ConfigView{Identity: IdentityView{ForgeHost: "https://github.com", ForgeType: "github"}}, true, nil
}
},
}
tests := []struct {
name string
task task.Task
wantIssue string
wantPR string
}{
{
"repository on a connection",
task.Task{Owner: "Sam", Repo: "archie", IssueNumber: 5, PRNumber: 6},
"https://git.example.test/Sam/archie/issues/5", "https://git.example.test/Sam/archie/pulls/6",
},
{
"repository without a policy",
task.Task{Owner: "acme", Repo: "app", IssueNumber: 1},
"https://github.com/acme/app/issues/1", "",
},
}
forge := api.resolveForge(context.Background())
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, issue, pr := taskURLs(tt.task, forge(tt.task))
if issue != tt.wantIssue || pr != tt.wantPR {
t.Fatalf("issue %q pr %q, want %q and %q", issue, pr, tt.wantIssue, tt.wantPR)
}
})
}
}