Last active
January 13, 2017 21:34
-
-
Save mitchlloyd/15980bc78fbccae76f421f6e9c6e9c78 to your computer and use it in GitHub Desktop.
Wrap Third Party APIs - Fake
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'; | |
const { Service, RSVP } = Ember; | |
export default Service.extend({ | |
init() { | |
this._super(...arguments); | |
// We record both the charges sent and notifications sent to verify in | |
// our tests. | |
this.chargesSent = []; | |
this.notificationsSent = []; | |
}, | |
charge(payment) { | |
this.chargesSent.push(payment); | |
let notificationsSent = this.notificationsSent; | |
return new RSVP.Promise((resolve, reject) => { | |
resolve({ | |
result: { | |
// Here we use stubbed data, but you may consider passing this information | |
// into the fake to handle more test cases. | |
token: { id: 'fake-token-id' }, | |
shippingContact 'Fake Shipping Contact' | |
}, | |
notify: { | |
success() { | |
notificationsSent.push('success') | |
}, | |
failure() { | |
notificationsSent.push('failure') | |
} | |
} | |
}) | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment