mirror of
https://github.com/hantsy/nestjs-rest-sample.git
synced 2025-12-08 20:36:27 +00:00
29 lines
668 B
TypeScript
29 lines
668 B
TypeScript
import * as mongoose from 'mongoose';
|
|
import { ParseObjectIdPipe } from './parse-object-id.pipe';
|
|
|
|
describe('ParseObjectIdPipe', () => {
|
|
let isObjectId;
|
|
|
|
beforeEach(() => {
|
|
isObjectId = new ParseObjectIdPipe();
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(isObjectId).toBeDefined();
|
|
});
|
|
|
|
it('if valid', () => {
|
|
const validId = new mongoose.Types.ObjectId().toHexString();
|
|
const result = isObjectId.transform(validId, {} as any);
|
|
expect(result).toEqual(validId);
|
|
});
|
|
|
|
it('if invalid', () => {
|
|
try {
|
|
const result = isObjectId.transform('anerror', {} as any);
|
|
} catch (e) {
|
|
expect(e).not.toBeNull();
|
|
}
|
|
});
|
|
});
|