Skip to content

Commit

Permalink
Merge branch 'master' into logo-test-page
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow authored Feb 8, 2019
2 parents cf6e3f5 + c46d2f9 commit 56f1d0a
Show file tree
Hide file tree
Showing 15 changed files with 514 additions and 373 deletions.
23 changes: 12 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
"babel-eslint": "^10.0.0",
"babel-plugin-inline-react-svg": "^1.0.1",
"babel-plugin-istanbul": "^5.1.0",
"babel-preset-gatsby": "^0.1.6",
"babel-preset-gatsby": "^0.1.7",
"caller": "^1.0.1",
"chai": "^4.1.2",
"chai-datetime": "^1.5.0",
Expand Down
1 change: 1 addition & 0 deletions services/chocolatey/chocolatey.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = createServiceFamily({
defaultLabel: 'chocolatey',
serviceBaseUrl: 'chocolatey',
apiBaseUrl: 'https://www.chocolatey.org/api/v2',
odataFormat: 'json',
title: 'Chocolatey',
examplePackageName: 'git',
exampleVersion: '2.19.2',
Expand Down
95 changes: 0 additions & 95 deletions services/chocolatey/chocolatey.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ const {
isVPlusDottedVersionNClauses,
isVPlusDottedVersionNClausesWithOptionalSuffix,
} = require('../test-validators')
const {
nuGetV2VersionJsonWithDash,
nuGetV2VersionJsonFirstCharZero,
nuGetV2VersionJsonFirstCharNotZero,
} = require('../nuget-fixtures')
const { ServiceTester } = require('../tester')

const t = (module.exports = new ServiceTester({
Expand Down Expand Up @@ -44,51 +39,6 @@ t.create('version (valid)')
})
)

t.create('version (mocked, yellow badge)')
.get('/v/scriptcs.json?style=_shields_test')
.intercept(nock =>
nock('https://www.chocolatey.org')
.get(
'/api/v2/Packages()?%24filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true'
)
.reply(200, nuGetV2VersionJsonWithDash)
)
.expectJSON({
name: 'chocolatey',
value: 'v1.2-beta',
color: 'yellow',
})

t.create('version (mocked, orange badge)')
.get('/v/scriptcs.json?style=_shields_test')
.intercept(nock =>
nock('https://www.chocolatey.org')
.get(
'/api/v2/Packages()?%24filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true'
)
.reply(200, nuGetV2VersionJsonFirstCharZero)
)
.expectJSON({
name: 'chocolatey',
value: 'v0.35',
color: 'orange',
})

t.create('version (mocked, blue badge)')
.get('/v/scriptcs.json?style=_shields_test')
.intercept(nock =>
nock('https://www.chocolatey.org')
.get(
'/api/v2/Packages()?%24filter=Id%20eq%20%27scriptcs%27%20and%20IsLatestVersion%20eq%20true'
)
.reply(200, nuGetV2VersionJsonFirstCharNotZero)
)
.expectJSON({
name: 'chocolatey',
value: 'v1.2.7',
color: 'blue',
})

t.create('version (not found)')
.get('/v/not-a-real-package.json')
.expectJSON({ name: 'chocolatey', value: 'not found' })
Expand All @@ -104,51 +54,6 @@ t.create('version (pre) (valid)')
})
)

t.create('version (pre) (mocked, yellow badge)')
.get('/vpre/scriptcs.json?style=_shields_test')
.intercept(nock =>
nock('https://www.chocolatey.org')
.get(
'/api/v2/Packages()?%24filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true'
)
.reply(200, nuGetV2VersionJsonWithDash)
)
.expectJSON({
name: 'chocolatey',
value: 'v1.2-beta',
color: 'yellow',
})

t.create('version (pre) (mocked, orange badge)')
.get('/vpre/scriptcs.json?style=_shields_test')
.intercept(nock =>
nock('https://www.chocolatey.org')
.get(
'/api/v2/Packages()?%24filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true'
)
.reply(200, nuGetV2VersionJsonFirstCharZero)
)
.expectJSON({
name: 'chocolatey',
value: 'v0.35',
color: 'orange',
})

