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

Update [Jira] tests to include color validation #2565

Merged
merged 4 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
126 changes: 109 additions & 17 deletions services/jira/jira-issue.tester.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict'

const t = (module.exports = require('../create-service-tester')())
const jiraTestHelpers = require('./jira-test-helpers')
const { colorScheme } = require('../test-helpers')
const { mockJiraCreds, restore, user, pass } = require('./jira-test-helpers')

t.create('live: unknown issue')
.get('/https/issues.apache.org/jira/notArealIssue-000.json')
Expand All @@ -11,8 +12,8 @@ t.create('live: known issue')
.get('/https/issues.apache.org/jira/kafka-2896.json')
.expectJSON({ name: 'kafka-2896', value: 'Resolved' })

t.create('http endpoint')
.get('/http/issues.apache.org/jira/foo-123.json')
t.create('no status color')
.get('/http/issues.apache.org/jira/foo-123.json?style=_shields_test')
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2/issue')
.get(`/${encodeURIComponent('foo-123')}`)
Expand All @@ -24,64 +25,155 @@ t.create('http endpoint')
},
})
)
.expectJSON({ name: 'foo-123', value: 'pending' })
.expectJSON({
name: 'foo-123',
value: 'pending',
colorB: colorScheme.lightgrey,
})

t.create('endpoint with port and path')
.get('/https/issues.apache.org:8000/jira/bar-345.json')
t.create('green status color')
.get('/https/issues.apache.org:8000/jira/bar-345.json?style=_shields_test')
.intercept(nock =>
nock('https://issues.apache.org:8000/jira/rest/api/2/issue')
.get(`/${encodeURIComponent('bar-345')}`)
.reply(200, {
fields: {
status: {
name: 'done',
statusCategory: {
colorName: 'green',
},
},
},
})
)
.expectJSON({ name: 'bar-345', value: 'done' })
.expectJSON({
name: 'bar-345',
value: 'done',
colorB: colorScheme.green,
})

t.create('endpoint with port and no path')
.get('/https/issues.apache.org:8080/abc-123.json')
t.create('medium-gray status color')
.get('/https/issues.apache.org:8080/abc-123.json?style=_shields_test')
.intercept(nock =>
nock('https://issues.apache.org:8080/rest/api/2/issue')
.get(`/${encodeURIComponent('abc-123')}`)
.reply(200, {
fields: {
status: {
name: 'under review',
statusCategory: {
colorName: 'medium-gray',
},
},
},
})
)
.expectJSON({ name: 'abc-123', value: 'under review' })
.expectJSON({
name: 'abc-123',
value: 'under review',
colorB: colorScheme.lightgrey,
})

t.create('endpoint with no port nor path')
.get('/https/issues.apache.org/test-001.json')
t.create('yellow status color')
.get('/https/issues.apache.org/test-001.json?style=_shields_test')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('test-001')}`)
.reply(200, {
fields: {
status: {
name: 'in progress',
statusCategory: {
colorName: 'yellow',
},
},
},
})
)
.expectJSON({ name: 'test-001', value: 'in progress' })
.expectJSON({
name: 'test-001',
value: 'in progress',
colorB: colorScheme.yellow,
})

t.create('brown status color')
.get('/https/issues.apache.org/zzz-789.json?style=_shields_test')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('zzz-789')}`)
.reply(200, {
fields: {
status: {
name: 'muddy',
statusCategory: {
colorName: 'brown',
},
},
},
})
)
.expectJSON({
name: 'zzz-789',
value: 'muddy',
colorB: colorScheme.orange,
})

