From 2cebfb350a864502d712236696738d495b722af7 Mon Sep 17 00:00:00 2001 From: zhumeisongsong Date: Mon, 18 Nov 2024 12:59:28 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20@users/presentation-d?= =?UTF-8?q?to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/users/presentation/README.md | 7 -- libs/users/presentation/dto/README.md | 7 ++ libs/users/presentation/dto/eslint.config.js | 3 + .../presentation/{ => dto}/jest.config.ts | 6 +- libs/users/presentation/dto/project.json | 9 +++ libs/users/presentation/dto/src/index.ts | 1 + .../src/lib/users-presentation-dto.spec.ts | 7 ++ .../dto/src/lib/users-presentation-dto.ts | 3 + .../presentation/{ => dto}/tsconfig.json | 2 +- .../presentation/{ => dto}/tsconfig.lib.json | 2 +- .../presentation/{ => dto}/tsconfig.spec.json | 2 +- libs/users/presentation/eslint.config.js | 3 - libs/users/presentation/project.json | 9 --- libs/users/presentation/src/index.ts | 1 - .../src/lib/users.resolver.spec.ts | 69 ------------------- .../presentation/src/lib/users.resolver.ts | 21 ------ tsconfig.base.json | 5 +- 17 files changed, 40 insertions(+), 117 deletions(-) delete mode 100644 libs/users/presentation/README.md create mode 100644 libs/users/presentation/dto/README.md create mode 100644 libs/users/presentation/dto/eslint.config.js rename libs/users/presentation/{ => dto}/jest.config.ts (55%) create mode 100644 libs/users/presentation/dto/project.json create mode 100644 libs/users/presentation/dto/src/index.ts create mode 100644 libs/users/presentation/dto/src/lib/users-presentation-dto.spec.ts create mode 100644 libs/users/presentation/dto/src/lib/users-presentation-dto.ts rename libs/users/presentation/{ => dto}/tsconfig.json (90%) rename libs/users/presentation/{ => dto}/tsconfig.lib.json (85%) rename libs/users/presentation/{ => dto}/tsconfig.spec.json (84%) delete mode 100644 libs/users/presentation/eslint.config.js delete mode 100644 libs/users/presentation/project.json delete mode 100644 libs/users/presentation/src/index.ts delete mode 100644 libs/users/presentation/src/lib/users.resolver.spec.ts delete mode 100644 libs/users/presentation/src/lib/users.resolver.ts diff --git a/libs/users/presentation/README.md b/libs/users/presentation/README.md deleted file mode 100644 index 255bbba..0000000 --- a/libs/users/presentation/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# users-presentation - -This library was generated with [Nx](https://nx.dev). - -## Running unit tests - -Run `nx test users-presentation` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/users/presentation/dto/README.md b/libs/users/presentation/dto/README.md new file mode 100644 index 0000000..447a3e3 --- /dev/null +++ b/libs/users/presentation/dto/README.md @@ -0,0 +1,7 @@ +# users-presentation-dto + +This library was generated with [Nx](https://nx.dev). + +## Running unit tests + +Run `nx test users-presentation-dto` to execute the unit tests via [Jest](https://jestjs.io). diff --git a/libs/users/presentation/dto/eslint.config.js b/libs/users/presentation/dto/eslint.config.js new file mode 100644 index 0000000..cdd3cba --- /dev/null +++ b/libs/users/presentation/dto/eslint.config.js @@ -0,0 +1,3 @@ +const baseConfig = require('../../../../eslint.config.js'); + +module.exports = [...baseConfig]; diff --git a/libs/users/presentation/jest.config.ts b/libs/users/presentation/dto/jest.config.ts similarity index 55% rename from libs/users/presentation/jest.config.ts rename to libs/users/presentation/dto/jest.config.ts index 9fb66bd..dce5b33 100644 --- a/libs/users/presentation/jest.config.ts +++ b/libs/users/presentation/dto/jest.config.ts @@ -1,10 +1,10 @@ export default { - displayName: 'users-presentation', - preset: '../../../jest.preset.js', + displayName: 'users-presentation-dto', + preset: '../../../../jest.preset.js', testEnvironment: 'node', transform: { '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }], }, moduleFileExtensions: ['ts', 'js', 'html'], - coverageDirectory: '../../../coverage/libs/users/presentation', + coverageDirectory: '../../../../coverage/libs/users/presentation/dto', }; diff --git a/libs/users/presentation/dto/project.json b/libs/users/presentation/dto/project.json new file mode 100644 index 0000000..a87f550 --- /dev/null +++ b/libs/users/presentation/dto/project.json @@ -0,0 +1,9 @@ +{ + "name": "users-presentation-dto", + "$schema": "../../../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "libs/users/presentation/dto/src", + "projectType": "library", + "tags": [], + "// targets": "to see all targets run: nx show project users-presentation-dto --web", + "targets": {} +} diff --git a/libs/users/presentation/dto/src/index.ts b/libs/users/presentation/dto/src/index.ts new file mode 100644 index 0000000..75f50c5 --- /dev/null +++ b/libs/users/presentation/dto/src/index.ts @@ -0,0 +1 @@ +export * from './lib/users-presentation-dto'; diff --git a/libs/users/presentation/dto/src/lib/users-presentation-dto.spec.ts b/libs/users/presentation/dto/src/lib/users-presentation-dto.spec.ts new file mode 100644 index 0000000..ccccc62 --- /dev/null +++ b/libs/users/presentation/dto/src/lib/users-presentation-dto.spec.ts @@ -0,0 +1,7 @@ +import { usersPresentationDto } from './users-presentation-dto'; + +describe('usersPresentationDto', () => { + it('should work', () => { + expect(usersPresentationDto()).toEqual('users-presentation-dto'); + }); +}); diff --git a/libs/users/presentation/dto/src/lib/users-presentation-dto.ts b/libs/users/presentation/dto/src/lib/users-presentation-dto.ts new file mode 100644 index 0000000..e5b7672 --- /dev/null +++ b/libs/users/presentation/dto/src/lib/users-presentation-dto.ts @@ -0,0 +1,3 @@ +export function usersPresentationDto(): string { + return 'users-presentation-dto'; +} diff --git a/libs/users/presentation/tsconfig.json b/libs/users/presentation/dto/tsconfig.json similarity index 90% rename from libs/users/presentation/tsconfig.json rename to libs/users/presentation/dto/tsconfig.json index 0dc79ca..07e0ec6 100644 --- a/libs/users/presentation/tsconfig.json +++ b/libs/users/presentation/dto/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../../tsconfig.base.json", + "extends": "../../../../tsconfig.base.json", "compilerOptions": { "module": "commonjs", "forceConsistentCasingInFileNames": true, diff --git a/libs/users/presentation/tsconfig.lib.json b/libs/users/presentation/dto/tsconfig.lib.json similarity index 85% rename from libs/users/presentation/tsconfig.lib.json rename to libs/users/presentation/dto/tsconfig.lib.json index e583571..28369ef 100644 --- a/libs/users/presentation/tsconfig.lib.json +++ b/libs/users/presentation/dto/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "commonjs", - "outDir": "../../../dist/out-tsc", + "outDir": "../../../../dist/out-tsc", "declaration": true, "types": ["node"] }, diff --git a/libs/users/presentation/tsconfig.spec.json b/libs/users/presentation/dto/tsconfig.spec.json similarity index 84% rename from libs/users/presentation/tsconfig.spec.json rename to libs/users/presentation/dto/tsconfig.spec.json index 69a251f..6668655 100644 --- a/libs/users/presentation/tsconfig.spec.json +++ b/libs/users/presentation/dto/tsconfig.spec.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "outDir": "../../../dist/out-tsc", + "outDir": "../../../../dist/out-tsc", "module": "commonjs", "types": ["jest", "node"] }, diff --git a/libs/users/presentation/eslint.config.js b/libs/users/presentation/eslint.config.js deleted file mode 100644 index 07e518f..0000000 --- a/libs/users/presentation/eslint.config.js +++ /dev/null @@ -1,3 +0,0 @@ -const baseConfig = require('../../../eslint.config.js'); - -module.exports = [...baseConfig]; diff --git a/libs/users/presentation/project.json b/libs/users/presentation/project.json deleted file mode 100644 index b60d286..0000000 --- a/libs/users/presentation/project.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "users-presentation", - "$schema": "../../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/users/presentation/src", - "projectType": "library", - "tags": [], - "// targets": "to see all targets run: nx show project users-presentation --web", - "targets": {} -} diff --git a/libs/users/presentation/src/index.ts b/libs/users/presentation/src/index.ts deleted file mode 100644 index 281b820..0000000 --- a/libs/users/presentation/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './lib/users.resolver'; diff --git a/libs/users/presentation/src/lib/users.resolver.spec.ts b/libs/users/presentation/src/lib/users.resolver.spec.ts deleted file mode 100644 index 411129c..0000000 --- a/libs/users/presentation/src/lib/users.resolver.spec.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { UsersService } from '@users/application'; -import { User } from '@user/domain'; - -import { UsersResolver } from './users.resolver'; - -describe('UsersResolver', () => { - let resolver: UsersResolver; - let service: UsersService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [ - UsersResolver, - { - provide: UsersService, - useValue: { - findById: jest.fn(), - }, - }, - ], - }).compile(); - - resolver = module.get(UsersResolver); - service = module.get(UsersService); - }); - - it('should be defined', () => { - expect(resolver).toBeDefined(); - }); - - describe('getUser', () => { - it('should return a user by id', () => { - const user: User = { id: '1', name: 'John Doe' }; - jest.spyOn(service, 'findById').mockReturnValue(user); - - expect(resolver.getUser('1')).toEqual(user); - expect(service.findById).toHaveBeenCalledWith('1'); - }); - - it('should return undefined if user not found', () => { - jest.spyOn(service, 'findById').mockReturnValue(undefined); - - expect(resolver.getUser('2')).toBeUndefined(); - expect(service.findById).toHaveBeenCalledWith('2'); - }); - }); - - describe('resolveReference', () => { - it('should return a user by reference id', () => { - const user: User = { id: '1', name: 'John Doe' }; - jest.spyOn(service, 'findById').mockReturnValue(user); - - expect( - resolver.resolveReference({ __typename: 'User', id: '1' }), - ).toEqual(user); - expect(service.findById).toHaveBeenCalledWith('1'); - }); - - it('should return undefined if user not found by reference id', () => { - jest.spyOn(service, 'findById').mockReturnValue(undefined); - - expect( - resolver.resolveReference({ __typename: 'User', id: '2' }), - ).toBeUndefined(); - expect(service.findById).toHaveBeenCalledWith('2'); - }); - }); -}); diff --git a/libs/users/presentation/src/lib/users.resolver.ts b/libs/users/presentation/src/lib/users.resolver.ts deleted file mode 100644 index 88ac9fa..0000000 --- a/libs/users/presentation/src/lib/users.resolver.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Args, ID, Query, Resolver, ResolveReference } from '@nestjs/graphql'; -import { UsersService } from '@users/application'; -import { User } from '@user/domain'; - -@Resolver(() => User) -export class UsersResolver { - constructor(private usersService: UsersService) {} - - @Query(() => User, { nullable: true }) - getUser(@Args({ name: 'id', type: () => ID }) id: string): User | undefined { - return this.usersService.findById(id); - } - - @ResolveReference() - resolveReference(reference: { - __typename: string; - id: string; - }): User | undefined { - return this.usersService.findById(reference.id); - } -} diff --git a/tsconfig.base.json b/tsconfig.base.json index 7c2161d..54ea840 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -19,7 +19,10 @@ "@prompt/domain": ["libs/prompt/domain/src/index.ts"], "@user/domain": ["libs/user/domain/src/index.ts"], "@users/application": ["libs/users/application/src/index.ts"], - "@users/presentation": ["libs/users/presentation/src/index.ts"] + "@users/presentation-dto": ["libs/users/presentation/dto/src/index.ts"], + "@users/presentation-resolver": [ + "libs/users/presentation/resolver/src/index.ts" + ] } }, "exclude": ["node_modules", "tmp"]