Files
shields/services/gem/gem-rank.tester.js
Paul Melnikow 226fa67a02 Create shortcut for BaseService-related imports (#2809)
Continue to implement #2698:

- Add `core/base-service/index.js` (but hold off on moving the things it imports)
- Add shortcuts in `services/index.js` for Base*Service, errors, and deprecatedService. This file will be streamlined later to avoid cluttering it with rarely used bits.
- Apply consistent ordering of imports and use of `module.exports` in testers.
- Remove some renaming of imports.
- Remove obsolete tests here and there.
2019-01-21 15:41:24 -05:00

47 lines
1.1 KiB
JavaScript

'use strict'
const Joi = require('joi')
const isOrdinalNumber = Joi.string().regex(/^[1-9][0-9]+(ᵗʰ|ˢᵗ|ⁿᵈ|ʳᵈ)$/)
const isOrdinalNumberDaily = Joi.string().regex(
/^[1-9][0-9]*(ᵗʰ|ˢᵗ|ⁿᵈ|ʳᵈ) daily$/
)
const t = (module.exports = require('..').createServiceTester())
t.create('total rank (valid)')
.get('/rt/rspec-puppet-facts.json')
.expectJSONTypes(
Joi.object().keys({
name: 'rank',
value: isOrdinalNumber,
})
)
t.create('daily rank (valid)')
.get('/rd/rails.json')
.expectJSONTypes(
Joi.object().keys({
name: 'rank',
value: isOrdinalNumberDaily,
})
)
t.create('rank (not found)')
.get('/rt/not-a-package.json')
.expectJSON({ name: 'rank', value: 'not found' })
t.create('rank is null')
.get('/rd/rails.json')
.intercept(nock =>
nock('http://bestgems.org')
.get('/api/v1/gems/rails/daily_ranking.json')
.reply(200, [
{
date: '2019-01-06',
daily_ranking: null,
},
])
)
.expectJSON({ name: 'rank', value: 'invalid rank' })