-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathparse.collection.array.pipe.spec.ts
More file actions
39 lines (32 loc) · 1.65 KB
/
parse.collection.array.pipe.spec.ts
File metadata and controls
39 lines (32 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { ArgumentMetadata, BadRequestException } from "@nestjs/common";
import { ParseCollectionArrayPipe } from "../../../common/src/pipes/parse.collection.array.pipe";
describe('ParseCollectionArrayPipe', () => {
let target: ParseCollectionArrayPipe;
beforeEach(() => {
target = new ParseCollectionArrayPipe();
});
describe('transform', () => {
describe('when validation passes', () => {
it('should return array of collection identifiers', async () => {
const validCollectionIdentifier = 'ABCDE-efb116';
expect(await target.transform(validCollectionIdentifier, {} as ArgumentMetadata)).toStrictEqual([validCollectionIdentifier]);
});
it('should return undefined for an empty string', async () => {
expect(await target.transform('', {} as ArgumentMetadata)).toBeUndefined();
});
it('should return undefined for undefined value', async () => {
expect(await target.transform(undefined, {} as ArgumentMetadata)).toBeUndefined();
});
});
describe('when validation fails', () => {
it('should throw BadRequestException', async () => {
const invalidCollectionIdentifier = 'ABCDE-efb116-02';
await expect(target.transform(invalidCollectionIdentifier, {} as ArgumentMetadata)).rejects.toThrow(BadRequestException);
});
it('should throw BadRequestException even if array contains an valid collection identifier', async () => {
const invalidCollectionIdentifiers = ['ABCDE-efb116-02', 'ABCDE-efb116'];
await expect(target.transform(invalidCollectionIdentifiers, {} as ArgumentMetadata)).rejects.toThrow(BadRequestException);
});
});
});
});