|
| 1 | +import org.scalatest.path.FunSpec |
| 2 | +import scala.concurrent.Await |
| 3 | +import scala.concurrent.ExecutionContext.Implicits.global |
| 4 | +import codecheck.github.models.SortDirection |
| 5 | +import codecheck.github.models.SearchRepositoryInput |
| 6 | +import codecheck.github.models.SearchCodeInput |
| 7 | +import codecheck.github.models.SearchIssueInput |
| 8 | +import codecheck.github.models.SearchUserInput |
| 9 | +import codecheck.github.models.SearchRepositorySort |
| 10 | +import codecheck.github.models.SearchCodeSort |
| 11 | +import codecheck.github.models.SearchIssueSort |
| 12 | +import codecheck.github.models.SearchUserSort |
| 13 | +import codecheck.github.models.SearchRepositoryResult |
| 14 | +import codecheck.github.models.SearchCodeResult |
| 15 | +import codecheck.github.exceptions.GitHubAPIException |
| 16 | + |
| 17 | +class SearchOpSpec extends FunSpec |
| 18 | + with Constants |
| 19 | +{ |
| 20 | + |
| 21 | + describe("searchRepositories") { |
| 22 | + it("with valid SearchInput should succeed") { |
| 23 | + val q = "tetris language:assembly".trim.replaceAll(" ","+") |
| 24 | + val input = SearchRepositoryInput(q,sort=Some(SearchRepositorySort.stars),order=SortDirection.desc) |
| 25 | + val res = Await.result(api.searchRepositories(input), TIMEOUT) |
| 26 | + assert(res.total_count >= 1) |
| 27 | + assert(res.items(0).id >= 1 ) |
| 28 | + assert(res.items(0).name.length >= 1) |
| 29 | + assert(res.items(0).full_name.length >= 1) |
| 30 | + assert(res.items(0).description.isDefined) |
| 31 | + assert(res.items(0).open_issues_count >= 0) |
| 32 | + assert(res.items(0).language == "Assembly") |
| 33 | + assert(res.items(0).stargazers_count > res.items(1).stargazers_count) |
| 34 | + } |
| 35 | + it("with valid changed query(q) SearchInput should succeed") { |
| 36 | + val q = "jquery in:name,description".trim.replaceAll(" ","+") |
| 37 | + val input = SearchRepositoryInput(q,sort=Some(SearchRepositorySort.stars),order=SortDirection.desc) |
| 38 | + val res = Await.result(api.searchRepositories(input), TIMEOUT) |
| 39 | + assert(res.total_count >= 1) |
| 40 | + assert(res.items(0).id >= 1 ) |
| 41 | + assert(res.items(0).name.length >= 1) |
| 42 | + assert(res.items(0).full_name.length >= 1) |
| 43 | + assert(res.items(0).description.isDefined) |
| 44 | + assert(res.items(0).open_issues_count >= 0) |
| 45 | + } |
| 46 | + } |
| 47 | + describe("searchCode") { |
| 48 | + it("with valid SearchInput q,no SortOrder should succeed") { |
| 49 | + val q = "addClass in:file language:js repo:jquery/jquery".trim.replaceAll(" ","+") |
| 50 | + val input = SearchCodeInput(q,sort=None,order=SortDirection.desc) |
| 51 | + val res = Await.result(api.searchCode(input), TIMEOUT) |
| 52 | + assert(res.total_count >= 1) |
| 53 | + assert(res.items(0).repository.id >= 1 ) |
| 54 | + assert(res.items(0).sha.length >= 40) |
| 55 | + assert(res.items(0).score >= 0d) |
| 56 | + assert(res.items(0).repository.full_name == "jquery/jquery") |
| 57 | + } |
| 58 | + it("with valid SearchInput it should succeed") { |
| 59 | + val q = "function size:10000 language:python".trim.replaceAll(" ","+") |
| 60 | + val input = SearchCodeInput(q,sort=Some(SearchCodeSort.indexed),order=SortDirection.asc) |
| 61 | + val res = Await.result(api.searchCode(input), TIMEOUT) |
| 62 | + assert(res.total_count >= 1) |
| 63 | + assert(res.items(0).repository.id >= 1 ) |
| 64 | + assert(res.items(0).path.endsWith(".py")) |
| 65 | + assert(res.items(0).sha.length >= 40) |
| 66 | + assert(res.items(0).score >= 0d) |
| 67 | + assert(res.items(0).repository.`private` == false) |
| 68 | + } |
| 69 | + } |
| 70 | + describe("searchIssues") { |
| 71 | + it("with valid SearchInput should succeed") { |
| 72 | + val q = "windows label:bug language:python state:open".trim.replaceAll(" ","+") |
| 73 | + val input = SearchIssueInput(q,sort=Some(SearchIssueSort.created),order=SortDirection.desc) |
| 74 | + val res = Await.result(api.searchIssues(input), TIMEOUT) |
| 75 | + assert(res.total_count >= 1) |
| 76 | + assert(res.items(0).labels(0).name == "bug" ) |
| 77 | + assert(res.items(0).state == "open") |
| 78 | + assert(((res.items(0).created_at).compareTo(res.items(1).created_at)) > 0) |
| 79 | + } |
| 80 | + } |
| 81 | + describe("searchUser") { |
| 82 | + it("with valid SearchInput should succeed") { |
| 83 | + val q = "tom repos:>42 followers:>1000" |
| 84 | + .trim.replaceAll(" ","+") |
| 85 | + .replaceAll(">","%3E") |
| 86 | + val input = SearchUserInput(q,sort=None,order=SortDirection.desc) |
| 87 | + val res = Await.result(api.searchUser(input), TIMEOUT) |
| 88 | + assert(res.total_count >= 0) |
| 89 | + assert(res.items(0).login.length >= 0) |
| 90 | + assert(res.items(0).id >= 0) |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments