Last active
August 29, 2015 14:23
-
-
Save sescobb27/60be05f13c76c4bb01d2 to your computer and use it in GitHub Desktop.
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
import Ember from "ember"; | |
import startApp from '../../helpers/start-app'; | |
import {textHas, selectFrom} from '../../helpers/util'; | |
import config from '../../../config/environment'; | |
import { module, test } from 'qunit'; | |
import QUnit from 'qunit'; | |
var debug = Ember.Logger.debug; | |
var apiUrl = config.api.host + config.api.namespace; | |
var path = '/checkout'; | |
module("End To End - Subscribe to Premium Plan", { | |
beforeEach: function(){ | |
this.App = startApp(); | |
}, | |
afterEach: function() { | |
Ember.run(this.App, 'destroy'); | |
} | |
}); | |
test('creates a new premium plan customer', function (assert) { | |
visit(path); | |
andThen(() => click('.option-premium')); | |
andThen(() => { | |
// pick first shirt | |
return click('.product:eq(0)'); | |
}); | |
click('.product:eq(1)'); | |
andThen(() => { | |
// add one shirt sized 2 | |
// choose size, quantity | |
selectFrom('select.product-size', '2', 'select size 2', assert); | |
selectFrom('select.product-qty', 1, 'select quantity 1', assert); | |
return click('.add-to-cart'); | |
}); | |
andThen(() => { | |
// personal information | |
fillIn('input[name="full-name"]', person.fullName); | |
fillIn('input[name="email"]', person.email); | |
fillIn('input[name="email-confirmation"]', person.email); | |
fillIn('input[name="password"]', person.password); | |
// shipping information | |
fillIn('input[name="line1"]', address.line1); | |
fillIn('input[name="line2"]', address.line2); | |
fillIn('input[name="zip"]', address.zip); | |
fillIn('input[name="city"]', address.city); | |
fillIn('input[name="state"]', address.state); | |
selectFrom('select[name="country"]', address.country, assert); | |
// billing information | |
fillIn('input[name="cc-number"]', cc.number); | |
selectFrom('select[name="cc-exp-month"]', cc.exp_month, assert); | |
selectFrom('select[name="cc-exp-year"]', cc.exp_year, assert); | |
fillIn('input[name="cvc"]', cc.cvc); | |
fillIn('input[name="cc-zip"]', cc.address_zip); | |
return click('button.submit'); // the test doesn't keep forward from here | |
}); | |
andThen(() => { | |
debug('flag1'); // never executes | |
var store = this.App.__container__.lookup('controller:store'); | |
var customer = store.get('attrs.customer'); | |
var order = store.get('attrs.order'); | |
debug('flag2'); | |
// stripe acct created | |
assert.ok(customer.get('stripeAccount'), 'stripe id set'); | |
// order saved | |
assert.ok(order.get('id'), 'order id set'); | |
assert.equal(order.get('status'), '0', 'order paid'); | |
assert.ok(order.get('customer.id'), 'order has customer'); | |
assert.ok(order.get('address.id'), 'order has address'); | |
// redirects properly | |
assert.equal(currentRouteName(), 'store.checkout.success'); | |
assert.equal(currentPath(), 'store.checkout.success'); | |
assert.equal(currentURL(), '/checkout/success'); | |
}); | |
}); |
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
// submit action | |
actions: { | |
subscribe: function () { | |
var stripe = this.get('stripe'); | |
var address = this.get('currentModel.address'); | |
var customer = this.get('currentModel.customer'); | |
var order = this.get('currentModel.order'); | |
var cc = this.get('currentModel.cc'); | |
var card = cc.getProperties( | |
'number', | |
'exp_month', | |
'exp_year', | |
'cvc', | |
'address_zip' | |
); | |
stripe.createToken(card) | |
.then((response) => { | |
var token = response.id; | |
debug('tokenReceived', token); | |
cc.set('token', token); | |
customer.set('stripeToken', token); | |
return address.save(); | |
}) | |
.then(() => { | |
address.set('customer', customer); | |
return customer.save(); | |
}) | |
.then(() => { | |
debug('customer saved'); | |
return address.save(); | |
}) | |
.then(() => { | |
debug('address relationship saved'); | |
order.set('address', address); | |
order.set('customer', customer); | |
order.set('status', '12'); | |
return order.save(); | |
}) | |
.then(() => { | |
debug('order submitted with customer and address'); | |
debug('order status', order.get('status')); | |
if (order.get('status') === '0') { | |
debug('redirecting to success'); | |
this.transitionTo('store.checkout.success'); | |
} | |
}) | |
.catch((err) => { | |
debug('error caught', err); | |
this.submitErrorHandler(err); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment