Created
February 12, 2013 04:53
-
-
Save danveloper/4760336 to your computer and use it in GitHub Desktop.
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
/** Addresses **/ | |
def billingAddress1 = new Address(street: "1 Main ST", unit: "7a", city: "Chicago", state: "IL", zip: 60652) | |
def billingAddress2 = new Address(street: "75 Dr Dre Rd.", city: "Compton", state: "CA", zip: 90220) | |
/** Payment Methods **/ | |
def giftCard = new GiftCard(number: "0000000001", balance: 50.00) | |
def creditCard = new CreditCard(number: "4111111111111111", expiration: new Date(year: 2013, month: 1, date: 31), billingAddress: billingAddress1) | |
/** Account **/ | |
def account = new Account(email: "[email protected]", orderCount: 0) | |
/** Products **/ | |
def xbox360 = new Product(name: "XBOX 360 - 250GB", type: Product.ProductType.PRODUCT, cost: 250.00) | |
def xbox360repairService = new Product(name: "XBOX 360 Repair Service (you'll need it!)", type: Product.ProductType.SERVICE, cost: 200.00) | |
/** Coupons **/ | |
def xbox360discount = new Coupon(id: "XBOX 360 - 10% discount", discountRate: 0.10, appliesTo: [Product.ProductType.PRODUCT]) | |
def xbox360serviceDiscount = new Coupon(id: "XBOX 360 - 20% discount", discountRate: 0.20, appliesTo: [Product.ProductType.SERVICE]) | |
/** Build Order **/ | |
def order = new ProductOrder(account: account, paymentMethod: creditCard, products: [xbox360]) | |
// call the rules engine against our newly created order | |
ProductOrderRules.callRules(order) | |
// verify that some of the rules worked (shippingAddress imposed from cc's billing address) | |
assert order.shippingAddress == order.paymentMethod.billingAddress | |
assert order.products.find { it == xbox360 }.cost == 250.00 | |
// add another product | |
order.products << xbox360repairService | |
// add a coupon to the order and re-run the rules | |
order.coupons = [xbox360discount] | |
ProductOrderRules.callRules(order) | |
// verify that the coupon's discount was applied | |
assert order.products.find { it == xbox360 }.cost == 225.00 | |
assert order.products.find { it == xbox360repairService }.cost == 200.00 | |
// add the xbox360 service discount coupon and re-run the rules | |
order.coupons << xbox360serviceDiscount | |
ProductOrderRules.callRules(order) | |
assert order.products.find { it == xbox360repairService }.cost == 160.00 | |
// verify the 1st time buyer email will be sent | |
assert order.firstOrderThankYou == true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment