package project import ( "context" "reflect" "testing" "edge-infra.dev/pkg/lib/logging" "github.com/google/go-github/v47/github" "edge-infra.dev/pkg/f8n/devinfra/jack/plugin" ) var c = &plugin.MockGithubClient{ GithubIssues: &plugin.MockIssueService{}, GithubProjects: &plugin.MockProjectsService{}, GithubOrganizations: &plugin.MockOrganizationsService{}, } var cv4 = &plugin.MockGithubV4Client{} var projectIDs = &plugin.ProjectPlugin{ IDs: []int64{1}, } var orp = &plugin.OrgRepoPlugins{ Project: *projectIDs, } var hp = &plugin.HandlerParams{ Ctx: context.Background(), Client: c, ClientV4: cv4, Org: "some-org", Repo: "some-repo", Log: *logging.NewLogger(), Params: *orp, } const nodeID = "nodeID" func TestAddIssue(t *testing.T) { // Test adding to normal project c.GithubProjects = &plugin.MockProjectsService{ ID: 1, Number: 1, OwnerURL: hp.Org, NodeID: nodeID, Name: "test", Cards: 0, Columns: 3, } c.GithubOrganizations = &plugin.MockOrganizationsService{ Login: hp.Org, Name: hp.Org, URL: hp.Org, Projects: []int{1}, } ie := &github.IssuesEvent{ Action: github.String("opened"), Repo: &github.Repository{ Owner: &github.User{Login: github.String(hp.Org)}, Organization: &github.Organization{ Login: github.String(hp.Org), Name: github.String(hp.Org), URL: github.String(hp.Org), }, }, Issue: &github.Issue{ NodeID: github.String(nodeID), ID: github.Int64(1234), }, } handleIssue(*hp, *ie) ct := &plugin.MockGithubClient{ GithubProjects: &plugin.MockProjectsService{ ID: 1, Number: 1, OwnerURL: hp.Org, NodeID: nodeID, Name: "test", Cards: 1, Columns: 3, }, } if !reflect.DeepEqual(ct.GithubProjects, c.GithubProjects) { t.Error("Failed: TestAddIssue -> Test adding to normal project.") } } func TestV4(t *testing.T) { // Test adding to V4 Project projectIDs.IDs = []int64{150} orp = &plugin.OrgRepoPlugins{ Project: *projectIDs, } hp.Params = *orp c.GithubProjects = &plugin.MockProjectsService{ ID: 150, Number: 150, OwnerURL: hp.Org, NodeID: nodeID, Name: "test", Cards: 0, } c.GithubOrganizations = &plugin.MockOrganizationsService{ Login: hp.Org, Name: hp.Org, URL: hp.Org, Projects: []int{2}, } ie := &github.IssuesEvent{ Action: github.String("opened"), Repo: &github.Repository{ Owner: &github.User{Login: github.String(hp.Org)}, Organization: &github.Organization{ Login: github.String(hp.Org), Name: github.String(hp.Org), URL: github.String(hp.Org), }, }, Issue: &github.Issue{ NodeID: github.String("otherID"), ID: github.Int64(2345), }, } handleIssue(*hp, *ie) ct := &plugin.MockGithubV4Client{ ProjectNodeID: "pnid", ProjectNextItemID: "next", } if !reflect.DeepEqual(ct.ProjectNextItemID, cv4.ProjectNextItemID) { t.Error("Failed: TestV4 -> Test adding to V4 Project.") } }