Skip to content

Instantly share code, notes, and snippets.

@laugri
laugri / ddd-example-usecase-test.js
Last active Dec 3, 2018
DDD Example - use case test
View ddd-example-usecase-test.js
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: []})
@laugri
laugri / ddd-example-repository-implementation.js
Created Dec 2, 2018
DDD example - Repository implementation
View ddd-example-repository-implementation.js
// Repository implementation example
class InMemoryShoppingCartRepository implements ShoppingCartRepository {
findById(shoppingCartId: ShoppingCartId) {
// implementation
}
store(ShoppingCart: ShoppingCart): Promise<void> {
// implementation
@laugri
laugri / ddd-example-repository-interface.js
Created Dec 2, 2018
DDD example - Repository Interface
View ddd-example-repository-interface.js
// Repository interface example
interface ShoppingCartRepository {
findById(shoppingCartId: ShoppingCartId): Promise<ShoppingCart>;
store(shoppingCart: ShoppingCart): Promise<void>;
}
@laugri
laugri / ddd-example-aggregate.js
Created Dec 2, 2018
DDD Example - Aggregate.js
View ddd-example-aggregate.js
// Our ShoppingCart example of an Entity is actually also an aggregate.
class ShoppingCart {
id: ShoppingCartId;
items: Array<ShoppingCartItem>
addItem(item: ShoppingCartItem) {
// implementation
}
@laugri
laugri / ddd-example-domain-service.js
Created Dec 2, 2018
DDD example - domain service
View ddd-example-domain-service.js
// For e-commerce, an example of a domain service would be the checkout step
function checkout(shoppingCart: ShoppingCart, ...) {
// do service stuff
}
View ddd-example-entity.js
// An example of an Entity
class ShoppingCart {
id: ShoppingCartId;
items: Array<ShoppingCartItem>
addItem(item: ShoppingCartItem) {
// implementation
}
@laugri
laugri / ddd-example-value-object.js
Last active Dec 5, 2018
DDD example - Value Object
View ddd-example-value-object.js
// An example of a Value Object
class Price {
amountInEuroCents: number
inEuros(): number {
// implementation
}
View package.json
{
"scripts": {
"heroku-postbuild": "./scripts/heroku.build",
}
}
View heroku.sh
#!/bin/sh -e
usage() {
echo "OVERVIEW: Build apps according to BUILD_ENV value. Meant to be used for Heroku deployment"
exit
}
if [ "$1" = '-h' ] || [ "$1" = '--help' ]; then
usage
fi
View spa-express-server.js
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const PORT = process.env.PORT || 3000;
const app = express();
const logger = morgan(
process.env.NODE_ENV !== 'production' ? 'dev' : 'combined',
You can’t perform that action at this time.