t.create('warm-red status color')
.get('/https/issues.apache.org/fire-321.json?style=_shields_test')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('fire-321')}`)
.reply(200, {
fields: {
status: {
name: 'heating up',
statusCategory: {
colorName: 'warm-red',
},
},
},
})
)
.expectJSON({
name: 'fire-321',
value: 'heating up',
colorB: colorScheme.red,
})

t.create('blue-gray status color')
.get('/https/issues.apache.org/sky-775.json?style=_shields_test')
.intercept(nock =>
nock('https://issues.apache.org/rest/api/2/issue')
.get(`/${encodeURIComponent('sky-775')}`)
.reply(200, {
fields: {
status: {
name: 'cloudy',
statusCategory: {
colorName: 'blue-gray',
},
},
},
})
)
.expectJSON({
name: 'sky-775',
value: 'cloudy',
colorB: colorScheme.blue,
})

t.create('with auth')
.before(jiraTestHelpers.mockJiraCreds)
.before(mockJiraCreds)
.get('/https/myprivatejira.com/secure-234.json')
.intercept(nock =>
nock('https://myprivatejira.com/rest/api/2/issue')
.get(`/${encodeURIComponent('secure-234')}`)
// This ensures that the expected credentials from serverSecrets are actually being sent with the HTTP request.
// Without this the request wouldn't match and the test would fail.
.basicAuth({
user: jiraTestHelpers.user,
pass: jiraTestHelpers.pass,
user,
pass,
})
.reply(200, {
fields: {
Expand All @@ -91,5 +183,5 @@ t.create('with auth')
},
})
)
.finally(jiraTestHelpers.restore)
.finally(restore)
.expectJSON({ name: 'secure-234', value: 'in progress' })
43 changes: 30 additions & 13 deletions services/jira/jira-sprint.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const Joi = require('joi')
const t = (module.exports = require('../create-service-tester')())
const { isIntegerPercentage } = require('../test-validators')
const jiraTestHelpers = require('./jira-test-helpers')
const { colorScheme } = require('../test-helpers')
const { mockJiraCreds, restore, user, pass } = require('./jira-test-helpers')

const sprintId = 8
const queryString = {
Expand All @@ -26,7 +27,7 @@ t.create('live: known sprint')
)

t.create('100% completion')
.get(`/http/issues.apache.org/jira/${sprintId}.json`)
.get(`/http/issues.apache.org/jira/${sprintId}.json?style=_shields_test`)
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2')
.get('/search')
Expand All @@ -51,10 +52,14 @@ t.create('100% completion')
],
})
)
.expectJSON({ name: 'completion', value: '100%' })
.expectJSON({
name: 'completion',
value: '100%',
colorB: colorScheme.brightgreen,
})

t.create('0% completion')
.get(`/http/issues.apache.org/jira/${sprintId}.json`)
.get(`/http/issues.apache.org/jira/${sprintId}.json?style=_shields_test`)
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2')
.get('/search')
Expand All @@ -72,10 +77,14 @@ t.create('0% completion')
],
})
)
.expectJSON({ name: 'completion', value: '0%' })
.expectJSON({
name: 'completion',
value: '0%',
colorB: colorScheme.red,
})

t.create('no issues in sprint')
.get(`/http/issues.apache.org/jira/${sprintId}.json`)
.get(`/http/issues.apache.org/jira/${sprintId}.json?style=_shields_test`)
.intercept(nock =>
nock('http://issues.apache.org/jira/rest/api/2')
.get('/search')
Expand All @@ -85,10 +94,14 @@ t.create('no issues in sprint')
issues: [],
})
)
.expectJSON({ name: 'completion', value: '0%' })
.expectJSON({
name: 'completion',
value: '0%',
colorB: colorScheme.red,
})

t.create('issue with null resolution value')
.get(`/https/jira.spring.io:8080/${sprintId}.json`)
.get(`/https/jira.spring.io:8080/${sprintId}.json?style=_shields_test`)
.intercept(nock =>
nock('https://jira.spring.io:8080/rest/api/2')
.get('/search')
Expand All @@ -111,10 +124,14 @@ t.create('issue with null resolution value')
],
})
)
.expectJSON({ name: 'completion', value: '50%' })
.expectJSON({
name: 'completion',
value: '50%',
colorB: colorScheme.orange,
})

t.create('with auth')
.before(jiraTestHelpers.mockJiraCreds)
.before(mockJiraCreds)
.get(`/https/myprivatejira/jira/${sprintId}.json`)
.intercept(nock =>
nock('https://myprivatejira/jira/rest/api/2')
Expand All @@ -123,8 +140,8 @@ t.create('with auth')
// This ensures that the expected credentials from serverSecrets are actually being sent with the HTTP request.
// Without this the request wouldn't match and the test would fail.
.basicAuth({
user: jiraTestHelpers.user,
pass: jiraTestHelpers.pass,
user,
pass,
})
.reply(200, {
total: 2,
Expand All @@ -146,5 +163,5 @@ t.create('with auth')
],
})
)
.finally(jiraTestHelpers.restore)
.finally(restore)
.expectJSON({ name: 'completion', value: '50%' })