Skip to content

Commit

Permalink
fix: better error scenario
Browse files Browse the repository at this point in the history
The previous scenario did not pass a color which would in most Octokit clients before sending the request due to local validation
  • Loading branch information
gr2m committed Oct 15, 2018
1 parent bd73a45 commit e97830b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 76 deletions.
16 changes: 12 additions & 4 deletions scenarios/api.github.com/errors/normalized-fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,33 @@
"method": "post",
"path": "/repos/octokit-fixture-org/errors/labels",
"body": {
"name": false
"name": "foo",
"color": "invalid"
},
"status": 422,
"response": {
"message": "Invalid request.\n\nFor 'properties/name', false is not a string.",
"message": "Validation Failed",
"errors": [
{
"resource": "Label",
"code": "invalid",
"field": "color"
}
],
"documentation_url": "https://developer.github.com/v3/issues/labels/#create-a-label"
},
"reqheaders": {
"accept": "application/vnd.github.v3+json",
"content-type": "application/json; charset=utf-8",
"authorization": "token 0000000000000000000000000000000000000001",
"content-length": 14,
"content-length": 32,
"host": "api.github.com"
},
"headers": {
"access-control-allow-origin": "*",
"access-control-expose-headers": "ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"connection": "close",
"content-length": "163",
"content-length": "180",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
Expand Down
148 changes: 78 additions & 70 deletions scenarios/api.github.com/errors/raw-fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"method": "post",
"path": "/orgs/octokit-fixture-org/repos",
"body": {
"name": "tmp-scenario-errors-20181015153335346-ep4x8"
"name": "tmp-scenario-errors-20181015182600961-dnun8"
},
"status": 201,
"response": {
"id": 153138204,
"node_id": "MDEwOlJlcG9zaXRvcnkxNTMxMzgyMDQ=",
"name": "tmp-scenario-errors-20181015153335346-ep4x8",
"full_name": "octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8",
"id": 153161947,
"node_id": "MDEwOlJlcG9zaXRvcnkxNTMxNjE5NDc=",
"name": "tmp-scenario-errors-20181015182600961-dnun8",
"full_name": "octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8",
"private": false,
"owner": {
"login": "octokit-fixture-org",
Expand All @@ -33,53 +33,53 @@
"type": "Organization",
"site_admin": false
},
"html_url": "https://github.com/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8",
"html_url": "https://github.com/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8",
"forks_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/forks",
"keys_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/teams",
"hooks_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/hooks",
"issue_events_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/issues/events{/number}",
"events_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/events",
"assignees_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/assignees{/user}",
"branches_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/branches{/branch}",
"tags_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/tags",
"blobs_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/statuses/{sha}",
"languages_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/languages",
"stargazers_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/stargazers",
"contributors_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/contributors",
"subscribers_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/subscribers",
"subscription_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/subscription",
"commits_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/contents/{+path}",
"compare_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/merges",
"archive_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/downloads",
"issues_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/issues{/number}",
"pulls_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/pulls{/number}",
"milestones_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/milestones{/number}",
"notifications_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/labels{/name}",
"releases_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/releases{/id}",
"deployments_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/deployments",
"created_at": "2018-10-15T15:33:35Z",
"updated_at": "2018-10-15T15:33:35Z",
"pushed_at": "2018-10-15T15:33:36Z",
"git_url": "git://github.com/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8.git",
"ssh_url": "[email protected]:octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8.git",
"clone_url": "https://github.com/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8.git",
"svn_url": "https://github.com/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8",
"url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8",
"forks_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/forks",
"keys_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/teams",
"hooks_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/hooks",
"issue_events_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/issues/events{/number}",
"events_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/events",
"assignees_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/assignees{/user}",
"branches_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/branches{/branch}",
"tags_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/tags",
"blobs_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/statuses/{sha}",
"languages_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/languages",
"stargazers_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/stargazers",
"contributors_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/contributors",
"subscribers_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/subscribers",
"subscription_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/subscription",
"commits_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/contents/{+path}",
"compare_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/merges",
"archive_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/downloads",
"issues_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/issues{/number}",
"pulls_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/pulls{/number}",
"milestones_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/milestones{/number}",
"notifications_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/labels{/name}",
"releases_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/releases{/id}",
"deployments_url": "https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/deployments",
"created_at": "2018-10-15T18:26:01Z",
"updated_at": "2018-10-15T18:26:01Z",
"pushed_at": "2018-10-15T18:26:02Z",
"git_url": "git://github.com/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8.git",
"ssh_url": "[email protected]:octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8.git",
"clone_url": "https://github.com/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8.git",
"svn_url": "https://github.com/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8",
"homepage": null,
"size": 0,
"stargazers_count": 0,
Expand Down Expand Up @@ -132,7 +132,7 @@
},
"rawHeaders": [
"Date",
"Mon, 15 Oct 2018 15:33:36 GMT",
"Mon, 15 Oct 2018 18:26:02 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Content-Length",
Expand All @@ -146,21 +146,21 @@
"X-RateLimit-Limit",
"5000",
"X-RateLimit-Remaining",
"4986",
"4688",
"X-RateLimit-Reset",
"1539620799",
"1539628574",
"Cache-Control",
"private, max-age=60, s-maxage=60",
"Vary",
"Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag",
"\"ea492f63cc3bc1439b1ff324670694bb\"",
"\"09b67e1426617cfacbd89faf8710638f\"",
"X-OAuth-Scopes",
"admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user",
"X-Accepted-OAuth-Scopes",
"public_repo, repo",
"Location",
"https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8",
"https://api.github.com/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8",
"X-GitHub-Media-Type",
"github.v3; param=speedy-preview; format=json",
"Access-Control-Expose-Headers",
Expand All @@ -182,7 +182,7 @@
"Vary",
"Accept-Encoding",
"X-GitHub-Request-Id",
"FF1F:139B:6321F5:7D163F:5BC4B34F"
"FFE5:139E:21F7C0B:2BABA89:5BC4DBB9"
],
"reqheaders": {
"accept": "application/vnd.github.v3+json,application/vnd.github.speedy-preview+json",
Expand All @@ -196,22 +196,30 @@
{
"scope": "https://api.github.com:443",
"method": "post",
"path": "/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8/labels",
"path": "/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8/labels",
"body": {
"name": false
"name": "foo",
"color": "invalid"
},
"status": 422,
"response": {
"message": "Invalid request.\n\nFor 'properties/name', false is not a string.",
"message": "Validation Failed",
"errors": [
{
"resource": "Label",
"code": "invalid",
"field": "color"
}
],
"documentation_url": "https://developer.github.com/v3/issues/labels/#create-a-label"
},
"rawHeaders": [
"Date",
"Mon, 15 Oct 2018 15:33:38 GMT",
"Mon, 15 Oct 2018 18:26:04 GMT",
"Content-Type",
"application/json; charset=utf-8",
"Content-Length",
"163",
"180",
"Connection",
"close",
"Server",
Expand All @@ -221,9 +229,9 @@
"X-RateLimit-Limit",
"5000",
"X-RateLimit-Remaining",
"4985",
"4687",
"X-RateLimit-Reset",
"1539620799",
"1539628574",
"X-OAuth-Scopes",
"admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user",
"X-Accepted-OAuth-Scopes",
Expand All @@ -247,26 +255,26 @@
"Content-Security-Policy",
"default-src 'none'",
"X-GitHub-Request-Id",
"FF33:139E:20C71E0:2A2154F:5BC4B352"
"FFFE:139D:1C27472:244B5B2:5BC4DBBC"
],
"reqheaders": {
"accept": "application/vnd.github.v3+json,application/vnd.github.speedy-preview+json",
"content-type": "application/json;charset=utf-8",
"authorization": "token 0000000000000000000000000000000000000001",
"content-length": 14,
"content-length": 32,
"host": "api.github.com"
}
},
{
"scope": "https://api.github.com:443",
"method": "delete",
"path": "/repos/octokit-fixture-org/tmp-scenario-errors-20181015153335346-ep4x8",
"path": "/repos/octokit-fixture-org/tmp-scenario-errors-20181015182600961-dnun8",
"body": "",
"status": 204,
"response": "",
"rawHeaders": [
"Date",
"Mon, 15 Oct 2018 15:33:41 GMT",
"Mon, 15 Oct 2018 18:26:07 GMT",
"Content-Type",
"application/octet-stream",
"Connection",
Expand All @@ -278,9 +286,9 @@
"X-RateLimit-Limit",
"5000",
"X-RateLimit-Remaining",
"4984",
"4686",
"X-RateLimit-Reset",
"1539620799",
"1539628574",
"X-OAuth-Scopes",
"admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user",
"X-Accepted-OAuth-Scopes",
Expand All @@ -306,7 +314,7 @@
"Vary",
"Accept-Encoding",
"X-GitHub-Request-Id",
"FF48:139C:EA6AA3:12C6A77:5BC4B355"
"C018:139E:21F8024:2BAC013:5BC4DBBF"
],
"reqheaders": {
"accept": "application/vnd.github.v3+json,application/vnd.github.speedy-preview+json",
Expand Down
3 changes: 2 additions & 1 deletion scenarios/api.github.com/errors/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async function errors (state) {
Authorization: `token ${env.FIXTURES_USER_A_TOKEN_FULL_ACCESS}`
},
data: {
name: false
name: 'foo',
color: 'invalid'
}
})

Expand Down
3 changes: 2 additions & 1 deletion scenarios/api.github.com/errors/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ test('Errors', async (t) => {
'Content-Type': 'application/json; charset=utf-8'
},
data: {
name: false
name: 'foo',
color: 'invalid'
}
})
} catch (error) {
Expand Down

0 comments on commit e97830b

Please sign in to comment.