Skip to content

Commit 359d414

Browse files
committed
Add test for SimpleRepository parsing
1 parent 01e9175 commit 359d414

File tree

1 file changed

+84
-9
lines changed

1 file changed

+84
-9
lines changed

src/test/scala/RemoteRepositorySpecs.scala

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.scalatest._
22
import org.scalatest.Matchers
33
import play.api.libs.json.Json
4-
import com.codacy.client.bitbucket.PullRequest
4+
import com.codacy.client.bitbucket.{PullRequest, SimpleRepository}
55
import com.codacy.client.bitbucket.PullRequest._
66

77
class RemoteRepositorySpecs extends FlatSpec with Matchers {
@@ -132,9 +132,10 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
132132
val json = Json.parse(input)
133133
val value = json.validate[PullRequest]
134134

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+
)
138139
}
139140

140141
it should "successfully parse JSON with null commit" in {
@@ -261,9 +262,10 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
261262
val json = Json.parse(input)
262263
val value = json.validate[PullRequest]
263264

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+
)
267269
}
268270

269271
it should "successfully parse a JSON with null author while getting info for PRs" in {
@@ -382,9 +384,82 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
382384
val json = Json.parse(input)
383385
val value = json.validate[PullRequest]
384386

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 {
386394

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]]
388459

460+
value.fold(e =>
461+
fail(s"$e"),
462+
repo => repo.length shouldBe 2
463+
)
389464
}
390465
}

0 commit comments

Comments
 (0)