Skip to content

Commit 25a6712

Browse files
committed
Add tests for Api v2
1 parent c15a34b commit 25a6712

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.codacy.client.bitbucket.v2
2+
3+
import org.scalatest.{Matchers, _}
4+
import play.api.libs.json.Json
5+
6+
class IssueSpecs extends FlatSpec with Matchers {
7+
8+
"IssueSpecs" should "successfully parse Issue" in {
9+
val input =
10+
"""
11+
|{
12+
| "priority": "major",
13+
| "kind": "bug",
14+
| "repository": {
15+
| "links": {
16+
| "self": {
17+
| "href": "https://bitbucket.org/!api/2.0/repositories/mrfyda/scalatests"
18+
| },
19+
| "html": {
20+
| "href": "https://bitbucket.org/mrfyda/scalatests"
21+
| },
22+
| "avatar": {
23+
| "href": "https://bytebucket.org/ravatar/%7B75411621-5a51-4bd4-a982-1d86cedd309e%7D?ts=default"
24+
| }
25+
| },
26+
| "type": "repository",
27+
| "name": "ScalaTests",
28+
| "full_name": "mrfyda/scalatests",
29+
| "uuid": "{75411621-5a51-4bd4-a982-1d86cedd309e}"
30+
| },
31+
| "links": {
32+
| "attachments": {
33+
| "href": "https://bitbucket.org/!api/2.0/repositories/mrfyda/scalatests/issues/1/attachments"
34+
| },
35+
| "self": {
36+
| "href": "https://bitbucket.org/!api/2.0/repositories/mrfyda/scalatests/issues/1"
37+
| },
38+
| "watch": {
39+
| "href": "https://bitbucket.org/!api/2.0/repositories/mrfyda/scalatests/issues/1/watch"
40+
| },
41+
| "comments": {
42+
| "href": "https://bitbucket.org/!api/2.0/repositories/mrfyda/scalatests/issues/1/comments"
43+
| },
44+
| "html": {
45+
| "href": "https://bitbucket.org/mrfyda/scalatests/issues/1/2e95d690c2c58a72e1a0bb4cd76808a4c0c60db4"
46+
| },
47+
| "vote": {
48+
| "href": "https://bitbucket.org/!api/2.0/repositories/mrfyda/scalatests/issues/1/vote"
49+
| }
50+
| },
51+
| "reporter": {
52+
| "username": "mrfyda",
53+
| "display_name": "Rafael Cortês",
54+
| "account_id": "557058:cb3153a1-1a69-4374-a536-fefac8f1cc64",
55+
| "links": {
56+
| "self": {
57+
| "href": "https://bitbucket.org/!api/2.0/users/mrfyda"
58+
| },
59+
| "html": {
60+
| "href": "https://bitbucket.org/mrfyda/"
61+
| },
62+
| "avatar": {
63+
| "href": "https://bitbucket.org/account/mrfyda/avatar/"
64+
| }
65+
| },
66+
| "type": "user",
67+
| "uuid": "{1e960327-38ba-4100-919e-5a677e668cad}"
68+
| },
69+
| "title": "2e95d690c2c58a72e1a0bb4cd76808a4c0c60db4",
70+
| "component": null,
71+
| "votes": 0,
72+
| "watches": 1,
73+
| "content": {
74+
| "raw": "hello world",
75+
| "markup": "markdown",
76+
| "html": "<p>hello world</p>",
77+
| "type": "rendered"
78+
| },
79+
| "assignee": null,
80+
| "state": "new",
81+
| "version": null,
82+
| "edited_on": null,
83+
| "created_on": "2018-09-02T09:08:01.435083+00:00",
84+
| "milestone": null,
85+
| "updated_on": "2018-09-02T09:08:01.435083+00:00",
86+
| "type": "issue",
87+
| "id": 1
88+
|}
89+
""".stripMargin
90+
val json = Json.parse(input)
91+
val value = json.validate[Issue]
92+
93+
value.fold(e =>
94+
fail(s"$e"),
95+
r => r.id shouldBe 1
96+
)
97+
}
98+
99+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.codacy.client.bitbucket.v2
2+
import org.scalatest.{Matchers, _}
3+
import play.api.libs.json.Json
4+
5+
class UserSpecs extends FlatSpec with Matchers {
6+
7+
"UserSpecs" should "successfully parse a JSON into an array of Email" in {
8+
val input = """
9+
|[
10+
| {
11+
| "is_primary": true,
12+
| "is_confirmed": true,
13+
| "type": "email",
14+
| "email": "[email protected]",
15+
| "links": {
16+
| "self": {
17+
| "href": "https://api.bitbucket.org/2.0/user/emails/[email protected]"
18+
| }
19+
| }
20+
| },
21+
| {
22+
| "is_primary": false,
23+
| "is_confirmed": true,
24+
| "type": "email",
25+
| "email": "[email protected]",
26+
| "links": {
27+
| "self": {
28+
| "href": "https://api.bitbucket.org/2.0/user/emails/[email protected]"
29+
| }
30+
| }
31+
| },
32+
| {
33+
| "is_primary": false,
34+
| "is_confirmed": true,
35+
| "type": "email",
36+
| "email": "[email protected]",
37+
| "links": {
38+
| "self": {
39+
| "href": "https://api.bitbucket.org/2.0/user/emails/[email protected]"
40+
| }
41+
| }
42+
| }
43+
|]
44+
""".stripMargin
45+
val json = Json.parse(input)
46+
val value = json.validate[Seq[Email]]
47+
48+
value.fold(e =>
49+
fail(s"$e"),
50+
emails => emails.length shouldBe 3
51+
)
52+
}
53+
}

0 commit comments

Comments
 (0)