-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6dfa7d
commit 45875fa
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
libs/tasks/application/src/lib/use-cases/get-all-user-tasks.use-case.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { TaskStatusEnum, UserTask } from '@tasks/domain'; | ||
import { GetAllUserTasksUseCase } from './get-all-user-tasks.use-case'; | ||
import { UserTasksService } from '../user-tasks.service'; | ||
|
||
describe('GetAllUserTasksUseCase', () => { | ||
let useCase: GetAllUserTasksUseCase; | ||
let userTasksService: UserTasksService; | ||
|
||
beforeEach(async () => { | ||
const moduleRef = await Test.createTestingModule({ | ||
providers: [ | ||
GetAllUserTasksUseCase, | ||
{ | ||
provide: UserTasksService, | ||
useValue: { | ||
findAll: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
useCase = moduleRef.get<GetAllUserTasksUseCase>(GetAllUserTasksUseCase); | ||
userTasksService = moduleRef.get<UserTasksService>(UserTasksService); | ||
}); | ||
|
||
describe('execute', () => { | ||
it('should return all user tasks', async () => { | ||
const userId = 'test-user-id'; | ||
const expectedTasks: UserTask[] = [ | ||
{ | ||
id: '1', | ||
userId, | ||
taskId: '1', | ||
createdAt: new Date('2024-01-01T00:00:00.000Z'), | ||
status: TaskStatusEnum.TODO, | ||
updatedAt: null, | ||
}, | ||
]; | ||
|
||
jest.spyOn(userTasksService, 'findAll').mockResolvedValue(expectedTasks); | ||
|
||
const result = await useCase.execute(userId); | ||
|
||
expect(result).toBe(expectedTasks); | ||
expect(userTasksService.findAll).toHaveBeenCalledWith(userId); | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
libs/tasks/application/src/lib/use-cases/get-all-user-tasks.use-case.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Injectable } from "@nestjs/common"; | ||
import { UserTask } from "@tasks/domain"; | ||
|
||
import { UserTasksService } from "../user-tasks.service"; | ||
|
||
@Injectable() | ||
export class GetAllUserTasksUseCase { | ||
constructor(private readonly userTasksService: UserTasksService) {} | ||
|
||
async execute(userId: string): Promise<UserTask[]> { | ||
return await this.userTasksService.findAll(userId); | ||
} | ||
} |