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
describe('Integration | Gateways | Http basket repository', () => { | |
const BASE_API_URL = 'https://www.fakeapi.com' | |
let httpClient: HTTPClient | |
let basketRepository: BasketRepository | |
let basket: Basket | |
beforeEach(() => { | |
httpClient = { | |
get : sinon.stub(), | |
post: sinon.stub() |
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
export interface BasketRepository { | |
getBasket(): Promise<Basket> | |
save(basket: Basket): Promise<void> | |
} |
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
export class InMemoryBasketRepository implements BasketRepository { | |
private _basket: Basket = new Basket() | |
getBasket(): Promise<Basket> { | |
return Promise.resolve(this._basket) | |
} | |
async save(basket: Basket): Promise<void> { | |
this._basket = basket | |
} |
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
export class GetBasketInformation { | |
constructor(private basketRepository: BasketRepository) { | |
} | |
handle(): Promise<Basket> { | |
return this.basketRepository.getBasket() | |
} | |
} |
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
export class AddToBasket { | |
constructor(private basketRepository: BasketRepository) { | |
} | |
async execute(book: Book): Promise<void> { | |
const basket = await this.basketRepository.getBasket() | |
basket.add(book) | |
return this.basketRepository.save(basket) | |
} | |
} |
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
describe('Unit | Basket price calculation', () => { | |
let getBasketInformation: GetBasketInformation | |
let addToBasket: AddToBasket | |
beforeEach(() => { | |
const basketRepository = new InMemoryBasketRepository() | |
getBasketInformation = new GetBasketInformation(basketRepository) | |
addToBasket = new AddToBasket(basketRepository) | |
}) |
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
describe('Unit | Caclcule du prix du panier', () => { | |
let basket: Basket | |
beforeEach(() => basket = new Basket()) | |
it('Pour un panier vide', () => { | |
expect(basket.price).to.equal(0) | |
}) | |
describe('Emprunter n livres différents', () => { |
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
describe('Unit | Basket price calculation', () => { | |
let basket: Basket | |
beforeEach(() => basket = new Basket()) | |
it('For an empty basket', () => { | |
expect(basket.price).to.equal(0) | |
}) | |
describe('Borrowing n different books', () => { |
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
class PhoneNumbersSaga(eventPublisher: EventPublisher) extends EventListener { | |
private var tracker = new PhoneNumberStateTracker | |
def handle(phoneNumbers: List[String]): PhoneNumberStateTracker = { | |
eventPublisher.publish(AllPhoneNumberListed(phoneNumbers)) | |
tracker | |
} | |
override def execute(event: Event): Unit = event match { | |
case apnc: AllPhoneNumbersCounted => tracker = PhoneNumberStateTracker(apnc.total, tracker.totalMatchedPhoneNumbers) |
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
export class NoDiscountCalculator implements DiscountCalculator { | |
applyDiscountOn(price: number): number { | |
return price | |
} | |
} |