Skip to content

Commit

Permalink
refactor: ♻️ add UserTasksService
Browse files Browse the repository at this point in the history
  • Loading branch information
zhumeisongsong committed Dec 7, 2024
1 parent a40db58 commit 94fbc9c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 55 deletions.
1 change: 1 addition & 0 deletions libs/tasks/application/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lib/tasks.service';
export * from './lib/user-tasks.service';
30 changes: 0 additions & 30 deletions libs/tasks/application/src/lib/tasks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
26 changes: 1 addition & 25 deletions libs/tasks/application/src/lib/tasks.service.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import { Injectable } from '@nestjs/common';
import { Task, UserTask } from '@tasks/domain';
import { Task } from '@tasks/domain';

@Injectable()
export class TasksService {
async findAll(): Promise<Task[]> {
// TODO: Implement this
return [];
}

async findUserTasks(
userId: string,
range?: { from: Date; to: Date },
): Promise<UserTask[]> {
// TODO: Implement this
return [];
}

async createUserTasks(
userId: string,
tasks: { id: string; createdAt: Date }[],
): Promise<string> {
// TODO: Implement this
return 'success';
}

async updateUserTasks(
userId: string,
userTasks: { id: string; updatedAt: Date }[],
): Promise<string> {
// TODO: Implement this
return 'success';
}
}
39 changes: 39 additions & 0 deletions libs/tasks/application/src/lib/user-tasks.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(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');
});
});
});
29 changes: 29 additions & 0 deletions libs/tasks/application/src/lib/user-tasks.service.ts
Original file line number Diff line number Diff line change
@@ -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<UserTask[]> {
// TODO: Implement this
return [];
}

async createSome(
userId: string,
tasks: { id: string; createdAt: Date }[],
): Promise<string> {
// TODO: Implement this
return 'success';
}

async updateSome(
userId: string,
userTasks: { id: string; updatedAt: Date }[],
): Promise<string> {
// TODO: Implement this
return 'success';
}
}

0 comments on commit 94fbc9c

Please sign in to comment.