1 package project
2
3 import (
4 "context"
5 "reflect"
6 "testing"
7
8 "edge-infra.dev/pkg/lib/logging"
9
10 "github.com/google/go-github/v47/github"
11
12 "edge-infra.dev/pkg/f8n/devinfra/jack/plugin"
13 )
14
15 var c = &plugin.MockGithubClient{
16 GithubIssues: &plugin.MockIssueService{},
17 GithubProjects: &plugin.MockProjectsService{},
18 GithubOrganizations: &plugin.MockOrganizationsService{},
19 }
20 var cv4 = &plugin.MockGithubV4Client{}
21 var projectIDs = &plugin.ProjectPlugin{
22 IDs: []int64{1},
23 }
24 var orp = &plugin.OrgRepoPlugins{
25 Project: *projectIDs,
26 }
27 var hp = &plugin.HandlerParams{
28 Ctx: context.Background(),
29 Client: c,
30 ClientV4: cv4,
31 Org: "some-org",
32 Repo: "some-repo",
33 Log: *logging.NewLogger(),
34 Params: *orp,
35 }
36
37 const nodeID = "nodeID"
38
39 func TestAddIssue(t *testing.T) {
40
41 c.GithubProjects = &plugin.MockProjectsService{
42 ID: 1,
43 Number: 1,
44 OwnerURL: hp.Org,
45 NodeID: nodeID,
46 Name: "test",
47 Cards: 0,
48 Columns: 3,
49 }
50 c.GithubOrganizations = &plugin.MockOrganizationsService{
51 Login: hp.Org,
52 Name: hp.Org,
53 URL: hp.Org,
54 Projects: []int{1},
55 }
56 ie := &github.IssuesEvent{
57 Action: github.String("opened"),
58 Repo: &github.Repository{
59 Owner: &github.User{Login: github.String(hp.Org)},
60 Organization: &github.Organization{
61 Login: github.String(hp.Org),
62 Name: github.String(hp.Org),
63 URL: github.String(hp.Org),
64 },
65 },
66 Issue: &github.Issue{
67 NodeID: github.String(nodeID),
68 ID: github.Int64(1234),
69 },
70 }
71
72 handleIssue(*hp, *ie)
73
74 ct := &plugin.MockGithubClient{
75 GithubProjects: &plugin.MockProjectsService{
76 ID: 1,
77 Number: 1,
78 OwnerURL: hp.Org,
79 NodeID: nodeID,
80 Name: "test",
81 Cards: 1,
82 Columns: 3,
83 },
84 }
85 if !reflect.DeepEqual(ct.GithubProjects, c.GithubProjects) {
86 t.Error("Failed: TestAddIssue -> Test adding to normal project.")
87 }
88 }
89
90 func TestV4(t *testing.T) {
91
92 projectIDs.IDs = []int64{150}
93 orp = &plugin.OrgRepoPlugins{
94 Project: *projectIDs,
95 }
96 hp.Params = *orp
97
98 c.GithubProjects = &plugin.MockProjectsService{
99 ID: 150,
100 Number: 150,
101 OwnerURL: hp.Org,
102 NodeID: nodeID,
103 Name: "test",
104 Cards: 0,
105 }
106
107 c.GithubOrganizations = &plugin.MockOrganizationsService{
108 Login: hp.Org,
109 Name: hp.Org,
110 URL: hp.Org,
111 Projects: []int{2},
112 }
113
114 ie := &github.IssuesEvent{
115 Action: github.String("opened"),
116 Repo: &github.Repository{
117 Owner: &github.User{Login: github.String(hp.Org)},
118 Organization: &github.Organization{
119 Login: github.String(hp.Org),
120 Name: github.String(hp.Org),
121 URL: github.String(hp.Org),
122 },
123 },
124 Issue: &github.Issue{
125 NodeID: github.String("otherID"),
126 ID: github.Int64(2345),
127 },
128 }
129
130 handleIssue(*hp, *ie)
131
132 ct := &plugin.MockGithubV4Client{
133 ProjectNodeID: "pnid",
134 ProjectNextItemID: "next",
135 }
136
137 if !reflect.DeepEqual(ct.ProjectNextItemID, cv4.ProjectNextItemID) {
138 t.Error("Failed: TestV4 -> Test adding to V4 Project.")
139 }
140 }
141
View as plain text