-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure checking for duplicate params is extended to hash
- Loading branch information
1 parent
698c9ae
commit 9706e12
Showing
7 changed files
with
129 additions
and
6 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,32 @@ | ||
import { expect, test } from 'vitest' | ||
import { DuplicateParamsError } from '@/errors/duplicateParamsError' | ||
import { combineHash } from '@/services/combineHash' | ||
import { withParams } from '@/services/withParams' | ||
|
||
test('given 2 hash, returns new Hash joined together', () => { | ||
const aHash = withParams('/foo', {}) | ||
const bHash = withParams('/bar', {}) | ||
|
||
const response = combineHash(aHash, bHash) | ||
|
||
expect(response.value).toBe('/foo/bar') | ||
}) | ||
|
||
test('given 2 hash with params, returns new Hash joined together with params', () => { | ||
const aHash = withParams('/[foz]', { foz: String }) | ||
const bHash = withParams('/[?baz]', { baz: Number }) | ||
|
||
const response = combineHash(aHash, bHash) | ||
|
||
expect(response.value).toBe('/[foz]/[?baz]') | ||
expect(Object.keys(response.params)).toMatchObject(['foz', '?baz']) | ||
}) | ||
|
||
test('given 2 hash with params that include duplicates, throws DuplicateParamsError', () => { | ||
const aHash = withParams('/[foz]', { foz: String }) | ||
const bHash = withParams('/[foz]', { foz: String }) | ||
|
||
const action: () => void = () => combineHash(aHash, bHash) | ||
|
||
expect(action).toThrow(DuplicateParamsError) | ||
}) |
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,75 @@ | ||
import { expect, test } from 'vitest' | ||
import { createExternalRoute } from '@/services/createExternalRoute' | ||
import { DuplicateParamsError } from '@/errors/duplicateParamsError' | ||
import { withParams } from '@/services/withParams' | ||
|
||
test('given parent, path is combined', () => { | ||
const parent = createExternalRoute({ | ||
host: 'https://kitbag.dev', | ||
path: '/parent', | ||
}) | ||
|
||
const child = createExternalRoute({ | ||
parent: parent, | ||
path: withParams('/child/[id]', { id: Number }), | ||
}) | ||
|
||
expect(child.path).toMatchObject({ | ||
value: '/parent/child/[id]', | ||
params: { | ||
id: Number, | ||
}, | ||
}) | ||
}) | ||
|
||
test('given parent, query is combined', () => { | ||
const parent = createExternalRoute({ | ||
host: 'https://kitbag.dev', | ||
query: 'static=123', | ||
}) | ||
|
||
const child = createExternalRoute({ | ||
parent: parent, | ||
query: withParams('sort=[sort]', { sort: Boolean }), | ||
}) | ||
|
||
expect(child.query).toMatchObject({ | ||
value: 'static=123&sort=[sort]', | ||
params: { | ||
sort: Boolean, | ||
}, | ||
}) | ||
}) | ||
|
||
test('given parent and child without meta, meta matches parent', () => { | ||
const parent = createExternalRoute({ | ||
host: 'https://kitbag.dev', | ||
meta: { | ||
foo: 123, | ||
}, | ||
}) | ||
|
||
const child = createExternalRoute({ | ||
parent: parent, | ||
}) | ||
|
||
expect(child.meta).toMatchObject({ | ||
foo: 123, | ||
}) | ||
}) | ||
|
||
test.each([ | ||
['https://[foo].dev', '/[foo]', 'foo=[zoo]', '[bar]'], | ||
['https://[zoo].dev', '/[foo]', 'foo=[bar]', '[foo]'], | ||
['https://[zoo].dev', '/[bar]', 'foo=[foo]', '[foo]'], | ||
['https://[zoo].dev', '/[bar]', 'foo=[foo]', '[foo]'], | ||
])('given duplicate params across different parts of the route, throws DuplicateParamsError', (host, path, query, hash) => { | ||
const action: () => void = () => createExternalRoute({ | ||
host, | ||
path, | ||
query, | ||
hash, | ||
}) | ||
|
||
expect(action).toThrow(DuplicateParamsError) | ||
}) |
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
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