Last active
September 6, 2016 10:16
-
-
Save jeffijoe/cac274a4b793f82787c8a9feb5144114 to your computer and use it in GitHub Desktop.
Snippet for my Medium article
This file contains hidden or 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
import makeTodosService from './todosService' | |
import TodosRepository from './todosRepository' | |
describe('Todos System', function () { | |
it('works', async function () { | |
// This is how DI is done manually | |
const todosService = makeTodosService({ | |
todosRepository: new TodosRepository(), | |
// Let's fake it til we make it! | |
currentUser: { | |
id: 123, | |
name: 'Jeff' | |
} | |
}) | |
// Todos Service already knows who's creating it! | |
const created = await todosService.create({ | |
text: 'Write Medium article' | |
}) | |
expect(created.userId).to.equal(123, 'user id should match currentUser') | |
const todos = await todosService.getTodos({ | |
filter: 'ALL' | |
}) | |
expect(todos.length).to.equal(1) | |
await todosService.update(todo.id, { | |
completed: true | |
}) | |
const incompleteTodos = await todosService.getTodos({ | |
filter: 'INCOMPLETED' | |
}) | |
expect(incompleteTodos.length).to.equal(0) | |
const completedTodos = await todosService.getTodos({ | |
filter: 'COMPLETED' | |
}) | |
expect(completedTodos.length).to.equal(1) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment