Skip to content

Commit

Permalink
build: fix lint errors and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Tomas Hernandez Lopez committed Jan 31, 2024
1 parent 7281ca0 commit 95ba2d3
Show file tree
Hide file tree
Showing 40 changed files with 159 additions and 173 deletions.
37 changes: 0 additions & 37 deletions packages/schematics old/README.md

This file was deleted.

96 changes: 0 additions & 96 deletions packages/schematics old/src/collection.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 32 additions & 6 deletions packages/schematics/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
# schematics
# devon4ts_node

This library was generated with [Nx](https://nx.dev).
[devonfw](https://www.devonfw.com/) is a platform which provides solutions to building business applications which combine best-in-class frameworks and libraries as well as industry proven practices and code conventions. devonfw is 100% Open Source (Apache License version 2.0) since the beginning of 2018.

## Building
devon4ts_node is the NodeJS stack of devonfw. It allows you to build business applications (backends) using NodeJS technology in standardized way based on established best-practices.

Run `nx build schematics` to build the library.
![License](https://img.shields.io/npm/l/@devon4ts_node/schematics)
![License](https://img.shields.io/npm/v/@devon4ts_node/schematics)
![License](https://img.shields.io/librariesio/release/npm/@devon4ts_node/schematics)
![License](https://img.shields.io/npm/dt/@devon4ts_node/schematics)

## Running unit tests
## devon4ts_node Schematics

Run `nx test schematics` to execute the unit tests via [Jest](https://jestjs.io).
This package contains the devon4ts_node schematics. Those schematics are responsible for generating code for devon4ts_node.

## Documentation

You can find all documentation in our [wiki](https://github.com/devonfw/devon4ts_node/wiki).

## Code of conduct

Visit [code of conduct document](https://github.com/devonfw/.github/blob/master/CODE_OF_CONDUCT.md).

## Contributing guide

Visit [contributing guide document](https://github.com/devonfw/.github/blob/master/CONTRIBUTING.asciidoc).

## Key Principles

Visit [key principles document](https://github.com/devonfw/.github/blob/master/key-principles.asciidoc).

## Samples

- [Employee example](https://github.com/devonfw-sample/devon4ts_node-samples/tree/develop/employee): simple backend example for a employee management application.
- [Components example](https://github.com/devonfw-sample/devon4ts_node/tree/develop/components-example): simple backend example which will show you the execution order of the devon4ts_node components.
- [GraphQL example](https://github.com/devonfw-sample/devon4ts_node/tree/develop/graphql): simple GraphQL example with starter configuration.
- [My Thai Star](https://github.com/devonfw/my-thai-star/tree/develop/node): realistic example about the management of a restaurant. This example has also a frontend and it is compatible with other devonfw stacks.
3 changes: 3 additions & 0 deletions packages/schematics/generators.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"$schema": "http://json-schema.org/schema",
"name": "@devon4ts_node/schematics",
"version": "5.0.1",
"generators": {
"controller": {
"factory": "./src/generators/controller/generator",
Expand Down
96 changes: 96 additions & 0 deletions packages/schematics/src/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
"extends": "@nestjs/schematics",
"schematics": {
"application": {
"description": "Create a devon4ts_node application.",
"factory": "./generators/devon4ts_node-application/devon4ts_node-application.factory#devon4ts_nodeApplication",
"schema": "./generators/devon4ts_node-application/schema.json"
},
"typeorm": {
"description": "Initialice typeorm into your current project in a correct way.",
"factory": "./generators/init-typeorm/init-typeorm.factory#initTypeorm",
"schema": "./generators/init-typeorm/schema.json"
},
"entity": {
"description": "Add a TypeOrm entity to your project",
"factory": "./generators/entity/entity.factory#main",
"schema": "./generators/entity/schema.json"
},
"convict": {
"description": "Initialize convict to manage the configuration into the project.",
"factory": "./generators/convict/convict.factory#initConvict",
"schema": "./generators/convict/schema.json"
},
"mailer": {
"description": "Add @devon4ts_node/mailer module to project.",
"factory": "./generators/mailer/mailer.factory#mailer",
"schema": "./generators/mailer/schema.json"
},
"swagger": {
"description": "Add swagger module to project.",
"factory": "./generators/swagger/swagger.factory#swagger",
"schema": "./generators/swagger/schema.json"
},
"auth-jwt": {
"description": "Add the auth JWT module to the project.",
"factory": "./generators/auth-jwt/auth.factory#authJWT",
"schema": "./generators/auth-jwt/schema.json"
},
"security": {
"description": "Add cors and helmet to your project.",
"factory": "./generators/security/security.factory#security",
"schema": "./generators/security/schema.json"
},
"repository": {
"factory": "./generators/repository/repository.factory#main",
"description": "Create a TypeORM custom repository.",
"schema": "./generators/repository/schema.json"
},
"controller": {
"factory": "./generators/controller/controller.factory#main",
"description": "Create a Nest controller.",
"schema": "./generators/controller/schema.json"
},
"module": {
"factory": "./generators/module/module.factory#main",
"description": "Create a Nest module.",
"schema": "./generators/module/schema.json"
},
"service": {
"factory": "./generators/service/service.factory#main",
"description": "Create a Nest service.",
"schema": "./generators/service/schema.json"
},
"filter": {
"factory": "./generators/filter/filter.factory#main",
"description": "Create a Nest filter.",
"schema": "./generators/filter/schema.json"
},
"guard": {
"factory": "./generators/guard/guard.factory#main",
"description": "Create a Nest guard.",
"schema": "./generators/guard/schema.json"
},
"interceptor": {
"factory": "./generators/interceptor/interceptor.factory#main",
"description": "Create a Nest interceptor.",
"schema": "./generators/interceptor/schema.json"
},
"middleware": {
"factory": "./generators/middleware/middleware.factory#main",
"description": "Create a Nest middleware.",
"schema": "./generators/middleware/schema.json"
},
"pipe": {
"factory": "./generators/pipe/pipe.factory#main",
"description": "Create a Nest pipe.",
"schema": "./generators/pipe/schema.json"
},
"resource": {
"factory": "./generators/resource/resource.factory#main",
"description": "Create a Nest resource.",
"schema": "./generators/resource/schema.json"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ describe('Auth Controller', () => {
};
const value = await controller.login(user, mockResponse);
expect(value).toBeUndefined();
expect(mockResponse.status).toBeCalledWith(200);
expect(sendMock.send).toBeCalledWith();
expect(mockResponse.setHeader).toBeCalledWith('Authorization', 'Bearer THISISNOTAJWTTOKEN');
expect(mockResponse.status).toHaveBeenCalledWith(200);
expect(sendMock.send).toHaveBeenCalledWith();
expect(mockResponse.setHeader).toHaveBeenCalledWith('Authorization', 'Bearer THISISNOTAJWTTOKEN');
});
it('should throw an error when the username or password are not correct', async () => {
await expect(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { compare } from 'bcrypt';
import { classToPlain, plainToClass } from 'class-transformer';
import { instanceToPlain, plainToClass } from 'class-transformer';
import { UserService } from '../../user/services/user.service';
import { User } from '../../user/model/entities/user.entity';
import { LoginDTO } from '../model/login.dto';
import { CreateUserDto } from '../../user/model/dto/create-user.dto';

@Injectable()
export class AuthService {
constructor(private readonly usersService: UserService, private readonly jwtService: JwtService) {}
constructor(
private readonly usersService: UserService,
private readonly jwtService: JwtService,
) {}

async validateUser(username: string, pass: string): Promise<User | undefined> {
const user = await this.usersService.findOne(username);
if (user && (await compare(pass, user.password!))) {
return classToPlain(user) as User;
return instanceToPlain(user) as User;
}
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Exclude } from 'class-transformer';
import { Column, Entity } from 'typeorm';

import { BaseEntity } from '../../../../../../init-typeorm/files/src/app/shared/model/entities/base.entity';
import { roles } from '../../../auth/model/roles.enum';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('UserService', () => {
username: 'user3',
password: 'user3',
};
await expect(service.registerUser(userToAdd)).rejects.toThrowError('User already exists');
await expect(service.registerUser(userToAdd)).rejects.toThrow('User already exists');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as _ from 'lodash';
import { FindOptionsWhere, FindOneOptions } from 'typeorm';
import { User } from '../../src/app/core/user/model/entities/user.entity';
import { User } from '../../core/user/model/entities/user.entity';

export class UserRepositoryMock {
users: Array<Partial<User>>;
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 @@ -2,7 +2,7 @@ import { addProjectConfiguration, formatFiles, generateFiles, Tree } from '@nx/d
import * as path from 'path';
import { AuthJwtGeneratorSchema } from './schema';

export async function authJwtGenerator(tree: Tree, options: AuthJwtGeneratorSchema) {
export async function authJwtGenerator(tree: Tree, options: AuthJwtGeneratorSchema): Promise<void> {
const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {
root: projectRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { controllerGenerator } from './generator';
import { ControllerGeneratorSchema } from './schema';

Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/src/generators/controller/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addProjectConfiguration, formatFiles, generateFiles, Tree } from '@nx/d
import * as path from 'path';
import { ControllerGeneratorSchema } from './schema';

export async function controllerGenerator(tree: Tree, options: ControllerGeneratorSchema) {
export async function controllerGenerator(tree: Tree, options: ControllerGeneratorSchema): Promise<void> {
const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {
root: projectRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { convictGenerator } from './generator';
import { ConvictGeneratorSchema } from './schema';

Expand Down
2 changes: 1 addition & 1 deletion packages/schematics/src/generators/convict/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addProjectConfiguration, formatFiles, generateFiles, Tree } from '@nx/d
import * as path from 'path';
import { ConvictGeneratorSchema } from './schema';

export async function convictGenerator(tree: Tree, options: ConvictGeneratorSchema) {
export async function convictGenerator(tree: Tree, options: ConvictGeneratorSchema): Promise<void> {
const projectRoot = `libs/${options.name}`;
addProjectConfiguration(tree, options.name, {
root: projectRoot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { entityGenerator } from './generator';
import { EntityGeneratorSchema } from './schema';

Expand Down
Loading

0 comments on commit 95ba2d3

Please sign in to comment.