-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dfef0e
commit 56ab159
Showing
6 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,3 +57,5 @@ typings/ | |
# dotenv environment variables file | ||
.env | ||
|
||
# Webstorm | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
### isPublished | ||
|
||
Check if the uri ends with '@published' | ||
|
||
#### Params | ||
|
||
* `uri` _string_ | ||
|
||
**Returns** _boolean_ | ||
|
||
#### Example | ||
|
||
```js | ||
isPublished('nymag.com/press/_components/base/instances/foobarbaz@published') | ||
//=> true | ||
|
||
isPublished('nymag.com/press/_components/base/instances/foobarbaz') | ||
//=> false | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const isUriStringCheck = require('../strCheck'), | ||
validationRegex = /.+@published$/; | ||
|
||
/** | ||
* First test if argument is a String. If true, test if the string ends with '@published'. | ||
* Otherwise, throw an error. | ||
* @param {string} uri | ||
* @return {Boolean} | ||
*/ | ||
module.exports = function (uri) { | ||
isUriStringCheck.strCheck(uri); | ||
return validationRegex.test(uri); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const name = __filename.split('/').pop().split('.').shift(), | ||
fn = require('./' + name), | ||
expect = require('chai').expect; | ||
|
||
describe('isPublished', () => { | ||
it('returns true if the reference is published', () => { | ||
expect(fn('domain.com/_components/foo/instances/bar@published')).to.equal(true); | ||
}); | ||
|
||
it('returns false if the reference is not published', () => { | ||
expect(fn('domain.com/_components/foo/instances/bar')).to.equal(false); | ||
}); | ||
|
||
it('throws an error if the URI passed in is not a string', () => { | ||
const nonStringArgument = function () { | ||
return fn([0, 1, 2, 3]); | ||
}; | ||
|
||
expect(nonStringArgument).to.throw(Error); | ||
}); | ||
}); |