Files
shields/services/suggest.integration.js
T
Marcin MielnickiandGitHub eeb78ccf15 Badge suggestion feature fix (#3331)
* Display suggested badges

* E2e test for badge suggestion

* Suggest resource returns example with pattern

* Do not require preview in MarkupModalContent

* Skip integration test for suggestion

* Unmodifiable path in customizer

* Use suggested link

* Allow to change suggested badges

* Enable skipped test

* Enable skipped test

* Code refactoring

* Code refactoring

* Code refactoring

* Code refactoring

* Code refactoring

* Code refactoring

* Unused code removed

* Unused code removed

* getExampleWithServiceByPattern helper added

* BadgeExamples uses examples instead of services definitions

* Revert "getExampleWithServiceByPattern helper added"

This reverts commit 80839fd705.

* style removed from example

* example.exact replaced with preview.buildFromExample

* keywords are required again

* Code refactoring

* More e2e tests for suggestion feature

* Code refactoring

* Build add with a base url

* showActualParams -> isPrefilled

* A new schema for BadgeExamples

* Link moved to queryParams

* Updated documentation for the suggest reponse format

* Link moved to queryParams - another test updated

* Revert "Link moved to queryParams - another test updated"

This reverts commit b5f811bb07.

* Revert "Link moved to queryParams"

This reverts commit 3b54c6d2b4.

* Disable changes in path in suggested badges

* 'link' element documentation restored
2019-04-29 18:38:27 +02:00

192 lines
5.7 KiB
JavaScript

'use strict'
const { expect } = require('chai')
const got = require('got')
const Camp = require('camp')
const portfinder = require('portfinder')
const serverSecrets = require('../lib/server-secrets')
const { setRoutes } = require('./suggest')
const GithubApiProvider = require('./github/github-api-provider')
describe('GitHub badge suggestions', function() {
const githubApiBaseUrl = process.env.GITHUB_URL || 'https://api.github.com'
let token, apiProvider
before(function() {
token = serverSecrets.gh_token
if (!token) {
throw Error('The integration tests require a gh_token to be set')
}
apiProvider = new GithubApiProvider({
baseUrl: githubApiBaseUrl,
globalToken: token,
withPooling: false,
})
})
let port, baseUrl
before(async function() {
port = await portfinder.getPortPromise()
baseUrl = `http://127.0.0.1:${port}`
})
let camp
before(async function() {
camp = Camp.start({ port, hostname: '::' })
await new Promise(resolve => camp.on('listening', () => resolve()))
})
after(async function() {
if (camp) {
await new Promise(resolve => camp.close(resolve))
camp = undefined
}
})
const origin = 'https://example.test'
before(function() {
setRoutes([origin], apiProvider, camp)
})
context('with an existing project', function() {
it('returns the expected suggestions', async function() {
const { statusCode, body } = await got(
`${baseUrl}/$suggest/v1?url=${encodeURIComponent(
'https://github.com/atom/atom'
)}`,
{
json: true,
}
)
expect(statusCode).to.equal(200)
expect(body).to.deep.equal({
suggestions: [
{
title: 'GitHub issues',
link: 'https://github.com/atom/atom/issues',
example: {
pattern: '/github/issues/:user/:repo',
namedParams: { user: 'atom', repo: 'atom' },
queryParams: {},
},
},
{
title: 'GitHub forks',
link: 'https://github.com/atom/atom/network',
example: {
pattern: '/github/forks/:user/:repo',
namedParams: { user: 'atom', repo: 'atom' },
queryParams: {},
},
},
{
title: 'GitHub stars',
link: 'https://github.com/atom/atom/stargazers',
example: {
pattern: '/github/stars/:user/:repo',
namedParams: { user: 'atom', repo: 'atom' },
queryParams: {},
},
},
{
title: 'GitHub license',
link: 'https://github.com/atom/atom/blob/master/LICENSE.md',
example: {
pattern: '/github/license/:user/:repo',
namedParams: { user: 'atom', repo: 'atom' },
queryParams: {},
},
},
{
title: 'Twitter',
link:
'https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fatom%2Fatom',
example: {
pattern: '/twitter/url/:protocol(https|http)/:hostAndPath+',
namedParams: {
protocol: 'https',
hostAndPath: 'github.com/atom/atom',
},
queryParams: {},
},
preview: {
style: 'social',
},
},
],
})
})
})
context('with a non-existent project', function() {
it('returns the expected suggestions', async function() {
this.timeout(5000)
const { statusCode, body } = await got(
`${baseUrl}/$suggest/v1?url=${encodeURIComponent(
'https://github.com/badges/not-a-real-project'
)}`,
{
json: true,
}
)
expect(statusCode).to.equal(200)
expect(body).to.deep.equal({
suggestions: [
{
title: 'GitHub issues',
link: 'https://github.com/badges/not-a-real-project/issues',
example: {
pattern: '/github/issues/:user/:repo',
namedParams: { user: 'badges', repo: 'not-a-real-project' },
queryParams: {},
},
},
{
title: 'GitHub forks',
link: 'https://github.com/badges/not-a-real-project/network',
example: {
pattern: '/github/forks/:user/:repo',
namedParams: { user: 'badges', repo: 'not-a-real-project' },
queryParams: {},
},
},
{
title: 'GitHub stars',
link: 'https://github.com/badges/not-a-real-project/stargazers',
example: {
pattern: '/github/stars/:user/:repo',
namedParams: { user: 'badges', repo: 'not-a-real-project' },
queryParams: {},
},
},
{
title: 'GitHub license',
link: 'https://github.com/badges/not-a-real-project',
example: {
pattern: '/github/license/:user/:repo',
namedParams: { user: 'badges', repo: 'not-a-real-project' },
queryParams: {},
},
},
{
title: 'Twitter',
link:
'https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fbadges%2Fnot-a-real-project',
example: {
pattern: '/twitter/url/:protocol(https|http)/:hostAndPath+',
namedParams: {
protocol: 'https',
hostAndPath: 'github.com/badges/not-a-real-project',
},
queryParams: {},
},
preview: {
style: 'social',
},
},
],
})
})
})
})