-
Notifications
You must be signed in to change notification settings - Fork 27
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
Showing
5 changed files
with
175 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@commercetools-frontend/constants': patch | ||
--- | ||
|
||
Refine some regex |
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,138 @@ | ||
import { | ||
PROJECT_KEY_REGEX, | ||
ENTRY_POINT_URI_PATH_REGEX, | ||
PERMISSION_GROUP_NAME_REGEX, | ||
} from './constants'; | ||
|
||
function generateRandomString(length: number) { | ||
return Array.from({ length: length + 1 }).join('x'); | ||
} | ||
|
||
describe.each` | ||
projectKey | isValid | ||
${'hello'} | ${true} | ||
${'i-am-a-valid-project-key'} | ${true} | ||
${'-invalid'} | ${false} | ||
${'_invalid'} | ${false} | ||
${'x'} | ${false} | ||
${'xy'} | ${true} | ||
${generateRandomString(36)} | ${true} | ||
${generateRandomString(37)} | ${false} | ||
${'__'} | ${false} | ||
${'--'} | ${false} | ||
${'..'} | ${false} | ||
${'@@'} | ${false} | ||
${'??'} | ${false} | ||
${'&&'} | ${false} | ||
${'##'} | ${false} | ||
${'invalid-'} | ${false} | ||
${'invalid_'} | ${false} | ||
${'not valid'} | ${false} | ||
${'this should not be valid'} | ${false} | ||
${'this--is-valid'} | ${true} | ||
${'this__is-valid'} | ${true} | ||
${'this-_is-valid'} | ${true} | ||
${'this_-is-valid'} | ${true} | ||
${'this---is-not-valid'} | ${false} | ||
${'this___is-not-valid'} | ${false} | ||
${'this-_-is-not-valid'} | ${false} | ||
${'This-Is-Not-VALID'} | ${false} | ||
`( | ||
'Validating project key "$projectKey"', | ||
({ projectKey, isValid }: { projectKey: string; isValid: boolean }) => { | ||
it(`should validate the key as ${isValid}`, () => { | ||
const matched = projectKey.match(PROJECT_KEY_REGEX); | ||
expect(Boolean(matched)).toBe(isValid); | ||
}); | ||
} | ||
); | ||
|
||
describe.each` | ||
entryPointUriPath | isValid | ||
${'hello'} | ${true} | ||
${'i-am-a-valid-entry-point'} | ${true} | ||
${'-invalid'} | ${false} | ||
${'_invalid'} | ${false} | ||
${'x'} | ${false} | ||
${'xy'} | ${true} | ||
${generateRandomString(64)} | ${true} | ||
${generateRandomString(65)} | ${false} | ||
${'__'} | ${false} | ||
${'--'} | ${false} | ||
${'..'} | ${false} | ||
${'@@'} | ${false} | ||
${'??'} | ${false} | ||
${'&&'} | ${false} | ||
${'##'} | ${false} | ||
${'invalid-'} | ${false} | ||
${'invalid_'} | ${false} | ||
${'not valid'} | ${false} | ||
${'this should not be valid'} | ${false} | ||
${'this--is-not-valid'} | ${false} | ||
${'this__is-not-valid'} | ${false} | ||
${'this-_is-not-valid'} | ${false} | ||
${'this_-is-not-valid'} | ${false} | ||
${'this---is-not-valid'} | ${false} | ||
${'this___is-not-valid'} | ${false} | ||
${'this-_-is-not-valid'} | ${false} | ||
${'This-Is-Not-VALID'} | ${false} | ||
`( | ||
'Validating entry point uri path "$entryPointUriPath"', | ||
({ | ||
entryPointUriPath, | ||
isValid, | ||
}: { | ||
entryPointUriPath: string; | ||
isValid: boolean; | ||
}) => { | ||
it(`should validate the key as ${isValid}`, () => { | ||
const matched = entryPointUriPath.match(ENTRY_POINT_URI_PATH_REGEX); | ||
expect(Boolean(matched)).toBe(isValid); | ||
}); | ||
} | ||
); | ||
|
||
describe.each` | ||
permissionGroup | isValid | ||
${'hello'} | ${true} | ||
${'i-am-a-valid-entry-point'} | ${true} | ||
${'-invalid'} | ${false} | ||
${'_valid'} | ${true} | ||
${'x'} | ${false} | ||
${'xy'} | ${true} | ||
${generateRandomString(64)} | ${true} | ||
${generateRandomString(65)} | ${false} | ||
${'__'} | ${true} | ||
${'--'} | ${false} | ||
${'..'} | ${false} | ||
${'@@'} | ${false} | ||
${'??'} | ${false} | ||
${'&&'} | ${false} | ||
${'##'} | ${false} | ||
${'invalid-'} | ${false} | ||
${'valid_'} | ${true} | ||
${'not valid'} | ${false} | ||
${'this should not be valid'} | ${false} | ||
${'this--is-not-valid'} | ${false} | ||
${'this__is-not-valid'} | ${false} | ||
${'this-_is-not-valid'} | ${false} | ||
${'this_-is-not-valid'} | ${false} | ||
${'this---is-not-valid'} | ${false} | ||
${'this___is-not-valid'} | ${false} | ||
${'this-_-is-not-valid'} | ${false} | ||
${'This-Is-Not-VALID'} | ${false} | ||
`( | ||
'Validating permission group name "$permissionGroup"', | ||
({ | ||
permissionGroup, | ||
isValid, | ||
}: { | ||
permissionGroup: string; | ||
isValid: boolean; | ||
}) => { | ||
it(`should validate the key as ${isValid}`, () => { | ||
const matched = permissionGroup.match(PERMISSION_GROUP_NAME_REGEX); | ||
expect(Boolean(matched)).toBe(isValid); | ||
}); | ||
} | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.