-
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.
Merge pull request #101 from zhumeisongsong/feature/tasks-interface-a…
…dapters feat: ✨ add tasks resolver: getTasks / getUserTasks / createUserTasks/updateUserTasks
- Loading branch information
Showing
49 changed files
with
837 additions
and
143 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
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,15 +1,13 @@ | ||
import { UnauthorizedException } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AwsCognitoService } from '@shared/infrastructure-aws-cognito'; | ||
import { UsersService } from '@users/application'; | ||
import { JwtService } from '@nestjs/jwt'; | ||
|
||
import { AuthService } from './auth.service'; | ||
|
||
describe('AuthService', () => { | ||
let service: AuthService; | ||
let awsCognitoService: jest.Mocked<AwsCognitoService>; | ||
let usersService: jest.Mocked<UsersService>; | ||
let jwtService: jest.Mocked<JwtService>; | ||
|
||
beforeEach(async () => { | ||
|
@@ -22,12 +20,6 @@ describe('AuthService', () => { | |
signIn: jest.fn(), | ||
}, | ||
}, | ||
{ | ||
provide: UsersService, | ||
useValue: { | ||
findByEmail: jest.fn(), | ||
}, | ||
}, | ||
{ | ||
provide: JwtService, | ||
useValue: { | ||
|
@@ -39,7 +31,6 @@ describe('AuthService', () => { | |
|
||
service = module.get<AuthService>(AuthService); | ||
awsCognitoService = module.get(AwsCognitoService); | ||
usersService = module.get(UsersService); | ||
jwtService = module.get(JwtService); | ||
}); | ||
|
||
|
@@ -50,8 +41,6 @@ describe('AuthService', () => { | |
describe('signIn', () => { | ||
const email = '[email protected]'; | ||
const password = 'password123'; | ||
const userId = '123'; | ||
const user = { id: userId, email, firstName: null, lastName: null }; | ||
|
||
// it('should throw UnauthorizedException when AWS Cognito sign in fails', async () => { | ||
// const error = new Error('Invalid credentials'); | ||
|
@@ -65,7 +54,6 @@ describe('AuthService', () => { | |
it('should throw UnauthorizedException when JWT signing fails', async () => { | ||
const error = new Error('JWT signing failed'); | ||
awsCognitoService.signIn.mockResolvedValue(undefined); | ||
usersService.findByEmail.mockResolvedValue(user); | ||
jwtService.signAsync.mockRejectedValue(error); | ||
|
||
await expect(service.signIn(email, password)).rejects.toThrow( | ||
|
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 +1,2 @@ | ||
export * from './lib/tasks-application'; | ||
export * from './lib/tasks.service'; | ||
export * from './lib/user-tasks.service'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,26 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
|
||
import { TasksService } from './tasks.service'; | ||
|
||
describe('TasksService', () => { | ||
let service: TasksService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [TasksService], | ||
}).compile(); | ||
|
||
service = module.get<TasksService>(TasksService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return an array of tasks', async () => { | ||
const result = await service.findAll(); | ||
expect(Array.isArray(result)).toBe(true); | ||
}); | ||
}); | ||
}); |
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,10 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Task } from '@tasks/domain'; | ||
|
||
@Injectable() | ||
export class TasksService { | ||
async findAll(): Promise<Task[]> { | ||
// TODO: Implement this | ||
return []; | ||
} | ||
} |
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,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'); | ||
}); | ||
}); | ||
}); |
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,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'; | ||
} | ||
} |
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 +1,4 @@ | ||
export * from './lib/tasks-domain'; | ||
export * from './lib/entities/task.entity'; | ||
export * from './lib/entities/user-task.entity'; | ||
|
||
export * from './lib/tasks.repository'; |
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,39 @@ | ||
import { Task } from './task.entity'; | ||
|
||
describe('Task', () => { | ||
it('should create a task with all properties', () => { | ||
const task = new Task( | ||
'test-id', | ||
'Test Title', | ||
'Test Description', | ||
['category1', 'category2'] | ||
); | ||
|
||
expect(task.id).toBe('test-id'); | ||
expect(task.title).toBe('Test Title'); | ||
expect(task.description).toBe('Test Description'); | ||
expect(task.categories).toEqual(['category1', 'category2']); | ||
}); | ||
|
||
it('should allow null description', () => { | ||
const task = new Task( | ||
'test-id', | ||
'Test Title', | ||
null, | ||
['category1'] | ||
); | ||
|
||
expect(task.description).toBeNull(); | ||
}); | ||
|
||
it('should create a task with empty categories array', () => { | ||
const task = new Task( | ||
'test-id', | ||
'Test Title', | ||
'Test Description', | ||
[] | ||
); | ||
|
||
expect(task.categories).toEqual([]); | ||
}); | ||
}); |
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,8 @@ | ||
export class Task { | ||
constructor( | ||
public readonly id: string, | ||
public readonly title: string, | ||
public readonly description: string | null, | ||
public readonly categories: string[], | ||
) {} | ||
} |
30 changes: 30 additions & 0 deletions
30
libs/tasks/domain/src/lib/entities/user-task.entity.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,30 @@ | ||
import { User } from '@users/domain'; | ||
import { Task } from './task.entity'; | ||
import { UserTask } from './user-task.entity'; | ||
|
||
describe('UserTask', () => { | ||
it('should create a user task instance', () => { | ||
const task = new Task('task-1', 'Test Task', 'Description', ['category1']); | ||
const user = new User('user-1', '[email protected]', null, null); | ||
const now = new Date(); | ||
|
||
const userTask = new UserTask( | ||
'user-task-1', | ||
now, | ||
null, | ||
'task-1', | ||
task, | ||
'user-1', | ||
user, | ||
); | ||
|
||
expect(userTask).toBeDefined(); | ||
expect(userTask.id).toBe('user-task-1'); | ||
expect(userTask.createdAt).toBe(now); | ||
expect(userTask.updatedAt).toBeNull(); | ||
expect(userTask.taskId).toBe('task-1'); | ||
expect(userTask.task).toBe(task); | ||
expect(userTask.userId).toBe('user-1'); | ||
expect(userTask.user).toBe(user); | ||
}); | ||
}); |
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,15 @@ | ||
import { User } from '@users/domain'; | ||
|
||
import { Task } from './task.entity'; | ||
|
||
export class UserTask { | ||
constructor( | ||
public readonly id: string, | ||
public readonly createdAt: Date, | ||
public readonly updatedAt: Date | null, | ||
public readonly taskId: string, | ||
public readonly task: Task | null, | ||
public readonly userId: string, | ||
public readonly user: User | null, | ||
) {} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
import { Task } from './entities/task.entity'; | ||
import { TasksRepository } from './tasks.repository'; | ||
|
||
class MockTasksRepository implements TasksRepository { | ||
async findAll(): Promise<Task[]> { | ||
return []; | ||
} | ||
} | ||
|
||
describe('TasksRepository', () => { | ||
let repository: TasksRepository; | ||
|
||
beforeEach(() => { | ||
repository = new MockTasksRepository(); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return all tasks', async () => { | ||
const tasks = await repository.findAll(); | ||
expect(Array.isArray(tasks)).toBe(true); | ||
expect(tasks.every((task) => task instanceof Task)).toBe(true); | ||
}); | ||
}); | ||
}); |
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,7 @@ | ||
import { Task } from './entities/task.entity'; | ||
|
||
export interface TasksRepository { | ||
findAll(): Promise<Task[]>; | ||
} | ||
|
||
export const TASKS_REPOSITORY = Symbol('TASKS_REPOSITORY'); |
Oops, something went wrong.