Skip to content

Commit

Permalink
factor out shared regex
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s committed Dec 3, 2017
1 parent 71f3df6 commit 3611916
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions service-tests/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const { isMetric } = require('./helpers/validators.js');
const {
isMetric,
isMetricOpenIssues
} = require('./helpers/validators.js');

const t = new ServiceTester({ id: 'bitbucket', title: 'BitBucket badges' });
module.exports = t;
Expand Down Expand Up @@ -30,7 +33,7 @@ t.create('issues (valid)')
.get('/issues/atlassian/python-bitbucket.json')
.expectJSONTypes(Joi.object().keys({
name: 'issues',
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? open$/)
value: isMetricOpenIssues
}));

t.create('issues (invalid)')
Expand Down Expand Up @@ -65,7 +68,7 @@ t.create('pr-raw (connection error)')
.get('/pr/atlassian/python-bitbucket.json')
.expectJSONTypes(Joi.object().keys({
name: 'pull requests',
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? open$/)
value: isMetricOpenIssues
}));

t.create('pr (invalid)')
Expand Down
7 changes: 4 additions & 3 deletions service-tests/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Joi = require('joi');
const ServiceTester = require('./runner/service-tester');
const {
isMetric,
isMetricOpenIssues,
isMetricOverTimePeriod,
isFileSize,
isFormattedDate,
Expand Down Expand Up @@ -42,7 +43,7 @@ t.create('GitHub pull requests')
.get('/issues-pr/badges/shields.json')
.expectJSONTypes(Joi.object().keys({
name: 'pull requests',
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? open$/)
value: isMetricOpenIssues
}));

t.create('GitHub pull requests raw')
Expand Down Expand Up @@ -70,7 +71,7 @@ t.create('GitHub open issues')
.get('/issues/badges/shields.json')
.expectJSONTypes(Joi.object().keys({
name: 'issues',
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? open$/)
value: isMetricOpenIssues
}));

t.create('GitHub open issues raw')
Expand Down Expand Up @@ -102,7 +103,7 @@ t.create('GitHub open pull requests by label')
.get('/issues-pr/badges/shields/service-badge.json')
.expectJSONTypes(Joi.object().keys({
name: 'service-badge pull requests',
value: Joi.string().regex(/^[0-9]+[kMGTPEZY]? open$/)
value: isMetricOpenIssues
}));

t.create('GitHub open pull requests by label (raw)')
Expand Down
3 changes: 3 additions & 0 deletions service-tests/helpers/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const isStarRating = withRegex(/^(?=.{5}$)(\u2605{0,5}[\u00BC\u00BD\u00BE]?\u260
// Required to be > 0, beacuse accepting zero masks many problems.
const isMetric = withRegex(/^[1-9][0-9]*[kMGTPEZY]?$/);

const isMetricOpenIssues = withRegex(/^[0-9]+[kMGTPEZY]? open$/);

const isMetricOverTimePeriod = withRegex(/^[1-9][0-9]*[kMGTPEZY]?\/(year|month|4 weeks|week|day)$/);

const isPercentage = withRegex(/^[0-9]+%$/);
Expand All @@ -55,6 +57,7 @@ module.exports = {
isComposerVersion,
isStarRating,
isMetric,
isMetricOpenIssues,
isMetricOverTimePeriod,
isPercentage,
isFileSize,
Expand Down

0 comments on commit 3611916

Please sign in to comment.