From 94fbc9cadfce2366dbc4299cc22a2d63f773193e Mon Sep 17 00:00:00 2001 From: zhumeisongsong Date: Sat, 7 Dec 2024 22:54:41 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20add=20UserTask?= =?UTF-8?q?sService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/tasks/application/src/index.ts | 1 + .../application/src/lib/tasks.service.spec.ts | 30 -------------- .../application/src/lib/tasks.service.ts | 26 +------------ .../src/lib/user-tasks.service.spec.ts | 39 +++++++++++++++++++ .../application/src/lib/user-tasks.service.ts | 29 ++++++++++++++ 5 files changed, 70 insertions(+), 55 deletions(-) create mode 100644 libs/tasks/application/src/lib/user-tasks.service.spec.ts create mode 100644 libs/tasks/application/src/lib/user-tasks.service.ts diff --git a/libs/tasks/application/src/index.ts b/libs/tasks/application/src/index.ts index 7465cca..05a5430 100644 --- a/libs/tasks/application/src/index.ts +++ b/libs/tasks/application/src/index.ts @@ -1 +1,2 @@ export * from './lib/tasks.service'; +export * from './lib/user-tasks.service'; \ No newline at end of file diff --git a/libs/tasks/application/src/lib/tasks.service.spec.ts b/libs/tasks/application/src/lib/tasks.service.spec.ts index e151139..95996af 100644 --- a/libs/tasks/application/src/lib/tasks.service.spec.ts +++ b/libs/tasks/application/src/lib/tasks.service.spec.ts @@ -23,34 +23,4 @@ describe('TasksService', () => { expect(Array.isArray(result)).toBe(true); }); }); - - describe('findUserTasks', () => { - it('should return an array of user tasks', async () => { - const result = await service.findUserTasks('123'); - expect(Array.isArray(result)).toBe(true); - }); - }); - - describe('createUserTasks', () => { - it('should create user tasks and return success', async () => { - const userId = '123'; - const tasks = [{ id: '3', createdAt: new Date() }]; - const result = await service.createUserTasks(userId, tasks); - expect(result).toBe('success'); - }); - }); - - describe('updateUserTasks', () => { - it('should update user tasks and return success', async () => { - const userId = '123'; - const userTasks = [ - { - id: 'user-task-1', - updatedAt: new Date(), - }, - ]; - const result = await service.updateUserTasks(userId, userTasks); - expect(result).toBe('success'); - }); - }); }); diff --git a/libs/tasks/application/src/lib/tasks.service.ts b/libs/tasks/application/src/lib/tasks.service.ts index 699f457..4ae8c08 100644 --- a/libs/tasks/application/src/lib/tasks.service.ts +++ b/libs/tasks/application/src/lib/tasks.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { Task, UserTask } from '@tasks/domain'; +import { Task } from '@tasks/domain'; @Injectable() export class TasksService { @@ -7,28 +7,4 @@ export class TasksService { // TODO: Implement this return []; } - - async findUserTasks( - userId: string, - range?: { from: Date; to: Date }, - ): Promise { - // TODO: Implement this - return []; - } - - async createUserTasks( - userId: string, - tasks: { id: string; createdAt: Date }[], - ): Promise { - // TODO: Implement this - return 'success'; - } - - async updateUserTasks( - userId: string, - userTasks: { id: string; updatedAt: Date }[], - ): Promise { - // TODO: Implement this - return 'success'; - } } diff --git a/libs/tasks/application/src/lib/user-tasks.service.spec.ts b/libs/tasks/application/src/lib/user-tasks.service.spec.ts new file mode 100644 index 0000000..b43230e --- /dev/null +++ b/libs/tasks/application/src/lib/user-tasks.service.spec.ts @@ -0,0 +1,39 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { UserTasksService } from './user-tasks.service'; + +describe('UserTasksService', () => { + let service: UserTasksService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [UserTasksService], + }).compile(); + + service = module.get(UserTasksService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); + + describe('findMany', () => { + it('should return user tasks', async () => { + const result = await service.findMany('userId', { from: new Date(), to: new Date() }); + expect(result).toEqual([]); + }); + }); + + describe('createSome', () => { + it('should create user tasks', async () => { + const result = await service.createSome('userId', [{ id: '1', createdAt: new Date() }]); + expect(result).toEqual('success'); + }); + }); + + describe('updateSome', () => { + it('should update user tasks', async () => { + const result = await service.updateSome('userId', [{ id: '1', updatedAt: new Date() }]); + expect(result).toEqual('success'); + }); + }); +}); diff --git a/libs/tasks/application/src/lib/user-tasks.service.ts b/libs/tasks/application/src/lib/user-tasks.service.ts new file mode 100644 index 0000000..d46d5ed --- /dev/null +++ b/libs/tasks/application/src/lib/user-tasks.service.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@nestjs/common'; +import { UserTask } from '@tasks/domain'; + +@Injectable() +export class UserTasksService { + async findMany( + userId: string, + range?: { from: Date; to: Date }, + ): Promise { + // TODO: Implement this + return []; + } + + async createSome( + userId: string, + tasks: { id: string; createdAt: Date }[], + ): Promise { + // TODO: Implement this + return 'success'; + } + + async updateSome( + userId: string, + userTasks: { id: string; updatedAt: Date }[], + ): Promise { + // TODO: Implement this + return 'success'; + } +}