@@ -8,6 +8,97 @@ import (
88 "testing"
99)
1010
11+ func Test_GetEntriesWithoutLinkToOpenProject (t * testing.T ) {
12+ tests := []struct {
13+ name string
14+ task Task
15+ }{
16+ {
17+ name : "empty task" ,
18+ task : Task {},
19+ },
20+ {
21+ name : "no external link" ,
22+ task : Task {
23+ Id : 123 ,
24+ Name : "some WP" ,
25+ },
26+ },
27+ {
28+ name : "link is not to openproject" ,
29+ task : Task {
30+ Id : 345 ,
31+ Name : "some WP" ,
32+ ExternalLink : ExternalLink {
33+ Link : "https://some_host/work_packages/123" ,
34+ IssueId : "#123" ,
35+ },
36+ },
37+ },
38+ {
39+ name : "IssueId is empty" ,
40+ task : Task {
41+ Id : 345 ,
42+ Name : "some WP" ,
43+ ExternalLink : ExternalLink {
44+ Link : "https://community.openproject.org/work_packages/123" ,
45+ IssueId : "" ,
46+ },
47+ },
48+ },
49+ {
50+ name : "IssueId has wrong format" ,
51+ task : Task {
52+ Id : 345 ,
53+ Name : "some WP" ,
54+ ExternalLink : ExternalLink {
55+ Link : "https://community.openproject.org/work_packages/123" ,
56+ IssueId : "!123" ,
57+ },
58+ },
59+ },
60+ }
61+ for _ , tt := range tests {
62+ t .Run (tt .name , func (t * testing.T ) {
63+ // adds a correct entry at the beginning and the end and makes sure the invalid
64+ // entry is still in the result
65+ config := & config.Config {
66+ ClientIdInTmetric : 123 ,
67+ TmetricExternalTaskLink : "https://community.openproject.org/" ,
68+ }
69+ validTimeEntry := TimeEntry {
70+ Project : Project {
71+ Client : Client {Id : 123 },
72+ Name : "Project1" ,
73+ },
74+ Note : "correct entry" ,
75+ Task : Task {
76+ Id : 345 ,
77+ Name : "some WP" ,
78+ ExternalLink : ExternalLink {
79+ Link : "https://community.openproject.org/work_packages/123" ,
80+ IssueId : "#123" ,
81+ },
82+ },
83+ }
84+ invalidTimeEntry := TimeEntry {
85+ Project : Project {
86+ Client : Client {Id : 123 },
87+ Name : "Project1" ,
88+ },
89+ Note : "invalid entry" ,
90+ Task : tt .task ,
91+ }
92+ timeEntriesToCheck := append ([]TimeEntry {invalidTimeEntry }, validTimeEntry )
93+ timeEntriesToCheck = append ([]TimeEntry {validTimeEntry }, timeEntriesToCheck ... )
94+ result := GetEntriesWithoutLinkToOpenProject (config , timeEntriesToCheck )
95+ if ! reflect .DeepEqual (result , []TimeEntry {invalidTimeEntry }) {
96+ t .Errorf ("got %v, want %v" , result , []TimeEntry {invalidTimeEntry })
97+ }
98+ })
99+ }
100+ }
101+
11102func Test_GetEntriesWithoutWorkType (t * testing.T ) {
12103 type args struct {
13104 timeEntries []TimeEntry
0 commit comments