-
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.
* adding test for Uri * fix name
- Loading branch information
Showing
5 changed files
with
61 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
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,17 @@ | ||
### isUri | ||
|
||
Check if '/_uris/' is in the uri | ||
|
||
#### Params | ||
|
||
* `uri` _string_ | ||
|
||
**Returns** _boolean_ | ||
|
||
#### Example | ||
|
||
```js | ||
isUri('nymag.com/_uris/someuriid') | ||
//=> true | ||
|
||
``` |
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,14 @@ | ||
'use strict'; | ||
|
||
const isUriStringCheck = require('../strCheck'); | ||
|
||
/** | ||
* First test if argument is a String. If true, test if '/_uris/' is in the string. | ||
* Otherwise, throw an error. | ||
* @param {string} uri | ||
* @return {Boolean} | ||
*/ | ||
module.exports = function (uri) { | ||
isUriStringCheck.strCheck(uri); | ||
return uri.toLowerCase().indexOf('/_uris/') > -1; | ||
}; |
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,28 @@ | ||
'use strict'; | ||
|
||
const name = __filename.split('/').pop().split('.').shift(), | ||
fn = require('./' + name), | ||
expect = require('chai').expect; | ||
|
||
describe('isUri', () => { | ||
it('returns true if uri reference', () => { | ||
expect(fn('domain.com/_uris/foo')).to.equal(true); | ||
}); | ||
|
||
it('returns true if uri instance reference', () => { | ||
expect(fn('nymag.com/scienceofus/_uris/foobarbaz@published')).to.equal(true); | ||
}); | ||
|
||
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); | ||
}); | ||
|
||
it('returns false if non-uri reference', () => { | ||
expect(fn('domain.com/_users/foo')).to.equal(false); | ||
expect(fn('domain.com/_components/foo')).to.equal(false); | ||
}); | ||
}); |