Skip to content

Commit

Permalink
test(end-to-end): custom fixtures
Browse files Browse the repository at this point in the history
thanks @martinb3
  • Loading branch information
martinb3 authored and gr2m committed Feb 11, 2018
1 parent 78ec679 commit ccbbaf1
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/end-to-end/custom-fixtures-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

npm link .
octokit-fixtures-server --fixtures='test/end-to-end/my-custom-scenario.json' &
serverPid=$!

sleep 3

# get fixtures id & url
FIXTURES=`curl -XPOST -H'Content-Type: application/json' http://localhost:3000/fixtures -d '{"scenario": "my-custom-scenario"}'`
ID=`echo $FIXTURES | grep -o '"id":\s*"[^"]*' | sed -E 's/"id":\s*"([^"]+)/\1/'`
URL=`echo $FIXTURES | grep -o '"url":\s*"[^"]*' | sed -E 's/"url":\s*"([^"]+)/\1/'`

# send request using id & url, test if output contains expected string
# If it does not return exit code accordingly
curl -H"Accept: application/vnd.github.v3+json" -H"X-Fixtures-Id: $ID" $URL/repos/martinb3/welcome | grep -q '"full_name":"martinb3/welcome"'
returnCode=$? # is 1 if grep could not find string above

# kill server and exit with exit code from above test
kill $serverPid
exit $returnCode
132 changes: 132 additions & 0 deletions test/end-to-end/my-custom-scenario.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
[
{
"scope": "https://api.github.com:443",
"method": "get",
"path": "/repos/martinb3/welcome",
"body": "",
"status": 200,
"response": {
"id": 1000,
"name": "welcome",
"full_name": "martinb3/welcome",
"owner": {
"login": "martinb3",
"id": 1000,
"avatar_url": "https://avatars0.githubusercontent.com/u/103033?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/martinb3",
"html_url": "https://github.com/martinb3",
"followers_url": "https://api.github.com/users/martinb3/followers",
"following_url": "https://api.github.com/users/martinb3/following{/other_user}",
"gists_url": "https://api.github.com/users/martinb3/gists{/gist_id}",
"starred_url": "https://api.github.com/users/martinb3/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/martinb3/subscriptions",
"organizations_url": "https://api.github.com/users/martinb3/orgs",
"repos_url": "https://api.github.com/users/martinb3/repos",
"events_url": "https://api.github.com/users/martinb3/events{/privacy}",
"received_events_url": "https://api.github.com/users/martinb3/received_events",
"type": "Organization",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/martinb3/welcome",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/martinb3/welcome",
"forks_url": "https://api.github.com/repos/martinb3/welcome/forks",
"keys_url": "https://api.github.com/repos/martinb3/welcome/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/martinb3/welcome/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/martinb3/welcome/teams",
"hooks_url": "https://api.github.com/repos/martinb3/welcome/hooks",
"issue_events_url": "https://api.github.com/repos/martinb3/welcome/issues/events{/number}",
"events_url": "https://api.github.com/repos/martinb3/welcome/events",
"assignees_url": "https://api.github.com/repos/martinb3/welcome/assignees{/user}",
"branches_url": "https://api.github.com/repos/martinb3/welcome/branches{/branch}",
"tags_url": "https://api.github.com/repos/martinb3/welcome/tags",
"blobs_url": "https://api.github.com/repos/martinb3/welcome/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/martinb3/welcome/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/martinb3/welcome/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/martinb3/welcome/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/martinb3/welcome/statuses/{sha}",
"languages_url": "https://api.github.com/repos/martinb3/welcome/languages",
"stargazers_url": "https://api.github.com/repos/martinb3/welcome/stargazers",
"contributors_url": "https://api.github.com/repos/martinb3/welcome/contributors",
"subscribers_url": "https://api.github.com/repos/martinb3/welcome/subscribers",
"subscription_url": "https://api.github.com/repos/martinb3/welcome/subscription",
"commits_url": "https://api.github.com/repos/martinb3/welcome/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/martinb3/welcome/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/martinb3/welcome/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/martinb3/welcome/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/martinb3/welcome/contents/{+path}",
"compare_url": "https://api.github.com/repos/martinb3/welcome/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/martinb3/welcome/merges",
"archive_url": "https://api.github.com/repos/martinb3/welcome/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/martinb3/welcome/downloads",
"issues_url": "https://api.github.com/repos/martinb3/welcome/issues{/number}",
"pulls_url": "https://api.github.com/repos/martinb3/welcome/pulls{/number}",
"milestones_url": "https://api.github.com/repos/martinb3/welcome/milestones{/number}",
"notifications_url": "https://api.github.com/repos/martinb3/welcome/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/martinb3/welcome/labels{/name}",
"releases_url": "https://api.github.com/repos/martinb3/welcome/releases{/id}",
"deployments_url": "https://api.github.com/repos/martinb3/welcome/deployments",
"created_at": "2017-10-10T16:00:00Z",
"updated_at": "2017-10-10T16:00:00Z",
"pushed_at": "2017-10-10T16:00:00Z",
"git_url": "git://github.com/martinb3/welcome.git",
"ssh_url": "git@github.com:martinb3/welcome.git",
"clone_url": "https://github.com/martinb3/welcome.git",
"svn_url": "https://github.com/martinb3/welcome",
"homepage": null,
"size": 0,
"stargazers_count": 42,
"watchers_count": 42,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 42,
"mirror_url": null,
"archived": false,
"open_issues_count": 42,
"license": null,
"forks": 42,
"open_issues": 42,
"watchers": 42,
"default_branch": "master",
"network_count": 42,
"subscribers_count": 42
},
"reqheaders": {
"accept": "application/vnd.github.v3+json",
"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",
"cache-control": "public, max-age=60, s-maxage=60",
"connection": "close",
"content-length": "6409",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
"etag": "\"00000000000000000000000000000000\"",
"last-modified": "Tue, 10 Oct 2017 16:00:00 GMT",
"status": "200 OK",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "0000:00000:0000000:0000000:00000000",
"x-ratelimit-limit": "60",
"x-ratelimit-remaining": "59",
"x-ratelimit-reset": "1507651200000",
"x-runtime-rack": "0.000000",
"x-xss-protection": "1; mode=block"
},
"badheaders": [
"authorization"
]
}
]

0 comments on commit ccbbaf1

Please sign in to comment.