|
| 1 | +package com.codacy.client.bitbucket.v2 |
| 2 | + |
| 3 | +import org.scalatest.{FlatSpec, Matchers} |
| 4 | +import play.api.libs.json.Json |
| 5 | + |
| 6 | +class PullRequestSpecs extends FlatSpec with Matchers { |
| 7 | + "PullRequestSpecs" should "successfully parse PullRequest" in { |
| 8 | + val input = |
| 9 | + """ |
| 10 | + |{ |
| 11 | + | "description":"README.md edited online with Bitbucket", |
| 12 | + | "links": |
| 13 | + | { |
| 14 | + | "decline": |
| 15 | + | { |
| 16 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/decline" |
| 17 | + | }, |
| 18 | + | "commits": |
| 19 | + | { |
| 20 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/commits" |
| 21 | + | }, |
| 22 | + | "self": |
| 23 | + | { |
| 24 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3" |
| 25 | + | }, |
| 26 | + | "comments": |
| 27 | + | { |
| 28 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/comments" |
| 29 | + | }, |
| 30 | + | "merge": |
| 31 | + | { |
| 32 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/merge" |
| 33 | + | }, |
| 34 | + | "html": |
| 35 | + | { |
| 36 | + | "href":"https:\/\/bitbucket.org\/jllopes\/test2\/pull-requests\/3" |
| 37 | + | }, |
| 38 | + | "activity": |
| 39 | + | { |
| 40 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/activity" |
| 41 | + | }, |
| 42 | + | "diff": |
| 43 | + | { |
| 44 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/diff" |
| 45 | + | }, |
| 46 | + | "approve": |
| 47 | + | { |
| 48 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/approve" |
| 49 | + | }, |
| 50 | + | "statuses": |
| 51 | + | { |
| 52 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/pullrequests\/3\/statuses" |
| 53 | + | } |
| 54 | + | }, |
| 55 | + | "title":"README.md edited online with Bitbucket", |
| 56 | + | "close_source_branch":true, |
| 57 | + | "merge_commit":null, |
| 58 | + | "destination": |
| 59 | + | { |
| 60 | + | "commit": |
| 61 | + | { |
| 62 | + | "type":"commit", |
| 63 | + | "hash":"a1dbc5a0d643", |
| 64 | + | "links": |
| 65 | + | { |
| 66 | + | "self": |
| 67 | + | { |
| 68 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/commit\/a1dbc5a0d643" |
| 69 | + | }, |
| 70 | + | "html": |
| 71 | + | { |
| 72 | + | "href":"https:\/\/bitbucket.org\/jllopes\/test2\/commits\/a1dbc5a0d643" |
| 73 | + | } |
| 74 | + | } |
| 75 | + | }, |
| 76 | + | "branch": |
| 77 | + | { |
| 78 | + | "name":"jllopes\/asdf2" |
| 79 | + | }, |
| 80 | + | "repository": |
| 81 | + | { |
| 82 | + | "full_name":"jllopes\/test2", |
| 83 | + | "type":"repository", |
| 84 | + | "name":"test2", |
| 85 | + | "links": |
| 86 | + | { |
| 87 | + | "self": |
| 88 | + | { |
| 89 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2" |
| 90 | + | }, |
| 91 | + | "html": |
| 92 | + | { |
| 93 | + | "href":"https:\/\/bitbucket.org\/jllopes\/test2" |
| 94 | + | }, |
| 95 | + | "avatar": |
| 96 | + | { |
| 97 | + | "href":"https:\/\/bytebucket.org\/ravatar\/%7B2eaf162b-90f7-4a63-b42f-a53381685ceb%7D?ts=default" |
| 98 | + | } |
| 99 | + | }, |
| 100 | + | "uuid":"{2eaf162b-90f7-4a63-b42f-a53381685ceb}" |
| 101 | + | } |
| 102 | + | }, |
| 103 | + | "comment_count":0, |
| 104 | + | "closed_by":null, |
| 105 | + | "source": |
| 106 | + | { |
| 107 | + | "commit": |
| 108 | + | { |
| 109 | + | "type":"commit", |
| 110 | + | "hash":"096bc35a6ba0", |
| 111 | + | "links": |
| 112 | + | { |
| 113 | + | "self": |
| 114 | + | { |
| 115 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2\/commit\/096bc35a6ba0" |
| 116 | + | }, |
| 117 | + | "html": |
| 118 | + | { |
| 119 | + | "href":"https:\/\/bitbucket.org\/jllopes\/test2\/commits\/096bc35a6ba0" |
| 120 | + | } |
| 121 | + | } |
| 122 | + | }, |
| 123 | + | "branch": |
| 124 | + | { |
| 125 | + | "name":"asdf5" |
| 126 | + | }, |
| 127 | + | "repository": |
| 128 | + | { |
| 129 | + | "full_name":"jllopes\/test2", |
| 130 | + | "type":"repository", |
| 131 | + | "name":"test2", |
| 132 | + | "links": |
| 133 | + | { |
| 134 | + | "self": |
| 135 | + | { |
| 136 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes\/test2" |
| 137 | + | }, |
| 138 | + | "html": |
| 139 | + | { |
| 140 | + | "href":"https:\/\/bitbucket.org\/jllopes\/test2" |
| 141 | + | }, |
| 142 | + | "avatar": |
| 143 | + | { |
| 144 | + | "href":"https:\/\/bytebucket.org\/ravatar\/%7B2eaf162b-90f7-4a63-b42f-a53381685ceb%7D?ts=default" |
| 145 | + | } |
| 146 | + | }, |
| 147 | + | "uuid":"{2eaf162b-90f7-4a63-b42f-a53381685ceb}" |
| 148 | + | } |
| 149 | + | }, |
| 150 | + | "created_on":"2019-01-15T15:14:16.752685+00:00", |
| 151 | + | "state":"OPEN", |
| 152 | + | "task_count":0, |
| 153 | + | "reason":"", |
| 154 | + | "updated_on":"2019-01-31T11:28:53.675721+00:00", |
| 155 | + | "author": |
| 156 | + | { |
| 157 | + | "username":"jllopes", |
| 158 | + | "website":"", |
| 159 | + | "display_name":"João Lopes", |
| 160 | + | "account_id":"123abc456def789ghi101jkl", |
| 161 | + | "links": |
| 162 | + | { |
| 163 | + | "hooks": |
| 164 | + | { |
| 165 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/users\/jllopes\/hooks" |
| 166 | + | }, |
| 167 | + | "self": |
| 168 | + | { |
| 169 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/users\/jllopes" |
| 170 | + | }, |
| 171 | + | "repositories": |
| 172 | + | { |
| 173 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/repositories\/jllopes" |
| 174 | + | }, |
| 175 | + | "html": |
| 176 | + | { |
| 177 | + | "href":"https:\/\/bitbucket.org\/jllopes\/" |
| 178 | + | }, |
| 179 | + | "followers": |
| 180 | + | { |
| 181 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/users\/jllopes\/followers" |
| 182 | + | }, |
| 183 | + | "avatar": |
| 184 | + | { |
| 185 | + | "href":"https:\/\/bitbucket.org\/account\/jllopes\/avatar\/" |
| 186 | + | }, |
| 187 | + | "following": |
| 188 | + | { |
| 189 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/users\/jllopes\/following" |
| 190 | + | }, |
| 191 | + | "snippets": |
| 192 | + | { |
| 193 | + | "href":"https:\/\/bitbucket.org\/!api\/2.0\/snippets\/jllopes" |
| 194 | + | } |
| 195 | + | }, |
| 196 | + | "type":"user", |
| 197 | + | "created_on":"2018-07-02T10:41:55.342788+00:00", |
| 198 | + | "is_staff":false, |
| 199 | + | "location":null, |
| 200 | + | "account_status":"active", |
| 201 | + | "nickname":"jllopes", |
| 202 | + | "uuid":"{c19f822b-0e29-433a-87a5-ec8ace58aa67}" |
| 203 | + | }, |
| 204 | + | "summary": |
| 205 | + | { |
| 206 | + | "raw":"README.md edited online with Bitbucket", |
| 207 | + | "markup":"markdown", |
| 208 | + | "html":"<p>README.md edited online with Bitbucket<\/p>", |
| 209 | + | "type":"rendered" |
| 210 | + | }, |
| 211 | + | "type":"pullrequest", |
| 212 | + | "id":3 |
| 213 | + |}""".stripMargin |
| 214 | + |
| 215 | + val json = Json.parse(input) |
| 216 | + val value = json.validate[PullRequest] |
| 217 | + |
| 218 | + value.fold(e => fail(s"$e"), pr => { |
| 219 | + pr.id shouldBe 3 |
| 220 | + pr.author.account_id shouldBe "123abc456def789ghi101jkl" |
| 221 | + }) |
| 222 | + } |
| 223 | + |
| 224 | +} |
0 commit comments