-
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
1a24931
commit f6dfa7d
Showing
5 changed files
with
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
// tasks | ||
export * from './lib/tasks.service'; | ||
export * from './lib/use-cases/get-all-tasks.use-case'; | ||
|
||
// user tasks | ||
export * from './lib/user-tasks.service'; | ||
export * from './lib/use-cases/create-some-user-tasks.use-case'; | ||
export * from './lib/use-cases/update-some-user-tasks.use-case'; |
47 changes: 47 additions & 0 deletions
47
libs/tasks/application/src/lib/use-cases/create-some-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,47 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserTasksService } from '../user-tasks.service'; | ||
import { CreateSomeUserTasksUseCase } from './create-some-user-tasks.use-case'; | ||
|
||
describe('CreateSomeUserTasksUseCase', () => { | ||
let useCase: CreateSomeUserTasksUseCase; | ||
let userTasksService: UserTasksService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
CreateSomeUserTasksUseCase, | ||
{ | ||
provide: UserTasksService, | ||
useValue: { | ||
createSome: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
useCase = module.get<CreateSomeUserTasksUseCase>(CreateSomeUserTasksUseCase); | ||
userTasksService = module.get<UserTasksService>(UserTasksService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(useCase).toBeDefined(); | ||
}); | ||
|
||
describe('execute', () => { | ||
it('should create multiple user tasks', async () => { | ||
const userId = 'test-user-id'; | ||
const tasks = [ | ||
{ id: '1', createdAt: new Date() }, | ||
{ id: '2', createdAt: new Date() }, | ||
]; | ||
const expectedResult = 'success'; | ||
|
||
jest.spyOn(userTasksService, 'createSome').mockResolvedValue(expectedResult); | ||
|
||
const result = await useCase.execute(userId, tasks); | ||
|
||
expect(result).toEqual(expectedResult); | ||
expect(userTasksService.createSome).toHaveBeenCalledWith(userId, tasks); | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
libs/tasks/application/src/lib/use-cases/create-some-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,14 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { UserTasksService } from '../user-tasks.service'; | ||
|
||
@Injectable() | ||
export class CreateSomeUserTasksUseCase { | ||
constructor(private readonly userTasksService: UserTasksService) {} | ||
|
||
async execute( | ||
userId: string, | ||
tasks: { id: string; createdAt: Date }[], | ||
): Promise<string> { | ||
return await this.userTasksService.createSome(userId, tasks); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
libs/tasks/application/src/lib/use-cases/update-some-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,47 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { UserTasksService } from '../user-tasks.service'; | ||
import { UpdateSomeUserTasksUseCase } from './update-some-user-tasks.use-case'; | ||
|
||
describe('UpdateSomeUserTasksUseCase', () => { | ||
let useCase: UpdateSomeUserTasksUseCase; | ||
let userTasksService: UserTasksService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
UpdateSomeUserTasksUseCase, | ||
{ | ||
provide: UserTasksService, | ||
useValue: { | ||
updateSome: jest.fn(), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
useCase = module.get<UpdateSomeUserTasksUseCase>(UpdateSomeUserTasksUseCase); | ||
userTasksService = module.get<UserTasksService>(UserTasksService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(useCase).toBeDefined(); | ||
}); | ||
|
||
describe('execute', () => { | ||
it('should update multiple user tasks', async () => { | ||
const userId = 'test-user-id'; | ||
const userTasks = [ | ||
{ id: '1', updatedAt: new Date() }, | ||
{ id: '2', updatedAt: new Date() }, | ||
]; | ||
const expectedResult = 'success'; | ||
|
||
jest.spyOn(userTasksService, 'updateSome').mockResolvedValue(expectedResult); | ||
|
||
const result = await useCase.execute(userId, userTasks); | ||
|
||
expect(result).toEqual(expectedResult); | ||
expect(userTasksService.updateSome).toHaveBeenCalledWith(userId, userTasks); | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
libs/tasks/application/src/lib/use-cases/update-some-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,14 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { UserTasksService } from '../user-tasks.service'; | ||
|
||
@Injectable() | ||
export class UpdateSomeUserTasksUseCase { | ||
constructor(private readonly userTasksService: UserTasksService) {} | ||
|
||
async execute( | ||
userId: string, | ||
userTasks: { id: string; updatedAt: Date }[], | ||
): Promise<string> { | ||
return await this.userTasksService.updateSome(userId, userTasks); | ||
} | ||
} |