diff --git a/src/domain/model/Operation.spec.ts b/src/domain/model/Operation.spec.ts index b2b8399..cf06bb7 100644 --- a/src/domain/model/Operation.spec.ts +++ b/src/domain/model/Operation.spec.ts @@ -27,6 +27,19 @@ describe(Operation, () => { }) }) + describe('create with valid arguments', () => { + const validUnusualCases = [ + { caseID: `with ':'`, path: '/foo/:id' }, + { caseID: `with '?' and '='`, path: '/foo?key=value' }, + ] + + validUnusualCases.forEach(({ caseID, path }) => { + test(`${caseID} doesn't throw error`, () => { + expect(() => Operation.create(HTTPVerb.GET, path)).not.toThrow() + }) + }) + }) + describe('create with invalid arguments throwing InvalidStateError', () => { test('when verb is a string not from the enum', () => { // @ts-ignore @@ -40,7 +53,6 @@ describe(Operation, () => { const cases = [ { id: 'with spaces', path: '/foo /bar' }, - { id: 'with invalid chars', path: '/foo?bar' }, { id: 'without leading forward-slash', path: 'foo/bar' }, { id: 'with trailling forward-slash', path: '/foo/bar/' }, ] diff --git a/src/domain/model/Operation.ts b/src/domain/model/Operation.ts index c5f63e6..59406ad 100644 --- a/src/domain/model/Operation.ts +++ b/src/domain/model/Operation.ts @@ -15,7 +15,7 @@ export class Operation { const validVerb = verbs.includes(verb) if (!validVerb) throw new InvalidStateError(`http verb must be one of: ${verbs.join(', ')}`) - const rgx = /^(\/[A-Za-z0-9\-_]+)+$/ + const rgx = /^(\/[A-Za-z0-9\-_:]+)+(\?[A-Za-z0-9\-_=&\[\]]+)?$/ const validPath = rgx.test(path) if (!validPath) throw new InvalidStateError('path must be of format /foo/baz/123, got ' + path)