Sha256: 15bfd21af390363a310687f37e6453ee8bae893c66b15c6a89193f606fab33e7

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

require 'test_helper'

module Workarea
  module Storefront
    class PurchaseGiftCardIntegrationTest < Workarea::IntegrationTest
      include Storefront::IntegrationTest

      def test_generates_gift_card
        pass && (return) unless Workarea::GiftCards.uses_system_cards?

        product = create_product(
          name: 'Gift Card',
          gift_card: true,
          customizations: 'gift_card',
          variants: [{ sku: 'GIFTCARD', regular: 10.to_m }]
        )

        create_fulfillment_sku(id: 'GIFTCARD', policy: :create_gift_card)

        post storefront.cart_items_path,
             params: {
               product_id: product.id,
               sku:        product.skus.first,
               email:      'recipient@workarea.com',
               from:       'from@workarea.com',
               message:    'this is a message',
               quantity:   1
             }

        complete_checkout

        assert_equal(1, Payment::GiftCard.count)

        card = Payment::GiftCard.first
        assert_equal(10.to_m, card.amount)
        assert_equal(0.to_m, card.used)
        assert_equal(10.to_m, card.balance)
        assert(card.order_id.present?)
        assert(card.purchased?)

        assert_equal(2, ActionMailer::Base.deliveries.length)

        gift_card_email = ActionMailer::Base.deliveries.detect do |email|
          assert_includes(email.to, 'recipient@workarea.com')
        end

        gift_card_email.parts.each do |part|
          assert_includes(part.body, card.token)
          assert_includes(part.body, 'from@workarea.com')
          assert_includes(part.body, 'this is a message')
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
workarea-gift_cards-4.0.1 test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb
workarea-gift_cards-4.0.0 test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb
workarea-gift_cards-4.0.0.beta.1 test/integration/workarea/storefront/purchase_gift_cards_integration_test.rb