From 8cac0758836e45e55aa2693e37191c8bdf3de99d Mon Sep 17 00:00:00 2001 From: Jarrett Widman Date: Mon, 7 Mar 2016 14:25:19 -0600 Subject: [PATCH 1/4] move build to drone 4 --- .drone.sec | 1 + .drone.yml | 17 ++++++++++------- .gitignore | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .drone.sec diff --git a/.drone.sec b/.drone.sec new file mode 100644 index 0000000..0c9d629 --- /dev/null +++ b/.drone.sec @@ -0,0 +1 @@ +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.U7ImF71v_sJbA1ezihPAaylkJLaDmNPb98EF3-oHwiAUxcRtgiK-yQpj-VlmQ70Z3AgOulq_Wdu7MYmvhnfSccP1FnqjkSUplb5PF9CP4LCAYKAjnSS6LSw0lxDYkeOFS50V35NE5RqWArGQ9Xkc6_kRU0AdtHM17WgV9VEHEUcaR7gcQ5u6roGqFEmIwHFDAV8UiDxx-wEBogKGXHwiGco2KKP2Xwb6zPigs4PUkuF-XYZOnU83IbK-LHEcZYv1qPkpj87QA8mfY2kr0BeUbxSLVl8pXpD4Wr-A_ce7i3hTeOdi_6SzYwD1YP5mArYgP57NHWtukCws8Paai1DpcA.33QBH1TIZugxEBIj.3olIOTMqLetSGfWbheaJ_NSQVUNo6TyulyaDngxRjHfsyjD20vNalLkLgLj8etUFpKYCgegrD5aRz2jFAKRePWYQwhp8yxo7Wv406qryvdzvQJ0fMV3W2v26BmglURcOYxcyn-M5yxTbqTax-2QBhOOC4AqoWnlu3Ow6pb0pcb_onPfTKJfqem50UZIMiU9cadFBoAG6CzTU2LeHjiNtnactjWoAYv9RctdsGdnj_Ez5--oVbuqRErYURg2mO5n06Z1BzCIw3etthH7tlbN5LuIDUB7km-TAnhb7cHy4t6jcV0GogHnpzJITrv6EiNcqTKcr_DOZb0e_3Q3cg5iK2ui0bW_11JbAH9ijTKhFuzX1BgYLxSpg4Wa9gA.8Vd21XSFHIoSyVQB4NYHfA diff --git a/.drone.yml b/.drone.yml index fc1bad4..44a81f2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,14 +1,17 @@ image: docker.vokal.io/web-testing -env: - - CVR_TOKEN=$$cvrToken - - GITHUB_CLIENTID=$$gitHubClientId - - GITHUB_CLIENTSECRET=$$gitHubClientSecret - - DB_CONN=$$mongoConn +build: + image: registry.vokal.io/web-testing + environment: + - REPO_OWNER=vokal + - REPO_NAME=cvr-view - GITHUB_CALLBACKURL=https://cvr.vokal.io/auth/github/callback - GITHUB_ORGS_WHITELIST=vokal - HOST=https://cvr.vokal.io/ - - GITHUB_TESTING_AUTH_TOKEN=$$gitHubTestingAuthToken -script: + - GITHUB_CLIENTID=$$GITHUB_CLIENTID + - GITHUB_CLIENTSECRET=$$GITHUB_CLIENTSECRET + - DB_CONN=$$DB_CONN + - GITHUB_TESTING_AUTH_TOKEN=$$GITHUB_TESTING_AUTH_TOKEN + commands: - npm install --silent -g istanbul - npm install --silent - chmod +x run-build.sh diff --git a/.gitignore b/.gitignore index 614240c..9b9b68a 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,5 @@ $RECYCLE.BIN/ local-settings.json tmp + +secrets.yml From ec778d987c656e31a96c739f11f80ca896bfa7aa Mon Sep 17 00:00:00 2001 From: Jarrett Widman Date: Mon, 7 Mar 2016 14:27:29 -0600 Subject: [PATCH 2/4] update build --- run-build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/run-build.sh b/run-build.sh index eb4c09b..2a7b146 100644 --- a/run-build.sh +++ b/run-build.sh @@ -5,10 +5,10 @@ npm run testcover RESULT=$? if [ $RESULT == 0 ]; then - GITHASH="$(git rev-parse HEAD)" - curl -F coverage=@coverage/lcov.info "https://cvr.vokal.io/coverage?token=$CVR_TOKEN&commit=$GITHASH&removepath=/var/cache/drone/src/github.com/vokal/cvr-view/&coveragetype=lcov" + echo "publish coverage for $DRONE_COMMIT" + curl -F coverage=@coverage/net/lcov.info "https://cvr.vokal.io/coverage?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$DRONE_COMMIT&coveragetype=lcov" else - curl -X POST "https://cvr.vokal.io/coverage/abort?token=$CVR_TOKEN&commit=$GITHASH" + curl -X POST "https://cvr.vokal.io/coverage/abort?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$GITHASH" fi exit $RESULT From 80ac35ff8f072c67462e227d1e9c4149f81d057b Mon Sep 17 00:00:00 2001 From: Jarrett Widman Date: Mon, 7 Mar 2016 14:47:19 -0600 Subject: [PATCH 3/4] yml issue? --- .drone.sec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.sec b/.drone.sec index 0c9d629..94d0d31 100644 --- a/.drone.sec +++ b/.drone.sec @@ -1 +1 @@ -eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.U7ImF71v_sJbA1ezihPAaylkJLaDmNPb98EF3-oHwiAUxcRtgiK-yQpj-VlmQ70Z3AgOulq_Wdu7MYmvhnfSccP1FnqjkSUplb5PF9CP4LCAYKAjnSS6LSw0lxDYkeOFS50V35NE5RqWArGQ9Xkc6_kRU0AdtHM17WgV9VEHEUcaR7gcQ5u6roGqFEmIwHFDAV8UiDxx-wEBogKGXHwiGco2KKP2Xwb6zPigs4PUkuF-XYZOnU83IbK-LHEcZYv1qPkpj87QA8mfY2kr0BeUbxSLVl8pXpD4Wr-A_ce7i3hTeOdi_6SzYwD1YP5mArYgP57NHWtukCws8Paai1DpcA.33QBH1TIZugxEBIj.3olIOTMqLetSGfWbheaJ_NSQVUNo6TyulyaDngxRjHfsyjD20vNalLkLgLj8etUFpKYCgegrD5aRz2jFAKRePWYQwhp8yxo7Wv406qryvdzvQJ0fMV3W2v26BmglURcOYxcyn-M5yxTbqTax-2QBhOOC4AqoWnlu3Ow6pb0pcb_onPfTKJfqem50UZIMiU9cadFBoAG6CzTU2LeHjiNtnactjWoAYv9RctdsGdnj_Ez5--oVbuqRErYURg2mO5n06Z1BzCIw3etthH7tlbN5LuIDUB7km-TAnhb7cHy4t6jcV0GogHnpzJITrv6EiNcqTKcr_DOZb0e_3Q3cg5iK2ui0bW_11JbAH9ijTKhFuzX1BgYLxSpg4Wa9gA.8Vd21XSFHIoSyVQB4NYHfA +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.GEF1oycfwz0IIvM4kuviYgG4iTviloBmvzVTKQ9Vt8AKv09teGCWGFgcscu8uPJPZQxBANIrjFtaHSJMX03yX6Dia4a4HI-xmxhcAVl1Up1aPx9ROrUPL-h0dePhU8YZL17MQ-L-Cs3QkOnwR04bU14l7kAnaVJt8Lbl5OYUtGpgaffowQsdiSR-xkZ25BI-CsREc_RD8MHnat353ld8l9QiXmdTftAfU9KPlt1r5DmADEn7WKXSGFF48Z7aBRFWrvaTf5__kaFUoeXJwHpfKW30pNhFVIRmkXnvsnHt4K0BrLfiAgpQVQi-Rqq6y9yE9D8M1jT-xJmDv5F_vW0Fkg.NZh3E8Jcv2-f1dnF.oMdxBfT8qsyV9vhYQNiGmkP3Hj7c633hDiYLiDPVEZNmtiRh3-unoOU1A3bu1BeKgri8iubuJdnMaa1ECsyj4TgZQOLgWkOCu6RmJ_LLEYNbFhTmBKTI8D0gb9URSVEfy01MIUmKWw28fWtvMxUf_Y9EISWBn6mdfK10HsPWk6HhiZQHxxyV8xzOKZihwlq1U2Niedc-oPp4oA9hs8BHGmA0lMO5LEDNYlo5q92NXPrvHTdYEvi1FHF8FIJbhdS9G9_bfqWO8E4-FsUiWWxAjOf-jJUvxwsTDaKVaoC0-havGeZx2Lf2r1L_Qde3aQwWhIPjFGCPqNbsB-aQLYAD02hwwYQFoOFNboWJcOSTxtoWBEw.aC4votwYvRxzutyfTydWcA From f9de744b21b5a1ee811de3a60d751f94cded8cc2 Mon Sep 17 00:00:00 2001 From: Jarrett Widman Date: Thu, 10 Mar 2016 16:39:47 -0600 Subject: [PATCH 4/4] use nock for test mocks, move CI to travis --- .drone.sec | 1 - .drone.yml | 18 --------- .travis.yml | 21 +++++++++++ package.json | 1 + routes/file.js | 2 +- run-build.sh | 8 ++-- test/404.js | 13 +++---- test/assets/webhook-synchronize.json | 12 +++--- test/auth-success.js | 20 +++++----- test/coverage.js | 56 ++++++++++++++++------------ test/delete-repo.js | 21 +++++++++-- test/new-token.js | 13 +++++-- test/repo-details.js | 40 +++++++++++++++----- test/repos.js | 46 ++++++++++++++++++++--- test/shields.js | 17 ++++----- test/upload.js | 13 +++---- test/webhook.js | 22 ++++++----- 17 files changed, 204 insertions(+), 120 deletions(-) delete mode 100644 .drone.sec delete mode 100644 .drone.yml create mode 100644 .travis.yml diff --git a/.drone.sec b/.drone.sec deleted file mode 100644 index 94d0d31..0000000 --- a/.drone.sec +++ /dev/null @@ -1 +0,0 @@ -eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.GEF1oycfwz0IIvM4kuviYgG4iTviloBmvzVTKQ9Vt8AKv09teGCWGFgcscu8uPJPZQxBANIrjFtaHSJMX03yX6Dia4a4HI-xmxhcAVl1Up1aPx9ROrUPL-h0dePhU8YZL17MQ-L-Cs3QkOnwR04bU14l7kAnaVJt8Lbl5OYUtGpgaffowQsdiSR-xkZ25BI-CsREc_RD8MHnat353ld8l9QiXmdTftAfU9KPlt1r5DmADEn7WKXSGFF48Z7aBRFWrvaTf5__kaFUoeXJwHpfKW30pNhFVIRmkXnvsnHt4K0BrLfiAgpQVQi-Rqq6y9yE9D8M1jT-xJmDv5F_vW0Fkg.NZh3E8Jcv2-f1dnF.oMdxBfT8qsyV9vhYQNiGmkP3Hj7c633hDiYLiDPVEZNmtiRh3-unoOU1A3bu1BeKgri8iubuJdnMaa1ECsyj4TgZQOLgWkOCu6RmJ_LLEYNbFhTmBKTI8D0gb9URSVEfy01MIUmKWw28fWtvMxUf_Y9EISWBn6mdfK10HsPWk6HhiZQHxxyV8xzOKZihwlq1U2Niedc-oPp4oA9hs8BHGmA0lMO5LEDNYlo5q92NXPrvHTdYEvi1FHF8FIJbhdS9G9_bfqWO8E4-FsUiWWxAjOf-jJUvxwsTDaKVaoC0-havGeZx2Lf2r1L_Qde3aQwWhIPjFGCPqNbsB-aQLYAD02hwwYQFoOFNboWJcOSTxtoWBEw.aC4votwYvRxzutyfTydWcA diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index 44a81f2..0000000 --- a/.drone.yml +++ /dev/null @@ -1,18 +0,0 @@ -image: docker.vokal.io/web-testing -build: - image: registry.vokal.io/web-testing - environment: - - REPO_OWNER=vokal - - REPO_NAME=cvr-view - - GITHUB_CALLBACKURL=https://cvr.vokal.io/auth/github/callback - - GITHUB_ORGS_WHITELIST=vokal - - HOST=https://cvr.vokal.io/ - - GITHUB_CLIENTID=$$GITHUB_CLIENTID - - GITHUB_CLIENTSECRET=$$GITHUB_CLIENTSECRET - - DB_CONN=$$DB_CONN - - GITHUB_TESTING_AUTH_TOKEN=$$GITHUB_TESTING_AUTH_TOKEN - commands: - - npm install --silent -g istanbul - - npm install --silent - - chmod +x run-build.sh - - ./run-build.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..ebd4f2a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,21 @@ +language: node_js +node_js: + - "node" +services: + - mongodb +env: + global: + - REPO_OWNER=vokal + - REPO_NAME=cvr-view + - GITHUB_CALLBACKURL=https://cvr.vokal.io/auth/github/callback + - GITHUB_ORGS_WHITELIST=vokal + - HOST=https://cvr.vokal.io/ + - GITHUB_CLIENTID=test + - GITHUB_CLIENTSECRET=test + - DB_CONN=mongodb://localhost +install: + - npm install -g istanbul + - npm install +script: + - chmod +x run-build.sh + - ./run-build.sh diff --git a/package.json b/package.json index 3ce2466..b5f6d35 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ }, "devDependencies": { "mocha": "^2.3.4", + "nock": "^7.2.2", "supertest": "^1.1.0" } } diff --git a/routes/file.js b/routes/file.js index 61f7f89..3b0440f 100644 --- a/routes/file.js +++ b/routes/file.js @@ -80,7 +80,7 @@ module.exports = function ( req, res, next ) + ". Is the path correctly based from the project root?", 404 ) ); } - if( errMessage.indexOf( "No commit found for the ref" ) > -1 ) + if( errMessage.indexOf && errMessage.indexOf( "No commit found for the ref" ) > -1 ) { return next( createError( "The hash " + req.params.hash + " does not exist", 404 ) ); } diff --git a/run-build.sh b/run-build.sh index 2a7b146..c5a85d8 100644 --- a/run-build.sh +++ b/run-build.sh @@ -4,11 +4,13 @@ npm run testcover RESULT=$? +COMMIT="${TRAVIS_COMMIT_RANGE##*...}" + if [ $RESULT == 0 ]; then - echo "publish coverage for $DRONE_COMMIT" - curl -F coverage=@coverage/net/lcov.info "https://cvr.vokal.io/coverage?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$DRONE_COMMIT&coveragetype=lcov" + echo "publish coverage for $COMMIT" + curl -F coverage=@coverage/lcov.info "https://cvr.vokal.io/coverage?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$COMMIT&coveragetype=lcov" else - curl -X POST "https://cvr.vokal.io/coverage/abort?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$GITHASH" + curl -X POST "https://cvr.vokal.io/coverage/abort?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$COMMIT" fi exit $RESULT diff --git a/test/404.js b/test/404.js index f9e17ca..0c9f413 100644 --- a/test/404.js +++ b/test/404.js @@ -2,23 +2,20 @@ var assert = require( "assert" ); var request = require( "supertest" ); -var app = require( "./server" ); +var app = require( "../app" ); module.exports = function () { - var server; + var agent; before( function ( done ) { - app( function ( err, res ) - { - server = res; - done( err ); - } ); + agent = request.agent( app ); + done(); } ); it( "should have a 404 page", function ( done ) { - request( server ) + agent .get( "/this/is/not/a/page" ) .expect( 404 ) .end( done ); diff --git a/test/assets/webhook-synchronize.json b/test/assets/webhook-synchronize.json index 5c91286..ea4a8d6 100644 --- a/test/assets/webhook-synchronize.json +++ b/test/assets/webhook-synchronize.json @@ -14,7 +14,7 @@ "type": "User", "site_admin": false }, - "body": "@foresmac pulling up new dep", + "body": "pulling up new dep", "created_at": "2015-09-10T17:51:48Z", "updated_at": "2015-09-10T18:18:21Z", "closed_at": null, @@ -25,7 +25,7 @@ "head": { "label": "jrit:master", "ref": "master", - "sha": "13a66297be32769cc2e2ecc8ca7146d717708b5f", + "sha": "558bc5aa45d591b3cdfea80af29e7ffb66ff55f1", "user": { "login": "jrit", "id": 1255823, @@ -35,8 +35,8 @@ }, "repo": { "id": 35064431, - "name": "cvr-view-seed", - "full_name": "jrit/cvr-view-seed", + "name": "cvr-view-test", + "full_name": "jrit/cvr-view-test", "owner": { "login": "jrit", "id": 1255823, @@ -59,8 +59,8 @@ }, "repo": { "id": 35064414, - "name": "cvr-view-seed", - "full_name": "vokal/cvr-view-seed", + "name": "cvr-view-test", + "full_name": "vokal/cvr-view-test", "owner": { "login": "vokal", "id": 375026, diff --git a/test/auth-success.js b/test/auth-success.js index 80a32de..d702d64 100644 --- a/test/auth-success.js +++ b/test/auth-success.js @@ -2,23 +2,21 @@ var assert = require( "assert" ); var request = require( "supertest" ); -var app = require( "./server" ); +var nock = require( "nock" ); +var app = require( "../app" ); module.exports = function () { - var server; + var agent; before( function ( done ) { - app( function ( err, res ) - { - server = res; - done( err ); - } ); + agent = request.agent( app ); + done(); } ); it( "should redirect from the page", function ( done ) { - request( server ) + agent .get( "/auth/github/success" ) .expect( 302 ) .end( function ( err, res ) @@ -30,7 +28,11 @@ module.exports = function () it( "should fail token auth when invalid", function ( done ) { - request( server ) + nock( "https://api.github.com" ) + .get( "/user?access_token=123" ) + .reply( 401 ); + + agent .post( "/auth/github/token" ) .field( "token", "123" ) .expect( 401, done ); diff --git a/test/coverage.js b/test/coverage.js index e4cb6eb..2ca487e 100644 --- a/test/coverage.js +++ b/test/coverage.js @@ -1,24 +1,24 @@ "use strict"; +var util = require( "util" ); var assert = require( "assert" ); var request = require( "supertest" ); -var app = require( "./server" ); +var app = require( "../app" ); +var nock = require( "nock" ); +var commit = "558bc5aa45d591b3cdfea80af29e7ffb66ff55f1"; module.exports = function () { - var server; + var agent; before( function ( done ) { - app( function ( err, res ) - { - server = res; - done( err ); - } ); + agent = request.agent( app ); + done(); } ); it( "should validate posting coverage", function ( done ) { - request( server ) + agent .post( "/coverage" ) .expect( 400 ) .end( function ( err, res ) @@ -30,7 +30,7 @@ module.exports = function () it( "should validate repo is required", function ( done ) { - request( server ) + agent .post( "/coverage" ) .field( "commit", "123" ) .expect( 400 ) @@ -43,7 +43,7 @@ module.exports = function () it( "should validate token", function ( done ) { - request( server ) + agent .post( "/coverage" ) .field( "commit", "123" ) .field( "token", "123" ) @@ -60,7 +60,7 @@ module.exports = function () { this.timeout( 5000 ); - request( server ) + agent .post( "/coverage" ) .field( "commit", "123" ) .field( "owner", "123" ) @@ -76,7 +76,7 @@ module.exports = function () it( "should validate coverage has content", function ( done ) { - request( server ) + agent .post( "/coverage" ) .field( "commit", "123" ) .field( "owner", "123" ) @@ -92,7 +92,7 @@ module.exports = function () it( "should validate coverage has a valid type", function ( done ) { - request( server ) + agent .post( "/coverage" ) .field( "commit", "123" ) .field( "owner", "123" ) @@ -109,13 +109,11 @@ module.exports = function () it( "should validate that commit exists on GitHub", function ( done ) { - this.timeout( 10000 ); - - request( server ) + agent .post( "/coverage" ) .field( "commit", "thisisnotacommit" ) .field( "owner", "vokal" ) - .field( "repo", "cvr-view-seed" ) + .field( "repo", "cvr-view-test" ) .attach( "coverage", "test/assets/lcov.info" ) .expect( 400 ) .end( function ( err, res ) @@ -127,13 +125,19 @@ module.exports = function () it( "should save coverage", function ( done ) { - this.timeout( 10000 ); + nock( "https://api.github.com" ) + .get( util.format( "/repos/vokal/cvr-view-test/commits?sha=%s&access_token=test", commit ) ) + .reply( 200 ) + .get( "/repos/vokal/cvr-view-test/pulls?access_token=test" ) + .reply( 200, [ { head: { sha: commit } } ] ) + .post( util.format( "/repos/vokal/cvr-view-test/statuses/%s?access_token=test", commit ) ) + .reply( 201 ); - request( server ) + agent .post( "/coverage" ) - .field( "commit", "13a66297be32769cc2e2ecc8ca7146d717708b5f" ) + .field( "commit", commit ) .field( "owner", "vokal" ) - .field( "repo", "cvr-view-seed" ) + .field( "repo", "cvr-view-test" ) .attach( "coverage", "test/assets/lcov.info" ) .expect( 201 ) .end( function ( err, res ) @@ -145,11 +149,15 @@ module.exports = function () it( "should abort pending coverage", function ( done ) { - request( server ) + nock( "https://api.github.com" ) + .post( util.format( "/repos/vokal/cvr-view-test/statuses/%s?access_token=test", commit ) ) + .reply( 200 ); + + agent .post( "/coverage/abort" ) - .field( "commit", "13a66297be32769cc2e2ecc8ca7146d717708b5f" ) + .field( "commit", "558bc5aa45d591b3cdfea80af29e7ffb66ff55f1" ) .field( "owner", "vokal" ) - .field( "repo", "cvr-view-seed" ) + .field( "repo", "cvr-view-test" ) .field( "reason", "This was a test" ) .expect( 201 ) .end( function ( err, res ) diff --git a/test/delete-repo.js b/test/delete-repo.js index 50a9cbe..d6b9f70 100644 --- a/test/delete-repo.js +++ b/test/delete-repo.js @@ -2,7 +2,9 @@ var assert = require( "assert" ); var request = require( "supertest" ); +var nock = require( "nock" ); var app = require( "../app" ); +var env = require( "../lib/env" ); module.exports = function () { @@ -15,16 +17,29 @@ module.exports = function () it( "should redirect on succesful login", function ( done ) { + nock( "https://api.github.com" ) + .get( "/user?access_token=test" ) + .reply( 200, { login: "cvr-view-test" }, { "x-oauth-scopes": "repo, user" } ); + agent .post( "/auth/github/token" ) - .field( "token", process.env.GITHUB_TESTING_AUTH_TOKEN ) + .field( "token", "test" ) .expect( 302, done ); } ); - it( "should delete the cvr-view-seed repo", function ( done ) + it( "should delete the cvr-view-test repo", function ( done ) { + nock( "https://api.github.com" ) + .get( "/repos/vokal/cvr-view-test/hooks" ) + .query( { access_token: "test", per_page: 100, page: 1 } ) + .reply( 200, [ { + config: { url: env.host + "webhook" } + } ] ) + .delete( "/repos/vokal/cvr-view-test/hooks?access_token=test" ) + .reply( 200 ); + agent - .post( "/repo/vokal/cvr-view-seed/delete" ) + .post( "/repo/vokal/cvr-view-test/delete" ) .expect( 302 ) .end( function ( err, res ) { diff --git a/test/new-token.js b/test/new-token.js index 4bf2eaa..541b484 100644 --- a/test/new-token.js +++ b/test/new-token.js @@ -3,6 +3,7 @@ var assert = require( "assert" ); var request = require( "supertest" ); var app = require( "../app" ); +var nock = require( "nock" ); module.exports = function () { @@ -15,20 +16,24 @@ module.exports = function () it( "should redirect on succesful login", function ( done ) { + nock( "https://api.github.com" ) + .get( "/user?access_token=test" ) + .reply( 200, { login: "cvr-view-test" }, { "x-oauth-scopes": "repo, user" } ); + agent .post( "/auth/github/token" ) - .field( "token", process.env.GITHUB_TESTING_AUTH_TOKEN ) + .field( "token", "test" ) .expect( 302, done ); } ); - it( "should create a new token for the cvr-view-seed repo", function ( done ) + it( "should create a new token for the cvr-view-test repo", function ( done ) { agent - .get( "/repo/vokal/cvr-view-seed/new-token" ) + .get( "/repo/vokal/cvr-view-test/new-token" ) .expect( 302 ) .end( function ( err, res ) { - assert.equal( res.headers.location, "/repo/vokal/cvr-view-seed" ); + assert.equal( res.headers.location, "/repo/vokal/cvr-view-test" ); done( err ); } ); } ); diff --git a/test/repo-details.js b/test/repo-details.js index cb6efcd..8959b86 100644 --- a/test/repo-details.js +++ b/test/repo-details.js @@ -3,6 +3,10 @@ var assert = require( "assert" ); var request = require( "supertest" ); var app = require( "../app" ); +var nock = require( "nock" ); +var fs = require( "fs" ); +var path = require( "path" ); +var env = require( "../lib/env" ); module.exports = function () { @@ -15,9 +19,13 @@ module.exports = function () it( "should redirect on succesful login", function ( done ) { + nock( "https://api.github.com" ) + .get( "/user?access_token=test" ) + .reply( 200, { login: "cvr-view-test" }, { "x-oauth-scopes": "repo, user" } ); + agent .post( "/auth/github/token" ) - .field( "token", process.env.GITHUB_TESTING_AUTH_TOKEN ) + .field( "token", "test" ) .expect( 302 ) .end( function ( err, res ) { @@ -26,41 +34,53 @@ module.exports = function () } ); } ); - it( "should load cvr-view-seed repo", function ( done ) + it( "should load cvr-view-test repo", function ( done ) { - this.timeout( 10000 ); + nock( "https://api.github.com" ) + .get( "/repos/vokal/cvr-view-test/hooks" ) + .query( { access_token: "test", per_page: 100, page: 1 } ) + .reply( 200, [ { + config: { url: env.host + "webhook" } + } ] ); agent - .get( "/repo/vokal/cvr-view-seed" ) + .get( "/repo/vokal/cvr-view-test" ) .expect( 200 ) .end( function ( err, res ) { app.repoToken = res.text.match( /\/coverage\?token=([0-9a-z]*)&commit=:commit_hash/ )[ 1 ]; - app.repoFile = res.text.match( /\/repo\/vokal\/cvr-view-seed\/[0-9a-z]*\/[^"]*/ )[ 0 ]; + app.repoFile = res.text.match( /\/repo\/vokal\/cvr-view-test\/[0-9a-z]*\/[^"]*/ )[ 0 ]; assert.equal( !!app.repoToken, true ); done( err ); } ); } ); - it( "should load cvr-view-seed repo settings", function ( done ) + it( "should load cvr-view-test repo settings", function ( done ) { agent - .get( "/repo/vokal/cvr-view-seed/settings" ) + .get( "/repo/vokal/cvr-view-test/settings" ) .expect( 200, done ); } ); - it( "should update cvr-view-seed repo settings", function ( done ) + it( "should update cvr-view-test repo settings", function ( done ) { agent - .post( "/repo/vokal/cvr-view-seed/settings" ) + .post( "/repo/vokal/cvr-view-test/settings" ) .field( "minPassingLinePercent", 50 ) .field( "removePath", "" ) .field( "prependPath", "" ) .expect( 200, done ); } ); - it( "should load a cvr-view-seed file", function ( done ) + it( "should load a cvr-view-test file", function ( done ) { + nock( "https://api.github.com" ) + .get( "/repos/vokal/cvr-view-test/contents/app.js?ref=558bc5aa45d591b3cdfea80af29e7ffb66ff55f1&access_token=test" ) + .reply( 200, { + encoding: "base64", + content: fs.readFileSync( path.resolve( process.cwd(), "app.js" ) ).toString() + } ); + agent .get( app.repoFile ) .expect( 200, done ); diff --git a/test/repos.js b/test/repos.js index 1ee5aef..d1a77af 100644 --- a/test/repos.js +++ b/test/repos.js @@ -3,6 +3,7 @@ var assert = require( "assert" ); var request = require( "supertest" ); var app = require( "../app" ); +var nock = require( "nock" ); module.exports = function () { @@ -30,11 +31,13 @@ module.exports = function () it( "should redirect to repos on succesful login", function ( done ) { - this.timeout( 10000 ); + nock( "https://api.github.com" ) + .get( "/user?access_token=test" ) + .reply( 200, { login: "cvr-view-test" }, { "x-oauth-scopes": "repo, user" } ); agent .post( "/auth/github/token" ) - .field( "token", process.env.GITHUB_TESTING_AUTH_TOKEN ) + .field( "token", "test" ) .expect( 302 ) .end( function ( err, res ) { @@ -45,19 +48,52 @@ module.exports = function () it( "should load repos page", function ( done ) { - this.timeout( 30000 ); // this takes too long on the first load + nock( "https://api.github.com" ) + .get( "/user/orgs" ) + .query( { per_page: "100", access_token: "test" } ) + .reply( 200, [ { + "login": "vokal" + } ] ); + + nock( "https://api.github.com" ) + .get( "/orgs/vokal/repos" ) + .query( { access_token: "test", per_page: 100, page: 1 } ) + .reply( 200, [ { + "owner": { + "login": "vokal" + }, + "name": "cvr-view-test", + "full_name": "vokal/cvr-view-test" + } ] ); + + nock( "https://api.github.com" ) + .get( "/user/repos" ) + .query( { access_token: "test", per_page: 100, page: 1 } ) + .reply( 200, [ { + "owner": { "login": "test" }, + "name": "cvr-view-test", + "full_name": "vokal/cvr-view-test", + "permissions": { "push": true } + } ] ); + + nock( "https://api.github.com" ) + .get( "/repos/vokal/cvr-view-test/hooks" ) + .query( { access_token: "test", per_page: 100, page: 1 } ) + .reply( 200, [] ) + .post( "/repos/vokal/cvr-view-test/hooks?access_token=test" ) + .reply( 201 ); agent .get( "/repos" ) .expect( 200, done ); } ); - it( "should activate the cvr-view-seed repo", function ( done ) + it( "should activate the cvr-view-test repo", function ( done ) { this.timeout( 10000 ); agent - .get( "/repo/vokal/cvr-view-seed" ) + .get( "/repo/vokal/cvr-view-test" ) .expect( 200 ) .end( function ( err, res ) { diff --git a/test/shields.js b/test/shields.js index f3a260f..782ba87 100644 --- a/test/shields.js +++ b/test/shields.js @@ -2,30 +2,27 @@ var assert = require( "assert" ); var request = require( "supertest" ); -var app = require( "./server" ); +var app = require( "../app" ); module.exports = function () { - var server; + var agent; before( function ( done ) { - app( function ( err, res ) - { - server = res; - done( err ); - } ); + agent = request.agent( app ); + done(); } ); it( "should load a shield", function ( done ) { - request( server ) - .get( "/vokal/cvr-view-seed/shield.svg" ) + agent + .get( "/vokal/cvr-view-test/shield.svg" ) .expect( 200, done ); } ); it( "should 404 a shield on non-existing repo", function ( done ) { - request( server ) + agent .get( "/vokal/notthedroidsyouarelookingfor/shield.svg" ) .expect( 404, done ); } ); diff --git a/test/upload.js b/test/upload.js index b93b638..e727c75 100644 --- a/test/upload.js +++ b/test/upload.js @@ -2,23 +2,20 @@ var assert = require( "assert" ); var request = require( "supertest" ); -var app = require( "./server" ); +var app = require( "../app" ); module.exports = function () { - var server; + var agent; before( function ( done ) { - app( function ( err, res ) - { - server = res; - done( err ); - } ); + agent = request.agent( app ); + done(); } ); it( "should exist", function ( done ) { - request( server ) + agent .get( "/upload" ) .expect( 200, done ); } ); diff --git a/test/webhook.js b/test/webhook.js index 4b2f381..fe3fef0 100644 --- a/test/webhook.js +++ b/test/webhook.js @@ -2,24 +2,22 @@ var assert = require( "assert" ); var request = require( "supertest" ); -var app = require( "./server" ); +var app = require( "../app" ); var fs = require( "fs" ); +var nock = require( "nock" ); module.exports = function () { - var server; + var agent; before( function ( done ) { - app( function ( err, res ) - { - server = res; - done( err ); - } ); + agent = request.agent( app ); + done(); } ); it( "should reject a non-PR request", function ( done ) { - request( server ) + agent .post( "/webhook" ) .expect( 202 ) .end( function ( err, res ) @@ -31,7 +29,11 @@ module.exports = function () it( "should accept a sync hook", function ( done ) { - request( server ) + nock( "https://api.github.com" ) + .post( "/repos/vokal/cvr-view-test/statuses/558bc5aa45d591b3cdfea80af29e7ffb66ff55f1?access_token=test" ) + .reply( 201 ); + + agent .post( "/webhook" ) .set( "Content-Type", "application/json" ) .send( fs.readFileSync( "./test/assets/webhook-synchronize.json" ).toString() ) @@ -48,7 +50,7 @@ module.exports = function () var hook = JSON.parse( fs.readFileSync( "./test/assets/webhook-synchronize.json" ).toString() ); hook.pull_request.title += "[ci skip]"; - request( server ) + agent .post( "/webhook" ) .set( "Content-Type", "application/json" ) .send( JSON.stringify( hook ) )