-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSearchOpSpec.scala
96 lines (94 loc) · 3.89 KB
/
SearchOpSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import org.scalatest.path.FunSpec
import scala.concurrent.Await
import scala.concurrent.ExecutionContext.Implicits.global
import codecheck.github.models.SortDirection
import codecheck.github.models.SearchInput
import codecheck.github.models.SearchSort
import codecheck.github.models.SearchRepositoryResult
import codecheck.github.models.SearchCodeResult
import codecheck.github.models.searchCodeItems
import codecheck.github.exceptions.GitHubAPIException
class SearchOpSpec extends FunSpec
with Constants
{
describe("searchRepositories") {
it("with valid SearchInput should succeed") {
var q = "tetris language:assembly"
val q1 = q.trim.replaceAll(" ","+");
val input = SearchInput(q1,sort=Some(SearchSort.stars),order=SortDirection.desc)
val res = Await.result(api.searchRepositories(input), TIMEOUT)
assert(res.total_count >= 1)
assert(res.items(0).id >= 1 )
assert(res.items(0).name.length >= 1)
assert(res.items(0).full_name.length >= 1)
assert(res.items(0).description.isDefined)
assert(res.items(0).open_issues_count >= 0)
assert(res.items(0).language == "Assembly")
assert(res.items(0).stargazers_count > res.items(1).stargazers_count)
}
it("with valid changed query(q) SearchInput should succeed") {
var q = "jquery in:name,description"
val q1 = q.trim.replaceAll(" ","+");
val input = SearchInput(q1,sort=Some(SearchSort.stars),order=SortDirection.desc)
val res = Await.result(api.searchRepositories(input), TIMEOUT)
assert(res.total_count >= 1)
assert(res.items(0).id >= 1 )
assert(res.items(0).name.length >= 1)
assert(res.items(0).full_name.length >= 1)
assert(res.items(0).description.isDefined)
assert(res.items(0).open_issues_count >= 0)
}
}
describe("searchCode") {
it("with valid SearchInput q,no SortOrder should succeed") {
var q = "addClass in:file language:js repo:jquery/jquery"
val q1 = q.trim.replaceAll(" ","+");
val input = SearchInput(q1,sort=None,order=SortDirection.desc)
val res = Await.result(api.searchCode(input), TIMEOUT)
assert(res.total_count >= 1)
assert(res.items(0).Repo.id >= 1 )
assert(res.items(0).Repo.full_name == "jquery/jquery")
}
//Following test results in error:
// "message" : "Validation Failed",
// "errors" : [ {
// "message" : "Must include at least one user, organization, or repository"
it("with valid SearchInput it should succeed") {
var q = "function size:10000 language:python"
val q1 = q.trim.replaceAll(" ","+");
val input = SearchInput(q1,sort=Some(SearchSort.indexed),order=SortDirection.desc)
try {
val res = Await.result(api.searchCode(input), TIMEOUT)
fail
} catch {
case e: GitHubAPIException =>
assert(e.error.errors.length == 1)
assert(e.error.message == "Validation Failed")
}
}
}
describe("searchIssues") {
it("with valid SearchInput should succeed") {
var q = "windows label:bug language:python state:open"
val q1 = q.trim.replaceAll(" ","+");
val input = SearchInput(q1,sort=Some(SearchSort.created),order=SortDirection.asc)
val res = Await.result(api.searchIssues(input), TIMEOUT)
assert(res.total_count >= 1)
assert(res.items(0).labels(0).name == "bug" )
assert(res.items(0).state == "open")
assert(((res.items(0).created_at).compareTo(res.items(1).created_at)) > 0)
}
}
describe("searchUser") {
it("with valid SearchInput should succeed") {
var q = "tom repos:>42 followers:>1000"
q = q.trim.replaceAll(" ","+")
val q1 = q.replaceAll(">","%3E")
val input = SearchInput(q1,sort=None,order=SortDirection.desc)
val res = Await.result(api.searchUser(input), TIMEOUT)
assert(res.total_count >= 0)
assert(res.items(0).login.length >= 0)
assert(res.items(0).id >= 0)
}
}
}