diff --git a/test/api/v3/unit/libs/payments.test.js b/test/api/v3/unit/libs/payments.test.js index fbe82377ac..058f312125 100644 --- a/test/api/v3/unit/libs/payments.test.js +++ b/test/api/v3/unit/libs/payments.test.js @@ -191,7 +191,7 @@ describe('payments/index', () => { await api.createSubscription(data); let msg = '\`Hello recipient, sender has sent you 3 months of subscription!\`'; - expect(user.sendMessage).to.be.calledOnce; + expect(user.sendMessage).to.be.calledTwice; expect(user.sendMessage).to.be.calledWith(recipient, { receiverMsg: msg, senderMsg: msg }); }); @@ -229,6 +229,77 @@ describe('payments/index', () => { }, }); }); + + context('Winter 2017-18 Gift-1-Get-1 Promotion', async () => { + it('creates a gift subscription for purchaser and recipient if none exist', async () => { + await api.createSubscription(data); + + expect(user.items.pets['Jackalope-RoyalPurple']).to.eql(5); + expect(user.purchased.plan.customerId).to.eql('Gift'); + expect(user.purchased.plan.dateTerminated).to.exist; + expect(user.purchased.plan.dateUpdated).to.exist; + expect(user.purchased.plan.dateCreated).to.exist; + + expect(recipient.items.pets['Jackalope-RoyalPurple']).to.eql(5); + expect(recipient.purchased.plan.customerId).to.eql('Gift'); + expect(recipient.purchased.plan.dateTerminated).to.exist; + expect(recipient.purchased.plan.dateUpdated).to.exist; + expect(recipient.purchased.plan.dateCreated).to.exist; + }); + + it('adds extraMonths to existing subscription for purchaser and creates a gift subscription for recipient without sub', async () => { + user.purchased.plan = plan; + + expect(user.purchased.plan.extraMonths).to.eql(0); + + await api.createSubscription(data); + + expect(user.purchased.plan.extraMonths).to.eql(3); + + expect(recipient.items.pets['Jackalope-RoyalPurple']).to.eql(5); + expect(recipient.purchased.plan.customerId).to.eql('Gift'); + expect(recipient.purchased.plan.dateTerminated).to.exist; + expect(recipient.purchased.plan.dateUpdated).to.exist; + expect(recipient.purchased.plan.dateCreated).to.exist; + }); + + it('adds extraMonths to existing subscription for recipient and creates a gift subscription for purchaser without sub', async () => { + recipient.purchased.plan = plan; + + expect(recipient.purchased.plan.extraMonths).to.eql(0); + + await api.createSubscription(data); + + expect(recipient.purchased.plan.extraMonths).to.eql(3); + + expect(user.items.pets['Jackalope-RoyalPurple']).to.eql(5); + expect(user.purchased.plan.customerId).to.eql('Gift'); + expect(user.purchased.plan.dateTerminated).to.exist; + expect(user.purchased.plan.dateUpdated).to.exist; + expect(user.purchased.plan.dateCreated).to.exist; + }); + + it('adds extraMonths to existing subscriptions for purchaser and recipient', async () => { + user.purchased.plan = plan; + recipient.purchased.plan = plan; + + expect(user.purchased.plan.extraMonths).to.eql(0); + expect(recipient.purchased.plan.extraMonths).to.eql(0); + + await api.createSubscription(data); + + expect(user.purchased.plan.extraMonths).to.eql(3); + expect(recipient.purchased.plan.extraMonths).to.eql(3); + }); + + it('sends a private message about the promotion', async () => { + await api.createSubscription(data); + let msg = '\`Hello sender, you received 3 months of subscription as part of our holiday gift-giving promotion!\`'; + + expect(user.sendMessage).to.be.calledTwice; + expect(user.sendMessage).to.be.calledWith(user, { senderMsg: msg }); + }); + }); }); context('Purchasing a subscription for self', () => { diff --git a/website/client/components/payments/sendGemsModal.vue b/website/client/components/payments/sendGemsModal.vue index c1b10acf98..fe227d2440 100644 --- a/website/client/components/payments/sendGemsModal.vue +++ b/website/client/components/payments/sendGemsModal.vue @@ -31,11 +31,17 @@ b-modal#send-gems(:title="title", :hide-footer="true", size='lg') ) h3.panel-heading {{ $t('subscription') }} .panel-body - .form-group - .radio(v-for='block in subscriptionBlocks', v-if="block.target !== 'group' && block.canSubscribe === true") - label - input(type="radio", name="subRadio", :value="block.key", v-model='gift.subscription.key') - | {{ $t('sendGiftSubscription', {price: block.price, months: block.months}) }} + .row + .col-md-4 + .form-group + .radio(v-for='block in subscriptionBlocks', v-if="block.target !== 'group' && block.canSubscribe === true") + label + input(type="radio", name="subRadio", :value="block.key", v-model='gift.subscription.key') + | {{ $t('sendGiftSubscription', {price: block.price, months: block.months}) }} + .col-md-8 + h4 {{ $t('winterPromoGiftHeader') }} + p {{ $t('winterPromoGiftDetails1') }} + p {{ $t('winterPromoGiftDetails2') }} textarea.form-control(rows='3', v-model='gift.message', :placeholder="$t('sendGiftMessagePlaceholder')") //include ../formatting-help diff --git a/website/client/components/settings/subscription.vue b/website/client/components/settings/subscription.vue index 787028630e..5b2761ecbb 100644 --- a/website/client/components/settings/subscription.vue +++ b/website/client/components/settings/subscription.vue @@ -90,6 +90,11 @@ li {{ $t('giftSubscriptionText2') }} li {{ $t('giftSubscriptionText3') }} h4 {{ $t('giftSubscriptionText4') }} + .col-6 + h2 {{ $t('winterPromoGiftHeader') }} + p {{ $t('winterPromoGiftDetails1') }} + p {{ $t('winterPromoGiftDetails2') }} +