overleaf/services/web/test/acceptance/src/helpers/RecurlySubscription.js
Eric Mc Sween d0fc8d90e5 Merge pull request #2119 from overleaf/ta-subscription-deletion
Store Deleted Subscriptions

GitOrigin-RevId: c7004f1807dee6b6ec82eeb2a8fe939801ce3e8b
2019-09-09 12:05:23 +00:00

39 lines
1 KiB
JavaScript

const { ObjectId } = require('../../../../app/src/infrastructure/mongojs')
const Subscription = require('./Subscription')
const MockRecurlyApi = require('./MockRecurlyApi')
const RecurlyWrapper = require('../../../../app/src/Features/Subscription/RecurlyWrapper')
class RecurlySubscription {
constructor(options = {}) {
this.subscription = new Subscription(options)
this.uuid = ObjectId().toString()
this.accountId = this.subscription.admin_id.toString()
this.state = options.state || 'active'
}
ensureExists(callback) {
this.subscription.ensureExists(error => {
if (error) {
return callback(error)
}
MockRecurlyApi.addSubscription({
uuid: this.uuid,
account_id: this.accountId,
state: this.state
})
MockRecurlyApi.addAccount({ id: this.accountId })
callback()
})
}
buildCallbackXml() {
return RecurlyWrapper._buildXml('expired_subscription_notification', {
subscription: {
uuid: this.uuid
}
})
}
}
module.exports = RecurlySubscription