summaryrefslogtreecommitdiff
path: root/spec/features/admin/subscriptions_spec.rb
blob: 1d9f6985a809c529d9d9553ef05aaa4fcaa7703a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
RSpec.describe 'Subscriptions admin' do
  stub_authorization!

  let(:shipping_address_fieldset) { 'Shipping Address' }
  let(:billing_address_fieldset) { 'Billing Address' }

  it 'Updating a subscription' do
    subscription = create(:subscription, :with_shipping_address, :with_billing_address)

    visit spree.admin_path
    click_link 'Subscriptions'
    find('.fa-edit').click
    within_fieldset(shipping_address_fieldset) do
      fill_in 'Zip Code', with: '33166'
    end
    within_fieldset(billing_address_fieldset) do
      fill_in 'Zip Code', with: '33167'
    end
    click_button 'Update'
    subscription.reload

    expect(subscription.shipping_address.zipcode).to eq('33166')
    expect(subscription.billing_address.zipcode).to eq('33167')
  end

  it 'Creates a subscription' do
    variant = create(:variant, subscribable: true)
    create(:user)
    create(:store)

    visit spree.admin_path
    click_link 'Subscriptions'
    click_link 'New Subscription'
    fill_in 'Actionable date', with: '01/01/2020'
    fill_in 'Interval length', with: 2
    fill_in 'End date', with: '01/03/2020'

    [shipping_address_fieldset, billing_address_fieldset].each do |fieldset|
      within_fieldset(fieldset) do
        name_input_label = if Spree.solidus_gem_version >= Gem::Version.new('2.11.0')
                             'Name'
                           else
                             'First Name'
                           end

        fill_in name_input_label, with: 'John Doe'
        fill_in 'Street Address', with: 'Street Address'
        fill_in 'City', with: 'City'
        fill_in 'Zip Code', with: '33166'
        fill_in 'Phone', with: '1234567890'
      end
    end

    select variant.name, from: 'Subscribable'
    fill_in 'Quantity', with: 1

    expect { click_on 'Create' }.to change { SolidusSubscriptions::Subscription.count }.by(1)

    expect(page).to have_text('Subscription has been successfully created!')
  end
end