import { Todo } from '../../todo/entities/todo.entity' ; export class MockTodoRepository { private mockTodos : Todo [ ] = [ ] ; constructor ( mockTodos ) { this . mockTodos = mockTodos ; } async save ( todo ) { this . mockTodos . push ( todo ) ; return todo ; } async find ( ) { return this . mockTodos ; } async findOne ( id ) { return this . mockTodos . find ( ( todo ) => todo . id === id ) ; } async update ( id , partialTodo ) { let targetTodo = this . mockTodos . find ( ( todo ) => todo . id === id ) ; targetTodo = Object . assign ( targetTodo , partialTodo ) ; return targetTodo ; } async delete ( id ) { const deletedTodo = this . mockTodos . find ( ( todo ) => todo . id === id ) ; const deletedIndex = this . mockTodos . indexOf ( deletedTodo ) ; this . mockTodos = this . mockTodos . splice ( deletedIndex , 1 ) ; return deletedTodo ; } }