mirror of
https://github.com/Kaelio/ktx.git
synced 2026-07-25 12:01:03 +02:00
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { InvalidArgumentError } from '@commander-js/extra-typings';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { parsePipelineArgument } from '../../src/commands/mongo-query-commands.js';
|
|
|
|
describe('parsePipelineArgument', () => {
|
|
it('parses a valid JSON array of pipeline-stage objects', () => {
|
|
expect(parsePipelineArgument('[{"$match":{"city":"NY"}},{"$limit":10}]')).toEqual([
|
|
{ $match: { city: 'NY' } },
|
|
{ $limit: 10 },
|
|
]);
|
|
});
|
|
|
|
it('parses an empty pipeline array', () => {
|
|
expect(parsePipelineArgument('[]')).toEqual([]);
|
|
});
|
|
|
|
it('throws InvalidArgumentError on invalid JSON', () => {
|
|
expect(() => parsePipelineArgument('{not json')).toThrow(InvalidArgumentError);
|
|
});
|
|
|
|
it('throws InvalidArgumentError when the value is not an array', () => {
|
|
expect(() => parsePipelineArgument('{}')).toThrow(InvalidArgumentError);
|
|
});
|
|
|
|
it('throws InvalidArgumentError when the array contains a non-object stage', () => {
|
|
expect(() => parsePipelineArgument('[{"$match":{}}, "not-a-stage"]')).toThrow(InvalidArgumentError);
|
|
});
|
|
|
|
it('throws InvalidArgumentError when the array contains a nested array stage', () => {
|
|
expect(() => parsePipelineArgument('[[1,2,3]]')).toThrow(InvalidArgumentError);
|
|
});
|
|
|
|
it('throws InvalidArgumentError when the array contains null', () => {
|
|
expect(() => parsePipelineArgument('[null]')).toThrow(InvalidArgumentError);
|
|
});
|
|
});
|