@@ -5,6 +5,9 @@ import codecheck.github.models.SortDirection
5
5
import codecheck .github .models .SearchInput
6
6
import codecheck .github .models .SearchSort
7
7
import codecheck .github .models .SearchRepositoryResult
8
+ import codecheck .github .models .SearchCodeResult
9
+ import codecheck .github .models .searchCodeItems
10
+ import codecheck .github .exceptions .GitHubAPIException
8
11
9
12
class SearchOpSpec extends FunSpec
10
13
with Constants
@@ -22,7 +25,8 @@ class SearchOpSpec extends FunSpec
22
25
assert(res.items(0 ).full_name.length >= 1 )
23
26
assert(res.items(0 ).description.isDefined)
24
27
assert(res.items(0 ).open_issues_count >= 0 )
25
- println(" RESULT" + res)
28
+ assert(res.items(0 ).language == " Assembly" )
29
+ assert(res.items(0 ).stargazers_count > res.items(1 ).stargazers_count)
26
30
}
27
31
}
28
32
it(" with valid changed query(q) SearchInput should succeed" ) {
@@ -36,7 +40,62 @@ class SearchOpSpec extends FunSpec
36
40
assert(res.items(0 ).full_name.length >= 1 )
37
41
assert(res.items(0 ).description.isDefined)
38
42
assert(res.items(0 ).open_issues_count >= 0 )
39
- println(" RESULT" + res)
43
+ }
44
+ }
45
+ }
46
+ describe(" searchCode" ) {
47
+ it(" with valid SearchInput q,no SortOrder should succeed" ) {
48
+ var q = " addClass in:file language:js repo:jquery/jquery"
49
+ val q1 = q.trim.replaceAll(" " ," +" );
50
+ val input = SearchInput (q1,sort= None ,order= SortDirection .desc)
51
+ Await .result(api.searchCode(input), TIMEOUT ).map { res =>
52
+ assert(res.total_count >= 1 )
53
+ assert(res.items(0 ).Repo .id >= 1 )
54
+ assert(res.items(0 ).Repo .full_name == " jquery/jquery" )
55
+ }
56
+ }
57
+ // Following test results in error:
58
+ // "message" : "Validation Failed",
59
+ // "errors" : [ {
60
+ // "message" : "Must include at least one user, organization, or repository"
61
+ it(" with valid SearchInput it should succeed" ) {
62
+ var q = " function size:10000 language:python"
63
+ val q1 = q.trim.replaceAll(" " ," +" );
64
+ val input = SearchInput (q1,sort= Some (SearchSort .indexed),order= SortDirection .desc)
65
+ try {
66
+ val res = Await .result(api.searchCode(input), TIMEOUT )
67
+ fail
68
+ } catch {
69
+ case e : GitHubAPIException =>
70
+ assert(e.error.errors.length == 1 )
71
+ assert(e.error.message == " Validation Failed" )
72
+ }
73
+ }
74
+ }
75
+ describe(" searchIssues" ) {
76
+ it(" with valid SearchInput should succeed" ) {
77
+ var q = " windows label:bug language:python state:open"
78
+ val q1 = q.trim.replaceAll(" " ," +" );
79
+ val input = SearchInput (q1,sort= Some (SearchSort .created),order= SortDirection .asc)
80
+ Await .result(api.searchIssues(input), TIMEOUT ).map { res =>
81
+ assert(res.total_count >= 1 )
82
+ assert(res.items(0 ).labels(0 ).name == " bug" )
83
+ assert(res.items(0 ).state == " open" )
84
+ assert(((res.items(0 ).created_at).compareTo(res.items(1 ).created_at)) > 0 )
85
+ }
86
+ }
87
+ }
88
+ describe(" searchUser" ) {
89
+ it(" with valid SearchInput should succeed" ) {
90
+ var q = " tom repos:>42 followers:>1000"
91
+ q = q.trim.replaceAll(" " ," +" )
92
+ val q1 = q.replaceAll(" >" ," %3E" )
93
+ println(" QUERY: searchUser" + q1)
94
+ val input = SearchInput (q1,sort= None ,order= SortDirection .desc)
95
+ Await .result(api.searchUser(input), TIMEOUT ).map { res =>
96
+ assert(res.total_count >= 1 )
97
+ assert(res.items(0 ).login.length >= 1 )
98
+ assert(res.items(0 ).id >= 1 )
40
99
}
41
100
}
42
101
}
0 commit comments