Skip to content
This repository has been archived by the owner on Aug 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #142 from jrit/master
Browse files Browse the repository at this point in the history
mock with nock, move CI to trvis
  • Loading branch information
jrit committed Mar 11, 2016
2 parents 0f8e4b2 + f9de744 commit f309b54
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 116 deletions.
15 changes: 0 additions & 15 deletions .drone.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ $RECYCLE.BIN/

local-settings.json
tmp

secrets.yml
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"devDependencies": {
"mocha": "^2.3.4",
"nock": "^7.2.2",
"supertest": "^1.1.0"
}
}
2 changes: 1 addition & 1 deletion routes/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
Expand Down
8 changes: 5 additions & 3 deletions run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ npm run testcover

RESULT=$?

COMMIT="${TRAVIS_COMMIT_RANGE##*...}"

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 $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?token=$CVR_TOKEN&commit=$GITHASH"
curl -X POST "https://cvr.vokal.io/coverage/abort?owner=$REPO_OWNER&repo=$REPO_NAME&commit=$COMMIT"
fi

exit $RESULT
13 changes: 5 additions & 8 deletions test/404.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
12 changes: 6 additions & 6 deletions test/assets/webhook-synchronize.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,7 +25,7 @@
"head": {
"label": "jrit:master",
"ref": "master",
"sha": "13a66297be32769cc2e2ecc8ca7146d717708b5f",
"sha": "558bc5aa45d591b3cdfea80af29e7ffb66ff55f1",
"user": {
"login": "jrit",
"id": 1255823,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 11 additions & 9 deletions test/auth-success.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 );
Expand Down
56 changes: 32 additions & 24 deletions test/coverage.js
Original file line number Diff line number Diff line change
@@ -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 )
Expand All @@ -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 )
Expand All @@ -43,7 +43,7 @@ module.exports = function ()

it( "should validate token", function ( done )
{
request( server )
agent
.post( "/coverage" )
.field( "commit", "123" )
.field( "token", "123" )
Expand All @@ -60,7 +60,7 @@ module.exports = function ()
{
this.timeout( 5000 );

request( server )
agent
.post( "/coverage" )
.field( "commit", "123" )
.field( "owner", "123" )
Expand All @@ -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" )
Expand All @@ -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" )
Expand All @@ -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 )
Expand All @@ -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 )
Expand All @@ -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 )
Expand Down
21 changes: 18 additions & 3 deletions test/delete-repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
Expand All @@ -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 )
{
Expand Down
Loading

0 comments on commit f309b54

Please sign in to comment.