Skip to content

Instantly share code, notes, and snippets.

@winnab
Last active August 29, 2015 14:06
Show Gist options
  • Save winnab/f4c4191e5de2ae73e713 to your computer and use it in GitHub Desktop.
Save winnab/f4c4191e5de2ae73e713 to your computer and use it in GitHub Desktop.
LSCC 24092014 Outside In TDD
// for London Software Craftsmanship Community event http://www.meetup.com/london-software-craftsmanship/events/208963722/
// from http://codingboard.org/boards/lscc
// nothing more than concepts here
function Order() {
return {
customer: {},
basket: {},
paymentInfo: {}
};
};
// ****************
// MOCKS
// ****************
var customerMock = {
email: 'test@example.com'
};
var basketMock = {
items: ['apple', 'orange', 'grape']
};
var paymentInfoMock = {
card: 'visa',
number: '12345'
};
var orderMock = new Order({
customer: customerMock,
basket: basketMock,
paymentInfo: paymentInfoMock
});
var orderSubmittedChecklist = {
checkedStock: false,
sentPaymentDetails: false,
sentOrderConfirmation: false
};
var submitOrder = function (order) {
return {
checkStock: stockManagementServiceMock.checkStock(order.basket),
processPayment: paymentProcessingMock.processPayment(order.paymentInfo),
emailSender: emailSenderMock.sendEmailConfirmation(order.customer)
};
};
function stockManagementServiceMock(basketItems) {
return {
checkStock: function (basketItems) {
if (basketItems) {
orderSubmittedChecklist.checkedStock = true;
}
return orderSubmittedChecklist;
}
};
}
function paymentProcessingMock(paymentDetails) {
return {
processPayment: function (paymentDetails) {
if (paymentDetails) {
orderSubmittedChecklist.sentPaymentDetails = true;
}
return orderSubmittedChecklist;
}
};
}
function emailSenderMock(paymentConfirmation) {
return {
sendEmailConfirmation: function (paymentConfirmation) {
if (paymentConfirmation) {
orderSubmittedChecklist.sentOrderConfirmation = true;
}
return orderSubmittedChecklist;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment