Skip to content

Commit

Permalink
refactor(Jira): change query param name
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright committed Sep 16, 2019
1 parent ad8e7d7 commit ad61827
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion services/jira/jira-issue-redirect.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = [
},
transformPath: ({ issueKey }) => `/jira/issue/${issueKey}`,
transformQueryParams: ({ protocol, hostAndPath }) => ({
hostUrl: `${protocol}://${hostAndPath}`,
baseUrl: `${protocol}://${hostAndPath}`,
}),
dateAdded: new Date('2019-09-14'),
}),
Expand Down
2 changes: 1 addition & 1 deletion services/jira/jira-issue-redirect.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ t.create('jira issue')
.expectStatus(301)
.expectHeader(
'Location',
`/jira/issue/kafka-2896.svg?hostUrl=${encodeURIComponent(
`/jira/issue/kafka-2896.svg?baseUrl=${encodeURIComponent(
'https://issues.apache.org/jira'
)}`
)
8 changes: 4 additions & 4 deletions services/jira/jira-issue.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { authConfig } = require('./jira-common')
const { BaseJsonService } = require('..')

const queryParamSchema = Joi.object({
hostUrl: optionalUrl.required(),
baseUrl: optionalUrl.required(),
}).required()

const schema = Joi.object({
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = class JiraIssue extends BaseJsonService {
issueKey: 'KAFKA-2896',
},
queryParams: {
hostUrl: 'https://issues.apache.org/jira',
baseUrl: 'https://issues.apache.org/jira',
},
staticPreview: this.render({
issueKey: 'KAFKA-2896',
Expand Down Expand Up @@ -81,11 +81,11 @@ module.exports = class JiraIssue extends BaseJsonService {
}
}

async handle({ issueKey }, { hostUrl }) {
async handle({ issueKey }, { baseUrl }) {
// Atlassian Documentation: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-api-2-issue-issueIdOrKey-get
const json = await this._requestJson({
schema,
url: `${hostUrl}/rest/api/2/issue/${encodeURIComponent(issueKey)}`,
url: `${baseUrl}/rest/api/2/issue/${encodeURIComponent(issueKey)}`,
options: { auth: this.authHelper.basicAuth },
errorMessages: { 404: 'issue not found' },
})
Expand Down
2 changes: 1 addition & 1 deletion services/jira/jira-issue.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('JiraIssue', function() {
{
issueKey: 'secure-234',
},
{ hostUrl: 'https://myprivatejira.test' }
{ baseUrl: 'https://myprivatejira.test' }
)
).to.deep.equal({
label: 'secure-234',
Expand Down
18 changes: 9 additions & 9 deletions services/jira/jira-issue.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
const t = (module.exports = require('../tester').createServiceTester())

t.create('unknown issue')
.get('/notArealIssue-000.json?hostUrl=https://issues.apache.org/jira')
.get('/notArealIssue-000.json?baseUrl=https://issues.apache.org/jira')
.expectBadge({ label: 'jira', message: 'issue not found' })

t.create('known issue')
.get('/kafka-2896.json?hostUrl=https://issues.apache.org/jira')
.get('/kafka-2896.json?baseUrl=https://issues.apache.org/jira')
.expectBadge({ label: 'kafka-2896', message: 'Resolved' })

t.create('no status color')
.get('/foo-123.json?hostUrl=http://issues.apache.org/jira')
.get('/foo-123.json?baseUrl=http://issues.apache.org/jira')
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2/issue')
.get(`/${encodeURIComponent('foo-123')}`)
Expand All @@ -30,7 +30,7 @@ t.create('no status color')
})

t.create('green status color')
.get('/bar-345.json?hostUrl=https://issues.apache.org:8000/jira')
.get('/bar-345.json?baseUrl=https://issues.apache.org:8000/jira')
.intercept(nock =>
nock('https://issues.apache.org:8000/jira/rest/api/2/issue')
.get(`/${encodeURIComponent('bar-345')}`)
Expand All @@ -52,7 +52,7 @@ t.create('green status color')
})

t.create('medium-gray status color')
.get('/abc-123.json?hostUrl=https://issues.apache.org:8080')
.get('/abc-123.json?baseUrl=https://issues.apache.org:8080')
.intercept(nock =>
nock('https://issues.apache.org:8080/rest/api/2/issue')
.get(`/${encodeURIComponent('abc-123')}`)
Expand All @@ -74,7 +74,7 @@ t.create('medium-gray status color')
})

t.create('yellow status color')
.get('/test-001.json?hostUrl=https://issues.apache.org')
.get('/test-001.json?baseUrl=https://issues.apache.org')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('test-001')}`)
Expand All @@ -96,7 +96,7 @@ t.create('yellow status color')
})

