Last active
August 29, 2015 14:06
-
-
Save winnab/f4c4191e5de2ae73e713 to your computer and use it in GitHub Desktop.
LSCC 24092014 Outside In TDD
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
// 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: '[email protected]' | |
}; | |
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