|
| 1 | +import 'dart:convert'; |
| 2 | + |
| 3 | +import 'package:github/src/common/model/checks.dart'; |
| 4 | +import 'package:test/test.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + group('Check run', () { |
| 8 | + test('CheckRun fromJson', () { |
| 9 | + /// The checkRun Json is the official Github values |
| 10 | + /// |
| 11 | + /// Github api url: https://docs.github.com/en/rest/reference/checks#get-a-check-run |
| 12 | + const checkRunJson = '''{ |
| 13 | + "id": 4, |
| 14 | + "head_sha": "ce587453ced02b1526dfb4cb910479d431683101", |
| 15 | + "node_id": "MDg6Q2hlY2tSdW40", |
| 16 | + "external_id": "", |
| 17 | + "url": "https://api.github.com/repos/github/hello-world/check-runs/4", |
| 18 | + "html_url": "https://github.com/github/hello-world/runs/4", |
| 19 | + "details_url": "https://example.com", |
| 20 | + "status": "completed", |
| 21 | + "conclusion": "neutral", |
| 22 | + "started_at": "2018-05-04T01:14:52Z", |
| 23 | + "completed_at": "2018-05-04T01:14:52Z", |
| 24 | + "output": { |
| 25 | + "title": "Mighty Readme report", |
| 26 | + "summary": "There are 0 failures, 2 warnings, and 1 notice.", |
| 27 | + "text": "You may have some misspelled words on lines 2 and 4. You also may want to add a section in your README about how to install your app.", |
| 28 | + "annotations_count": 2, |
| 29 | + "annotations_url": "https://api.github.com/repos/github/hello-world/check-runs/4/annotations" |
| 30 | + }, |
| 31 | + "name": "mighty_readme", |
| 32 | + "check_suite": { |
| 33 | + "id": 5 |
| 34 | + }, |
| 35 | + "app": { |
| 36 | + "id": 1, |
| 37 | + "slug": "octoapp", |
| 38 | + "node_id": "MDExOkludGVncmF0aW9uMQ==", |
| 39 | + "owner": { |
| 40 | + "login": "github", |
| 41 | + "id": 1, |
| 42 | + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=", |
| 43 | + "url": "https://api.github.com/orgs/github", |
| 44 | + "repos_url": "https://api.github.com/orgs/github/repos", |
| 45 | + "events_url": "https://api.github.com/orgs/github/events", |
| 46 | + "avatar_url": "https://github.com/images/error/octocat_happy.gif", |
| 47 | + "gravatar_id": "", |
| 48 | + "html_url": "https://github.com/octocat", |
| 49 | + "followers_url": "https://api.github.com/users/octocat/followers", |
| 50 | + "following_url": "https://api.github.com/users/octocat/following{/other_user}", |
| 51 | + "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", |
| 52 | + "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", |
| 53 | + "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", |
| 54 | + "organizations_url": "https://api.github.com/users/octocat/orgs", |
| 55 | + "received_events_url": "https://api.github.com/users/octocat/received_events", |
| 56 | + "type": "User", |
| 57 | + "site_admin": true |
| 58 | + }, |
| 59 | + "name": "Octocat App", |
| 60 | + "description": "", |
| 61 | + "external_url": "https://example.com", |
| 62 | + "html_url": "https://github.com/apps/octoapp", |
| 63 | + "created_at": "2017-07-08T16:18:44-04:00", |
| 64 | + "updated_at": "2017-07-08T16:18:44-04:00", |
| 65 | + "permissions": { |
| 66 | + "metadata": "read", |
| 67 | + "contents": "read", |
| 68 | + "issues": "write", |
| 69 | + "single_file": "write" |
| 70 | + }, |
| 71 | + "events": [ |
| 72 | + "push", |
| 73 | + "pull_request" |
| 74 | + ] |
| 75 | + }, |
| 76 | + "pull_requests": [ |
| 77 | + { |
| 78 | + "url": "https://api.github.com/repos/github/hello-world/pulls/1", |
| 79 | + "id": 1934, |
| 80 | + "number": 3956, |
| 81 | + "head": { |
| 82 | + "ref": "say-hello", |
| 83 | + "sha": "3dca65fa3e8d4b3da3f3d056c59aee1c50f41390", |
| 84 | + "repo": { |
| 85 | + "id": 526, |
| 86 | + "url": "https://api.github.com/repos/github/hello-world", |
| 87 | + "name": "hello-world" |
| 88 | + } |
| 89 | + }, |
| 90 | + "base": { |
| 91 | + "ref": "master", |
| 92 | + "sha": "e7fdf7640066d71ad16a86fbcbb9c6a10a18af4f", |
| 93 | + "repo": { |
| 94 | + "id": 526, |
| 95 | + "url": "https://api.github.com/repos/github/hello-world", |
| 96 | + "name": "hello-world" |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + ] |
| 101 | + }'''; |
| 102 | + final checkRun = CheckRun.fromJson(jsonDecode(checkRunJson)); |
| 103 | + |
| 104 | + expect(checkRun.id, 4); |
| 105 | + expect(checkRun.name, 'mighty_readme'); |
| 106 | + expect(checkRun.conclusion, CheckRunConclusion.neutral); |
| 107 | + }); |
| 108 | + }); |
| 109 | +} |
0 commit comments