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