-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(uuid): expose genTestUuid procedure
- Loading branch information
1 parent
25b80fb
commit 2c17d2c
Showing
5 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
import { genTestUuid, isTestUuid } from './genTestUuid'; | ||
|
||
describe('genTestUuid', () => { | ||
it('should generate a uuid', () => { | ||
const uuid = genTestUuid(); | ||
expect(uuid).toBeTruthy(); | ||
}); | ||
it('should generate a uuid that is namespaced for testing by whodis', () => { | ||
const uuid = genTestUuid(); | ||
expect(uuid).toMatch(/^beef.*-.*-.*-.*-.*beef$/); | ||
expect(isTestUuid(uuid)).toEqual(true); | ||
}); | ||
it('should generate a uuid that is different every time', () => { | ||
const uuid1 = genTestUuid(); | ||
const uuid2 = genTestUuid(); | ||
expect(uuid1).not.toEqual(uuid2); | ||
}); | ||
}); |
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 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
/** | ||
* generates a random uuid namespaced for tests, pattern `beef****-****-****-****-********beef` | ||
* | ||
* usecase | ||
* - produces a uuid that can be clearly identified as one produced for tests | ||
*/ | ||
export const genTestUuid = (): string => { | ||
return ['beef', uuid().slice(4, -4), 'beef'].join(''); | ||
}; | ||
|
||
/** | ||
* decides whether a uuid is namespaced for tests | ||
*/ | ||
export const isTestUuid = (userUuid: string): boolean => | ||
/^beef.{4}-.{4}-.{4}-.{4}-.{8}beef$/.test(userUuid); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { given, when, then } from './givenWhenThen'; | ||
export { genTestUuid } from './genTestUuid'; | ||
|
||
// forward the getError method since it is almost always needed with tests | ||
export { getError } from '@ehmpathy/error-fns'; |