Last active
December 3, 2018 17:55
-
-
Save laugri/4dfa5dbfc507148467a648dcbf82407b to your computer and use it in GitHub Desktop.
DDD Example - use case test
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 { articleTestFactory } from '~/domain/article'; | |
import { shoppingCartTestFactory, itemTestFactory } from '~/domain/shoppingCart'; | |
import { InMemoryShoppingCartRepository } from '~/infrastructure/InMemoryShoppingCartRepository'; | |
import { InMemoryArticleRepository } from '~/infrastructure/InMemoryArticleRepository'; | |
describe('addArticleToCart', () => { | |
it('should update, persist and return the cart with a new article', async () => { | |
// Arrange | |
const shoppingCartRepository = new InMemoryShoppingCartRepository(); | |
const shoppingCart = shoppingCartTestFactory({items: []}) | |
shoppingCartRepository.store(shoppingCart); | |
const articleRepository = new InMemoryArticleRepository(); | |
const article = articleTestFactory(); | |
articleRepository.store(article); | |
// Act | |
const newShoppingCart = await addArticleToCart( | |
{ | |
shoppingCartRepository, | |
articleRepository | |
shoppingCartId: shoppingCart.id, | |
articleId: article.id, | |
quantity: 1, | |
}, | |
); | |
// Assert | |
const expectedShoppingCart = shoppingCartTestFactory({ | |
items: [itemTestFactory({ article, quantity: 1 })], | |
}); | |
expect(newShoppingCart).toEqual(expectedShoppingCart); | |
expect( | |
await shoppingCartRepository.findById(shoppingCart.id), | |
).toEqual(expectedShoppingCart); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment