|
1 | 1 | import org.scalatest._
|
2 | 2 | import org.scalatest.Matchers
|
3 | 3 | import play.api.libs.json.Json
|
4 |
| -import com.codacy.client.bitbucket.PullRequest |
| 4 | +import com.codacy.client.bitbucket.{PullRequest, SimpleRepository} |
5 | 5 | import com.codacy.client.bitbucket.PullRequest._
|
6 | 6 |
|
7 | 7 | class RemoteRepositorySpecs extends FlatSpec with Matchers {
|
@@ -132,9 +132,10 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
|
132 | 132 | val json = Json.parse(input)
|
133 | 133 | val value = json.validate[PullRequest]
|
134 | 134 |
|
135 |
| - val parsed = value.fold(e => false, r => r.destCommit.isDefined) |
136 |
| - |
137 |
| - parsed shouldBe true |
| 135 | + value.fold(e => |
| 136 | + fail(s"$e"), |
| 137 | + r => r.destCommit.isDefined shouldBe true |
| 138 | + ) |
138 | 139 | }
|
139 | 140 |
|
140 | 141 | it should "successfully parse JSON with null commit" in {
|
@@ -261,9 +262,10 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
|
261 | 262 | val json = Json.parse(input)
|
262 | 263 | val value = json.validate[PullRequest]
|
263 | 264 |
|
264 |
| - val parsed = value.fold(e =>false, r => r.destCommit.isEmpty) |
265 |
| - |
266 |
| - parsed shouldBe true |
| 265 | + value.fold(e => |
| 266 | + fail(s"$e"), |
| 267 | + r => r.destCommit.isEmpty shouldBe true |
| 268 | + ) |
267 | 269 | }
|
268 | 270 |
|
269 | 271 | it should "successfully parse a JSON with null author while getting info for PRs" in {
|
@@ -382,9 +384,126 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
|
382 | 384 | val json = Json.parse(input)
|
383 | 385 | val value = json.validate[PullRequest]
|
384 | 386 |
|
385 |
| - val parsed = value.fold(e => false, r => r.destCommit.isDefined) |
| 387 | + value.fold(e => |
| 388 | + fail(s"$e"), |
| 389 | + r => r.destCommit.isDefined shouldBe true |
| 390 | + ) |
| 391 | + } |
| 392 | + |
| 393 | + it should "successfully parse a JSON into an array of SimpleRepository" in { |
386 | 394 |
|
387 |
| - parsed shouldBe true |
| 395 | + val input = |
| 396 | + """[ |
| 397 | + |{ |
| 398 | + | "scm": "git", |
| 399 | + | "has_wiki": false, |
| 400 | + | "last_updated": "2016-01-26T21:39:24.485", |
| 401 | + | "no_forks": false, |
| 402 | + | "created_on": "2015-09-04T20:33:22.640", |
| 403 | + | "owner": "carrots", |
| 404 | + | "logo": "https://bitbucket.org/carrots/potatos/avatar/32/?ts=1453840764", |
| 405 | + | "email_mailinglist": "", |
| 406 | + | "is_mq": false, |
| 407 | + | "size": 14544338, |
| 408 | + | "read_only": false, |
| 409 | + | "fork_of": null, |
| 410 | + | "mq_of": null, |
| 411 | + | "state": "available", |
| 412 | + | "utc_created_on": "2015-09-04 18:37:22+00:00", |
| 413 | + | "website": "", |
| 414 | + | "description": "", |
| 415 | + | "has_issues": false, |
| 416 | + | "is_fork": false, |
| 417 | + | "slug": "potatos", |
| 418 | + | "is_private": true, |
| 419 | + | "name": "Carrots and company", |
| 420 | + | "language": "", |
| 421 | + | "utc_last_updated": "2016-01-26 20:39:24+00:00", |
| 422 | + | "no_public_forks": true, |
| 423 | + | "creator": null, |
| 424 | + | "resource_uri": "/1.0/repositories/carrots/potatos" |
| 425 | + |}, |
| 426 | + |{ |
| 427 | + | "scm": "git", |
| 428 | + | "has_wiki": false, |
| 429 | + | "last_updated": "2017-02-03T20:29:18.224", |
| 430 | + | "no_forks": false, |
| 431 | + | "created_on": "2017-02-01T17:42:37.640", |
| 432 | + | "owner": "carrots", |
| 433 | + | "logo": "https://bitbucket.org/carrots/potatos/avatar/32/?ts=1486150158", |
| 434 | + | "email_mailinglist": "", |
| 435 | + | "is_mq": false, |
| 436 | + | "size": 13489122, |
| 437 | + | "read_only": false, |
| 438 | + | "fork_of": null, |
| 439 | + | "mq_of": null, |
| 440 | + | "state": "available", |
| 441 | + | "utc_created_on": "2017-02-01 16:41:37+00:00", |
| 442 | + | "website": "", |
| 443 | + | "description": "credentials.certainteed.com (Rackspace)", |
| 444 | + | "has_issues": false, |
| 445 | + | "is_fork": false, |
| 446 | + | "slug": "potatos", |
| 447 | + | "is_private": true, |
| 448 | + | "name": "Nice potatos", |
| 449 | + | "language": "php", |
| 450 | + | "utc_last_updated": "2017-02-03 19:29:18+00:00", |
| 451 | + | "no_public_forks": true, |
| 452 | + | "creator": null, |
| 453 | + | "resource_uri": "/1.0/repositories/carrots/potatos" |
| 454 | + |} |
| 455 | + |] |
| 456 | + """.stripMargin |
| 457 | + val json = Json.parse(input) |
| 458 | + val value = json.validate[Seq[SimpleRepository]] |
| 459 | + |
| 460 | + value.fold(e => |
| 461 | + fail(s"$e"), |
| 462 | + repo => repo.length shouldBe 2 |
| 463 | + ) |
| 464 | + } |
| 465 | + |
| 466 | + it should "successfully parse a JSON into an array of SimpleRepository that has no milliseconds on the created date" in { |
| 467 | + |
| 468 | + val input = |
| 469 | + """[ |
| 470 | + |{ |
| 471 | + | "scm": "git", |
| 472 | + | "has_wiki": false, |
| 473 | + | "last_updated": "2016-01-26T21:39:24.485", |
| 474 | + | "no_forks": false, |
| 475 | + | "created_on": "2015-09-04T20:33:22", |
| 476 | + | "owner": "carrots", |
| 477 | + | "logo": "https://bitbucket.org/carrots/potatos/avatar/32/?ts=1453840764", |
| 478 | + | "email_mailinglist": "", |
| 479 | + | "is_mq": false, |
| 480 | + | "size": 14544338, |
| 481 | + | "read_only": false, |
| 482 | + | "fork_of": null, |
| 483 | + | "mq_of": null, |
| 484 | + | "state": "available", |
| 485 | + | "utc_created_on": "2015-09-04 18:37:22+00:00", |
| 486 | + | "website": "", |
| 487 | + | "description": "", |
| 488 | + | "has_issues": false, |
| 489 | + | "is_fork": false, |
| 490 | + | "slug": "potatos", |
| 491 | + | "is_private": true, |
| 492 | + | "name": "Carrots and company", |
| 493 | + | "language": "", |
| 494 | + | "utc_last_updated": "2016-01-26 20:39:24+00:00", |
| 495 | + | "no_public_forks": true, |
| 496 | + | "creator": null, |
| 497 | + | "resource_uri": "/1.0/repositories/carrots/potatos" |
| 498 | + |} |
| 499 | + |] |
| 500 | + """.stripMargin |
| 501 | + val json = Json.parse(input) |
| 502 | + val value = json.validate[Seq[SimpleRepository]] |
388 | 503 |
|
| 504 | + value.fold(e => |
| 505 | + fail(s"$e"), |
| 506 | + repo => repo.length shouldBe 1 |
| 507 | + ) |
389 | 508 | }
|
390 | 509 | }
|
0 commit comments