-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: search params not handle single item array correctly
- Loading branch information
Showing
4 changed files
with
185 additions
and
3 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 @@ | ||
--- | ||
'@joyid/common': patch | ||
--- | ||
|
||
fix: search params not handle single item array correctly |
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,179 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { encodeSearch, decodeSearch } from './search-params' | ||
|
||
describe('search-params', () => { | ||
describe('array', () => { | ||
it('array', () => { | ||
const data = { | ||
a: [1, 2, 3], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single number', () => { | ||
const data = { | ||
a: [1], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single string', () => { | ||
const data = { | ||
a: ['1'], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single object', () => { | ||
const data = { | ||
a: [{ b: 1 }], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single object with array', () => { | ||
const data = { | ||
a: [{ b: [1, 2] }], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single object with object', () => { | ||
const data = { | ||
a: [{ b: { c: 1 } }], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single object with array of objects', () => { | ||
const data = { | ||
a: [{ b: [{ c: 1 }, { c: 2 }] }], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - single object with object of arrays', () => { | ||
const data = { | ||
a: [{ b: { c: [1, 2] } }], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - multiple types', () => { | ||
const data = { | ||
a: [1, '2', { c: 3 }], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('array - nested', () => { | ||
const data = { | ||
a: [1, [2, [3]]], | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
}) | ||
|
||
describe('object', () => { | ||
it('object - single number', () => { | ||
const data = { | ||
a: { b: 1 }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - single string', () => { | ||
const data = { | ||
a: { b: '1' }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - single object', () => { | ||
const data = { | ||
a: { b: { c: 1 } }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - single object with array', () => { | ||
const data = { | ||
a: { b: [1, 2] }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - single object with object', () => { | ||
const data = { | ||
a: { b: { c: 1 } }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - single object with array of objects', () => { | ||
const data = { | ||
a: { b: [{ c: 1 }, { c: 2 }] }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - single object with object of arrays', () => { | ||
const data = { | ||
a: { b: { c: [1, 2] } }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - multiple types', () => { | ||
const data = { | ||
a: { b: 1, c: '2', d: { e: 3 } }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
|
||
it('object - nested', () => { | ||
const data = { | ||
a: { b: 1, c: { d: 2, e: { f: 3 } } }, | ||
} | ||
|
||
const encoded = encodeSearch(data) | ||
expect(data).toStrictEqual(decodeSearch(encoded)) | ||
}) | ||
}) | ||
}) |
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