Lightweight invoice purchases show description on PaymentsView

This commit is contained in:
Scott Erickson 2016-05-06 11:43:54 -07:00
parent 6916de6c8b
commit 3ad395ecb8
5 changed files with 40 additions and 8 deletions

View file

@ -0,0 +1,7 @@
Payment = require 'models/Payment'
CocoCollection = require 'collections/CocoCollection'
module.exports = class Payments extends CocoCollection
model: Payment
url: '/db/payment'

View file

@ -10,7 +10,8 @@ block content
a(href="/account", data-i18n="nav.account")
li.active(data-i18n="account.payments")
if view.payments.models.length
- console.log('render', view.payments.size())
if view.payments.size()
table.table.table-striped
tr
th(data-i18n="account.purchased")
@ -21,7 +22,9 @@ block content
for payment in view.payments.models
- var service = payment.get('service')
tr
if payment.get('productID')
if payment.get('productID') === 'custom'
td= payment.get('description')
else if payment.get('productID')
td(data-i18n='account.gems')
else
td(data-i18n='subscribe.stripe_description')
@ -32,4 +35,4 @@ block content
else
td(data-i18n="account.service_web")
td $#{(payment.get('amount')/100).toFixed(2)}
td= payment.get('gems')
td= payment.get('gems') || '-'

View file

@ -1,13 +1,12 @@
RootView = require 'views/core/RootView'
template = require 'templates/account/payments-view'
CocoCollection = require 'collections/CocoCollection'
Payment = require 'models/Payment'
Payments = require 'collections/Payments'
module.exports = class PaymentsView extends RootView
id: "payments-view"
template: template
constructor: (options) ->
super(options)
@payments = new CocoCollection([], { url: '/db/payment', model: Payment, comparator:'_id' })
@supermodel.loadCollection(@payments, 'payments', {cache: false})
initialize: ->
@payments = new Payments()
@supermodel.trackRequest(@payments.fetch({cache: false}))

View file

@ -140,6 +140,13 @@ module.exports = {
name: _.string.humanize(_id)
}, attrs)
return new ThangType(attrs)
makePayment: (attrs, sources={}) ->
_id = _.uniqueId('payment_')
attrs = _.extend({}, {
_id
}, attrs)
return new ThangType(attrs)
}

View file

@ -0,0 +1,16 @@
PaymentsView = require 'views/account/PaymentsView'
Payments = require 'collections/Payments'
factories = require 'test/app/factories'
describe 'PaymentsView', ->
it 'displays the payment "description" if the payment\'s productID is "custom"', ->
view = new PaymentsView()
payment = factories.makePayment({productID: 'custom', description: 'Custom Description' })
view.payments.fakeRequests[0].respondWith({
status: 200
responseText: new Payments([payment]).stringify()
})
view.render()
expect(_.contains(view.$el.text(), 'Custom Description')).toBe(true)
jasmine.demoEl(view.$('#site-content-area'))