Skip to content

Commit

Permalink
fix: remove console statements
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Tomas Hernandez Lopez committed Feb 26, 2024
1 parent d87a1b3 commit 81b7155
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/schematics/src/generators/application/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface ApplicationGeneratorSchema {
projectName: string;
name: string;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthServiceMock } from '../../../test/auth/auth.service.mock';
import { AuthServiceMock } from '../../../../../test/auth/auth.service.mock';
import { AuthService } from '../services/auth.service';
import { AuthController } from './auth.controller';
import { PassportModule } from '@nestjs/passport';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Exclude } from 'class-transformer';
import { Column, Entity } from 'typeorm';
import { BaseEntity } from '../../../../../../init-typeorm/files/src/app/shared/model/entities/base.entity';
import { BaseEntity } from '../../../../shared/model/entities/base.entity';
import { roles } from '../../../auth/model/roles.enum';

@Entity()
Expand Down
3 changes: 3 additions & 0 deletions packages/schematics/src/generators/auth-jwt/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe('auth-jwt generator', () => {
expect(fileContent).toMatch(/"devDependencies": {(.|\n)*"@types\/passport-jwt":/g);
expect(fileContent).toMatch(/"devDependencies": {(.|\n)*"@types\/bcrypt":/g);
expect(fileContent).toMatch(/"devDependencies": {(.|\n)*"@types\/lodash":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@nestjs\/jwt":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@nestjs\/typeorm":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"bcrypt":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"typeorm":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"passport":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"passport-jwt":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"lodash":/g);
Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/src/generators/auth-jwt/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function authJwtGenerator(tree: Tree, options: AuthJwtGeneratorSche
[packagesVersion['bcrypt'].name]: packagesVersion['bcrypt'].version,
[packagesVersion['nestjsTypeorm'].name]: packagesVersion['nestjsTypeorm'].version,
[packagesVersion['nestjsPassport'].name]: packagesVersion['nestjsPassport'].version,
[packagesVersion['nestjsSwagger'].name]: packagesVersion['nestjsSwagger'].version,
[packagesVersion['nestjsJwt'].name]: packagesVersion['nestjsJwt'].version,
[packagesVersion['lodash'].name]: packagesVersion['lodash'].version,
[packagesVersion['passport'].name]: packagesVersion['passport'].version,
[packagesVersion['passportJwt'].name]: packagesVersion['passportJwt'].version,
Expand Down
13 changes: 12 additions & 1 deletion packages/schematics/src/generators/convict/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@
"$id": "ConvictConfigSchematic",
"title": "Convict Configuration Schema",
"type": "object",
"properties": {}
"properties": {
"projectName": {
"type": "string",
"description": "",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "In which project would you like to add convict configuration?"
}
},
"required": ["projectName"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('entity generator', () => {
it('should add dependencies to package.json', async () => {
const fileContent = tree.read('package.json')?.toString('utf-8');
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"typeorm":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"mysql2":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@nestjs\/typeorm":/g);
});

Expand Down
1 change: 0 additions & 1 deletion packages/schematics/src/generators/entity/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export async function entityGenerator(tree: Tree, options: EntityGeneratorSchema
{
[packagesVersion['typeorm'].name]: packagesVersion['typeorm'].version,
[packagesVersion['nestjsTypeorm'].name]: packagesVersion['nestjsTypeorm'].version,
[packagesVersion['mysql2'].name]: packagesVersion['mysql2'].version,
},
{},
);
Expand Down
14 changes: 14 additions & 0 deletions packages/schematics/src/generators/mailer/configvalues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ export const mailerValuesFromConfig = `{
}`;

export const mailerConfigType = `{
mailOptions: {
host: string;
port: number;
secure: boolean;
tlsRejectUnauthorized: boolean;
};
emailFrom: string;
hbsOptions: {
templatesDir: string;
partialsDir: string;
};
}`;

export const mailerConfigFile = `{
mailOptions: {
host: {
doc: 'Mail server host URL',
Expand Down
61 changes: 51 additions & 10 deletions packages/schematics/src/generators/mailer/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import applicationGenerator from '../application/generator';
import { mailerGenerator } from './generator';
import { MailerGeneratorSchema } from './schema';
import convictGenerator from '../convict/generator';

describe('mailer generator', () => {
let tree: Tree;
Expand All @@ -15,25 +16,65 @@ describe('mailer generator', () => {
projectNameAndRootFormat: 'as-provided',
directory: 'apps/test',
});
await mailerGenerator(tree, options);
jest.clearAllMocks();
}, 60000);

it('should run successfully', async () => {
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
it('should add dependencies to package.json', async () => {
const fileContent = tree.read('package.json')?.toString('utf-8');
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"handlebars":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@devon4ts\/mailer":/g);

describe('mailer generator without convict', () => {
beforeAll(async () => {
await mailerGenerator(tree, options);
}, 60000);

it('should add dependencies to package.json', async () => {
const fileContent = tree.read('package.json')?.toString('utf-8');
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"handlebars":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@devon4ts\/mailer":/g);
});

it('should add MailerModule to core.module', async () => {
const fileContent = tree
.read(`./packages/schematics/apps/${options.projectName}/src/app/core/core.module.ts`)
?.toString('utf-8');

expect(fileContent).toContain('MailerModule');
});
});

it('should add MailerModule to core.module', async () => {
const fileContent = tree
.read(`./packages/schematics/apps/${options.projectName}/src/app/core/core.module.ts`)
?.toString('utf-8');
describe('mailer generator with convict', () => {
beforeAll(async () => {
await convictGenerator(tree, options);
await mailerGenerator(tree, options);
}, 60000);

expect(fileContent).toContain('MailerModule');
it('should add dependencies to package.json', async () => {
const fileContent = tree.read('package.json')?.toString('utf-8');
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"handlebars":/g);
expect(fileContent).toMatch(/"dependencies": {(.|\n)*"@devon4ts\/mailer":/g);
});

it('should add MailerModule to core.module', async () => {
const fileContent = tree
.read(`./packages/schematics/apps/${options.projectName}/src/app/core/core.module.ts`)
?.toString('utf-8');
expect(fileContent).toContain('MailerModule');
});

it('should add mailer configuration src/app/shared/app-config.ts', async () => {
const fileContent = tree
.read(`./packages/schematics/apps/${options.projectName}/src/app/shared/app-config.ts`)
?.toString('utf-8');
expect(fileContent).toContain('mailer');
});

it('should add mailer configuration src/config.ts', async () => {
const fileContent = tree
.read(`./packages/schematics/apps/${options.projectName}/src/config.ts`)
?.toString('utf-8');
expect(fileContent).toContain('mailer');
});
});
});
18 changes: 12 additions & 6 deletions packages/schematics/src/generators/mailer/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';
import { ASTFileBuilder } from '../../utils/ast-file-builder';
import { existsConvictConfig } from '../../utils/tree-utils';
import { packagesVersion } from '../packagesVersion';
import { defaultMailerValues, mailerConfigType, mailerValuesFromConfig } from './configvalues';
import { defaultMailerValues, mailerConfigType, mailerConfigFile, mailerValuesFromConfig } from './configvalues';
import { MailerGeneratorSchema } from './schema';

export async function mailerGenerator(tree: Tree, options: MailerGeneratorSchema): Promise<() => void> {
Expand Down Expand Up @@ -68,13 +68,19 @@ function addMailerToProject(tree: Tree, projectRoot: string): Tree {
}

addMailerToCoreModule(tree, true, projectRoot);
const typesFile = `${projectRoot}/config.ts`;

const typesFileContent = new ASTFileBuilder(tree.read(typesFile)!.toString('utf-8'))
.addPropertyToObjectLiteralParam('config', 0, 'mailer', mailerConfigType)
// Add properties to config type file
const configTypeFile = `${projectRoot}/app/shared/app-config.ts`;
const configTypeFileContent = new ASTFileBuilder(tree.read(configTypeFile)!.toString('utf-8'))
.addPropToInterface('AppConfig', 'mailer', mailerConfigType)
.build();
tree.write(configTypeFile, configTypeFileContent);

tree.write(typesFile, typesFileContent);

// Add properties to config file
const configFile = `${projectRoot}/config.ts`;
const configFileContent = new ASTFileBuilder(tree.read(configFile)!.toString('utf-8'))
.addPropertyToObjectLiteralParam('config', 0, 'mailer', mailerConfigFile)
.build();
tree.write(configFile, configFileContent);
return tree;
}
4 changes: 2 additions & 2 deletions packages/schematics/src/generators/swagger/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Swagger Schema",
"type": "object",
"properties": {
"project": {
"projectName": {
"type": "string",
"description": "Target application where Swagger config is going to be created.",
"$default": {
Expand All @@ -14,5 +14,5 @@
"x-prompt": "What application would you like to modify?"
}
},
"required": ["project"]
"required": ["projectName"]
}

0 comments on commit 81b7155

Please sign in to comment.