-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[badge/dynamic/json] User defined JSON source badge #820
Changes from 29 commits
7eed1ca
7765ce2
7058fc0
57639f7
bd02eac
9659051
e6813cc
ff7ce12
1895b5d
a792fe7
fe99975
ac1506f
339092e
1d83608
49260e4
476c6d8
c90ba38
a662287
3aa5abf
6444481
f162211
a3aa1e5
695be9d
0dd37d2
19e48ab
6841fa2
e27159f
c497f95
d841039
f396d7f
ea0619c
346dc25
9075290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const Joi = require('joi'); | ||
const ServiceTester = require('./runner/service-tester'); | ||
|
||
const t = new ServiceTester({ id: 'badge/dynamic/json', title: 'User Defined JSON Source Data' }); | ||
module.exports = t; | ||
|
||
t.create('Connection error') | ||
.get('.json?uri=https://github.com/badges/shields/raw/master/package.json&query=$.name&label=Package Name') | ||
.networkOff() | ||
.expectJSON({ name: 'Package Name', value: 'inaccessible' }); | ||
|
||
t.create('No URI specified') | ||
.get('.json?query=$.name&label=Package Name') | ||
.expectJSON({ name: 'Package Name', value: 'no uri specified' }); | ||
|
||
t.create('JSON from uri') | ||
.get('.json?uri=https://github.com/badges/shields/raw/master/package.json&query=$.name') | ||
.expectJSON({ name: 'custom badge', value: 'gh-badges'}); | ||
|
||
t.create('JSON from uri | caching with new query params') | ||
.get('.json?uri=https://github.com/badges/shields/raw/master/package.json&query=$.version') | ||
.expectJSONTypes(Joi.object().keys({ | ||
name: Joi.equal('custom badge'), | ||
value: Joi.string().regex(/^\d+(\.\d+)?(\.\d+)?$/) | ||
})); | ||
|
||
t.create('JSON from uri | with prefix & suffix & label') | ||
.get('.json?uri=https://github.com/badges/shields/raw/master/package.json&query=$.version&prefix=v&suffix= dev&label=Shields') | ||
.expectJSONTypes(Joi.object().keys({ | ||
name: Joi.equal('Shields'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know! |
||
value: Joi.string().regex(/^v\d+(\.\d+)?(\.\d+)?\sdev$/) | ||
})); | ||
|
||
t.create('JSON from uri | object doesnt exist') | ||
.get('.json?uri=https://github.com/badges/shields/raw/master/package.json&query=$.does_not_exist') | ||
.expectJSONTypes(Joi.object().keys({ | ||
name: Joi.equal('custom badge'), | ||
value: Joi.equal('') | ||
})); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since these are both literals, you can simplify this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, did not see that. |
||
|
||
t.create('JSON from uri | invalid uri') | ||
.get('.json?uri=https://github.com/badges/shields/raw/master/notafile.json&query=$.version') | ||
.expectJSONTypes(Joi.object().keys({ | ||
name: Joi.equal('custom badge'), | ||
value: Joi.equal('invalid resource') | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to start with the
var url = document.getElementById('imgUrlPrefix').textContent
line frommakeImage()
above. Otherwise it will try to serve fromshields.io
instead ofimg.shields.io
in production.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test this you can run
make website
. The dynamic badge won't work of course, though you should be able to confirm that it's generating URLs that begin withhttps://img.shields.io/
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah did not think about that, i updated it to match the static badge function.