t.create('version (pre) (mocked, blue badge)')
.get('/vpre/scriptcs.json?style=_shields_test')
.intercept(nock =>
nock('https://www.chocolatey.org')
.get(
'/api/v2/Packages()?%24filter=Id%20eq%20%27scriptcs%27%20and%20IsAbsoluteLatestVersion%20eq%20true'
)
.reply(200, nuGetV2VersionJsonFirstCharNotZero)
)
.expectJSON({
name: 'chocolatey',
value: 'v1.2.7',
color: 'blue',
})

t.create('version (pre) (not found)')
.get('/vpre/not-a-real-package.json')
.expectJSON({ name: 'chocolatey', value: 'not found' })
105 changes: 105 additions & 0 deletions services/nodeping/nodeping-status.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
'use strict'

const { BaseJsonService } = require('..')
const Joi = require('joi')

const rowSchema = Joi.object().keys({ su: Joi.boolean() })

const schema = Joi.array()
.items(rowSchema)
.min(1)

/*
* this is the checkUuid for the NodePing.com (as used on the [example page](https://nodeping.com/reporting.html#results))
*/
const sampleCheckUuid = 'jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei'

class NodePingStatus extends BaseJsonService {
static get category() {
return 'monitoring'
}

static get defaultBadgeData() {
return {
label: 'Status',
}
}

static get route() {
return {
base: 'nodeping/status',
pattern: ':checkUuid',
queryParams: ['up_message', 'down_message', 'up_color', 'down_color'],
}
}

static get examples() {
return [
{
title: 'NodePing status',
namedParams: {
checkUuid: sampleCheckUuid,
},
staticPreview: this.render({ status: true }),
},
{
title: 'NodePing status (customized)',
namedParams: {
checkUuid: sampleCheckUuid,
},
queryParams: {
up_message: 'Online',
up_color: 'blue',
down_message: 'Offline',
down_color: 'lightgrey',
},
staticPreview: this.render({
status: true,
upMessage: 'Online',
upColor: 'blue',
}),
},
]
}

async fetch({ checkUuid }) {
const rows = await this._requestJson({
schema,
url: `https://nodeping.com/reports/results/${checkUuid}/1`,
options: {
qs: { format: 'json' },
headers: {
'cache-control': 'no-cache',
},
},
})
return { status: rows[0].su }
}

async handle(
{ checkUuid },
{
up_message: upMessage,
down_message: downMessage,
up_color: upColor,
down_color: downColor,
}
) {
const { status } = await this.fetch({ checkUuid })
return this.constructor.render({
status,
upMessage,
downMessage,
upColor,
downColor,
})
}

static render({ status, upMessage, downMessage, upColor, downColor }) {
return status
? { message: upMessage || 'up', color: upColor || 'brightgreen' }
: { message: downMessage || 'down', color: downColor || 'red' }
}
}

module.exports = NodePingStatus
75 changes: 75 additions & 0 deletions services/nodeping/nodeping-status.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict'

const Joi = require('joi')

const t = (module.exports = require('../tester').createServiceTester())

t.create('NodePing status - live').get(
'/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json'
)
Joi.object().keys({
name: 'Status',
value: Joi.equal('up', 'down').required(),
})

t.create('NodePing status - up (mock)')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
.get(
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json'
)
.reply(200, [{ su: true }])
)
.expectJSON({
name: 'Status',
value: 'up',
})

t.create('NodePing status - down (mock)')
.get('/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json')
.intercept(nock =>
nock('https://nodeping.com')
.get(
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json'
)
.reply(200, [{ su: false }])
)
.expectJSON({
name: 'Status',
value: 'down',
})

t.create('NodePing status - custom up color/message')
.get(
'/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json?style=_shields_test&up_color=blue&up_message=happy'
)
.intercept(nock =>
nock('https://nodeping.com')
.get(
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json'
)
.reply(200, [{ su: true }])
)
.expectJSON({
name: 'Status',
value: 'happy',
color: 'blue',
})

t.create('NodePing status - custom down color/message')
.get(
'/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei.json?style=_shields_test&down_color=yellow&down_message=sad'
)
.intercept(nock =>
nock('https://nodeping.com')
.get(
'/reports/results/jkiwn052-ntpp-4lbb-8d45-ihew6d9ucoei/1?format=json'
)
.reply(200, [{ su: false }])
)
.expectJSON({
name: 'Status',
value: 'sad',
color: 'yellow',
})
Loading

0 comments on commit 56f1d0a

Please sign in to comment.