t.create('brown status color')
.get('/zzz-789.json?hostUrl=https://issues.apache.org')
.get('/zzz-789.json?baseUrl=https://issues.apache.org')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('zzz-789')}`)
Expand All @@ -118,7 +118,7 @@ t.create('brown status color')
})

t.create('warm-red status color')
.get('/fire-321.json?hostUrl=https://issues.apache.org')
.get('/fire-321.json?baseUrl=https://issues.apache.org')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('fire-321')}`)
Expand All @@ -140,7 +140,7 @@ t.create('warm-red status color')
})

t.create('blue-gray status color')
.get('/sky-775.json?hostUrl=https://issues.apache.org')
.get('/sky-775.json?baseUrl=https://issues.apache.org')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('sky-775')}`)
Expand Down
2 changes: 1 addition & 1 deletion services/jira/jira-sprint-redirect.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = [
},
transformPath: ({ sprintId }) => `/jira/sprint/${sprintId}`,
transformQueryParams: ({ protocol, hostAndPath }) => ({
hostUrl: `${protocol}://${hostAndPath}`,
baseUrl: `${protocol}://${hostAndPath}`,
}),
dateAdded: new Date('2019-09-14'),
}),
Expand Down
2 changes: 1 addition & 1 deletion services/jira/jira-sprint-redirect.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ t.create('jira sprint')
.expectStatus(301)
.expectHeader(
'Location',
`/jira/sprint/94.svg?hostUrl=${encodeURIComponent(
`/jira/sprint/94.svg?baseUrl=${encodeURIComponent(
'https://jira.spring.io'
)}`
)
8 changes: 4 additions & 4 deletions services/jira/jira-sprint.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { authConfig } = require('./jira-common')
const { BaseJsonService } = require('..')

const queryParamSchema = Joi.object({
hostUrl: optionalUrl.required(),
baseUrl: optionalUrl.required(),
}).required()

const schema = Joi.object({
Expand Down Expand Up @@ -57,7 +57,7 @@ module.exports = class JiraSprint extends BaseJsonService {
sprintId: '94',
},
queryParams: {
hostUrl: 'https://jira.spring.io',
baseUrl: 'https://jira.spring.io',
},
staticPreview: this.render({
numCompletedIssues: 27,
Expand Down Expand Up @@ -90,12 +90,12 @@ module.exports = class JiraSprint extends BaseJsonService {
}
}

async handle({ sprintId }, { hostUrl }) {
async handle({ sprintId }, { baseUrl }) {
// Atlassian Documentation: https://developer.atlassian.com/cloud/jira/platform/rest/v2/#api-group-Search
// There are other sprint-specific APIs but those require authentication. The search API
// allows us to get the needed data without being forced to authenticate.
const json = await this._requestJson({
url: `${hostUrl}/rest/api/2/search`,
url: `${baseUrl}/rest/api/2/search`,
schema,
options: {
qs: {
Expand Down
2 changes: 1 addition & 1 deletion services/jira/jira-sprint.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('JiraSprint', function() {
{
sprintId,
},
{ hostUrl: 'https://myprivatejira.test/jira' }
{ baseUrl: 'https://myprivatejira.test/jira' }
)
).to.deep.equal({
label: 'completion',
Expand Down
12 changes: 6 additions & 6 deletions services/jira/jira-sprint.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ const { isIntegerPercentage } = require('../test-validators')
const { sprintId, sprintQueryString } = require('./jira-test-helpers')

t.create('unknown sprint')
.get('/abc.json?hostUrl=https://jira.spring.io')
.get('/abc.json?baseUrl=https://jira.spring.io')
.expectBadge({ label: 'jira', message: 'sprint not found' })

t.create('known sprint')
.get('/94.json?hostUrl=https://jira.spring.io')
.get('/94.json?baseUrl=https://jira.spring.io')
.expectBadge({
label: 'completion',
message: isIntegerPercentage,
})

t.create('100% completion')
.get(`/${sprintId}.json?hostUrl=http://issues.apache.org/jira`)
.get(`/${sprintId}.json?baseUrl=http://issues.apache.org/jira`)
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2')
.get('/search')
Expand Down Expand Up @@ -48,7 +48,7 @@ t.create('100% completion')
})

t.create('0% completion')
.get(`/${sprintId}.json?hostUrl=http://issues.apache.org/jira`)
.get(`/${sprintId}.json?baseUrl=http://issues.apache.org/jira`)
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2')
.get('/search')
Expand All @@ -73,7 +73,7 @@ t.create('0% completion')
})

t.create('no issues in sprint')
.get(`/${sprintId}.json?hostUrl=http://issues.apache.org/jira`)
.get(`/${sprintId}.json?baseUrl=http://issues.apache.org/jira`)
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2')
.get('/search')
Expand All @@ -90,7 +90,7 @@ t.create('no issues in sprint')
})

t.create('issue with null resolution value')
.get(`/${sprintId}.json?hostUrl=https://jira.spring.io:8080`)
.get(`/${sprintId}.json?baseUrl=https://jira.spring.io:8080`)
.intercept(nock =>
nock('https://jira.spring.io:8080/rest/api/2')
.get('/search')
Expand Down

0 comments on commit ad61827

Please sign in to comment.