Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for [suggest] endpoint #1398

Merged
merged 3 commits into from
Dec 28, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions service-tests/suggest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use strict';

const config = require('../lib/test-config');
const ServiceTester = require('./runner/service-tester');

const t = new ServiceTester({ id: 'suggest', title: 'suggest', pathPrefix: '/$suggest' });
module.exports = t;

const origin = `http://localhost:${config.port}`;

t.create('issues, forks, stars and twitter')
.get('/v1?url=' + encodeURIComponent('https://github.com/atom/atom'))
// suggest resource requires this header value
.addHeader('origin', 'https://shields.io')
.addHeader('origin', origin)
.expectJSON('badges.?', {
name: 'GitHub issues',
link: 'https://github.com/atom/atom/issues',
Expand All @@ -33,7 +35,7 @@ t.create('issues, forks, stars and twitter')

t.create('license')
.get('/v1?url=' + encodeURIComponent('https://github.com/atom/atom'))
.addHeader('origin', 'https://shields.io')
.addHeader('origin', origin)
.expectJSON('badges.?', {
name: 'GitHub license',
link: 'https://github.com/atom/atom/blob/master/LICENSE.md',
Expand All @@ -42,7 +44,7 @@ t.create('license')

t.create('license for non-existing project')
.get('/v1?url=' + encodeURIComponent('https://github.com/atom/atom'))
.addHeader('origin', 'https://shields.io')
.addHeader('origin', origin)
.intercept(nock => nock('https://api.github.com')
.get(/\/repos\/atom\/atom\/license/)
.reply(404))
Expand All @@ -54,7 +56,7 @@ t.create('license for non-existing project')

t.create('license when json response is invalid')
.get('/v1?url=' + encodeURIComponent('https://github.com/atom/atom'))
.addHeader('origin', 'https://shields.io')
.addHeader('origin', origin)
.intercept(nock => nock('https://api.github.com')
.get(/\/repos\/atom\/atom\/license/)
.reply(200, 'invalid json'), {
Expand All @@ -68,7 +70,7 @@ t.create('license when json response is invalid')

t.create('license when html_url not found in GitHub api response')
.get('/v1?url=' + encodeURIComponent('https://github.com/atom/atom'))
.addHeader('origin', 'https://shields.io')
.addHeader('origin', origin)
.intercept(nock => nock('https://api.github.com')
.get(/\/repos\/atom\/atom\/license/)
.reply(200, {
Expand All @@ -79,4 +81,3 @@ t.create('license when html_url not found in GitHub api response')
link: 'https://github.com/atom/atom',
badge: 'https://img.shields.io/github/license/atom/atom.svg'
});