Skip to content

Commit

Permalink
Fix tests for [suggest] endpoint (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow authored Dec 28, 2017
1 parent f719705 commit 09cf211
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 3 additions & 2 deletions lib/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const githubApiUrl = process.env.GITHUB_URL || 'https://api.github.com';
// - badge: shields image URL.
// - name: string
function suggest (allowedOrigin, data, end, ask) {
// Same-host requests may be made in development or in single-server
// testing. These are legitimate, but do not have an origin header.
// The typical dev and production setups are cross-origin. However, in
// Heroku deploys and some self-hosted deploys these requests may come from
// the same host.
const origin = ask.req.headers.origin;
if (origin) {
if (allowedOrigin.includes(origin)) {
Expand Down
10 changes: 3 additions & 7 deletions service-tests/suggest.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
'use strict';

// These tests are for the badge-suggestion endpoint in lib/suggest.js. This
// endpoint is called from frontend/components/suggestion-and-search.js.

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

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


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')
.expectJSON('badges.?', {
name: 'GitHub issues',
link: 'https://github.com/atom/atom/issues',
Expand All @@ -33,7 +34,6 @@ t.create('issues, forks, stars and twitter')

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

t.create('license for non-existing project')
.get('/v1?url=' + encodeURIComponent('https://github.com/atom/atom'))
.addHeader('origin', 'https://shields.io')
.intercept(nock => nock('https://api.github.com')
.get(/\/repos\/atom\/atom\/license/)
.reply(404))
Expand All @@ -54,7 +53,6 @@ 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')
.intercept(nock => nock('https://api.github.com')
.get(/\/repos\/atom\/atom\/license/)
.reply(200, 'invalid json'), {
Expand All @@ -68,7 +66,6 @@ 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')
.intercept(nock => nock('https://api.github.com')
.get(/\/repos\/atom\/atom\/license/)
.reply(200, {
Expand All @@ -79,4 +76,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'
});

0 comments on commit 09cf211

Please sign in to comment.