UNPKG

@mbc-cqrs-serverless/cli

Version:

a CLI to get started with MBC CQRS serverless framework

129 lines (128 loc) 5.89 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const testing_1 = require("@angular-devkit/schematics/testing"); const path = __importStar(require("path")); describe('Dto Factory', () => { const runner = new testing_1.SchematicTestRunner('.', path.join(__dirname, '../../collection.json')); it('should generate correct template', async () => { const options = { name: 'foo', }; const tree = await runner.runSchematic('dto', options); const files = tree.files; expect(files.find((filename) => filename === '/src/foo/dto/foo-attributes.dto.ts')).toBeDefined(); expect(files.find((filename) => filename === '/src/foo/dto/foo-command.dto.ts')).toBeDefined(); expect(files.find((filename) => filename === '/src/foo/dto/foo-create.dto.ts')).toBeDefined(); expect(files.find((filename) => filename === '/src/foo/dto/foo-search.dto.ts')).toBeDefined(); expect(files.find((filename) => filename === '/src/foo/dto/foo-update.dto.ts')).toBeDefined(); expect(tree.readContent('/src/foo/dto/foo-attributes.dto.ts')).toEqual("import { IsObject } from 'class-validator'\n" + '\n' + 'export class FooAttributes {\n' + ' @IsObject()\n' + ' value: object\n' + '}\n'); expect(tree.readContent('/src/foo/dto/foo-command.dto.ts')).toEqual("import { CommandDto } from '@mbc-cqrs-serverless/core'\n" + "import { Type } from 'class-transformer'\n" + "import { ValidateNested } from 'class-validator'\n" + '\n' + "import { FooAttributes } from './foo-attributes.dto'\n" + '\n' + 'export class FooCommandDto extends CommandDto {\n' + ' @Type(() => FooAttributes)\n' + ' @ValidateNested()\n' + ' attributes: FooAttributes\n' + '\n' + ' constructor(partial: Partial<FooCommandDto>) {\n' + ' super()\n' + ' Object.assign(this, partial)\n' + ' }\n' + '}\n'); expect(tree.readContent('/src/foo/dto/foo-create.dto.ts')).toEqual("import { Type } from 'class-transformer'\n" + "import { IsOptional, IsString, ValidateNested } from 'class-validator'\n" + '\n' + "import { FooAttributes } from './foo-attributes.dto'\n" + '\n' + 'export class FooCreateDto {\n' + ' @IsString()\n' + ' name: string\n' + '\n' + ' @Type(() => FooAttributes)\n' + ' @ValidateNested()\n' + ' @IsOptional()\n' + ' attributes?: FooAttributes\n' + '\n' + ' constructor(partial: Partial<FooCreateDto>) {\n' + ' Object.assign(this, partial)\n' + ' }\n' + '}\n'); expect(tree.readContent('/src/foo/dto/foo-search.dto.ts')).toEqual("import { SearchDto } from '@mbc-cqrs-serverless/core'\n" + 'export class FooSearchDto extends SearchDto {}\n'); expect(tree.readContent('/src/foo/dto/foo-update.dto.ts')).toEqual("import { PartialType } from '@nestjs/swagger'\n" + "import { Transform, Type } from 'class-transformer'\n" + 'import {\n' + ' IsBoolean,\n' + ' IsOptional,\n' + ' IsString,\n' + ' ValidateNested,\n' + "} from 'class-validator'\n" + '\n' + "import { FooAttributes } from './foo-attributes.dto'\n" + '\n' + 'export class FooUpdateAttributes extends PartialType(FooAttributes) {}\n' + '\n' + 'export class FooUpdateDto {\n' + ' @IsString()\n' + ' @IsOptional()\n' + ' name?: string\n' + '\n' + ' @IsBoolean()\n' + ' @Transform(({ value }) =>\n' + " value === 'true' ? true : value === 'false' ? false : value,\n" + ' )\n' + ' @IsOptional()\n' + ' isDeleted?: boolean\n' + '\n' + ' @Type(() => FooUpdateAttributes)\n' + ' @ValidateNested()\n' + ' @IsOptional()\n' + ' attributes?: FooUpdateAttributes\n' + '\n' + ' constructor(partial: Partial<FooUpdateDto>) {\n' + ' Object.assign(this, partial)\n' + ' }\n' + '}\n'); }); });