Sha256: 1e5e7dd74a7dd3272ae9838813b15d8f05169dd7778c105c288a06ca1c049ae9

Contents?: true

Size: 1.31 KB

Versions: 8

Compression:

Stored size: 1.31 KB

Contents

require 'test_helper'

module Workarea
  class UpdateEmailTest < TestCase
    def test_updating_payment_profile
      user = create_user(email: 'user@workarea.com')
      profile = Payment::Profile.lookup(PaymentReference.new(user))

      UpdateEmail.new.perform(user.id.to_s, 'email' => [nil, 'user@workarea.com'])
      assert_equal(profile.reload.email, 'user@workarea.com')

      UpdateEmail.new.perform(
        user.id.to_s,
        'email' => ['user@workarea.com', 'test@workarea.com']
      )
      assert_equal(profile.reload.email, 'test@workarea.com')
    end

    def test_updating_metrics
      user = create_user(email: 'user@workarea.com')
      old_metrics = Metrics::User.find_or_initialize_by(id: 'user@workarea.com')
      old_metrics.update!(orders: 3)

      UpdateEmail.new.perform(user.id.to_s, 'email' => [nil, 'user@workarea.com'])
      assert_equal(1, Metrics::User.count)
      assert_equal(3, old_metrics.reload.orders)

      new_metrics = Metrics::User.create!(id: 'test@workarea.com', orders: 1)

      UpdateEmail.new.perform(
        user.id.to_s,
        'email' => ['user@workarea.com', 'test@workarea.com']
      )
      assert_equal(1, Metrics::User.count)
      assert_raises(Mongoid::Errors::DocumentNotFound) { old_metrics.reload }
      assert_equal(4, new_metrics.reload.orders)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
workarea-core-3.5.27 test/workers/workarea/update_email_test.rb
workarea-core-3.5.26 test/workers/workarea/update_email_test.rb
workarea-core-3.4.45 test/workers/workarea/update_email_test.rb
workarea-core-3.5.25 test/workers/workarea/update_email_test.rb
workarea-core-3.5.23 test/workers/workarea/update_email_test.rb
workarea-core-3.4.44 test/workers/workarea/update_email_test.rb
workarea-core-3.5.22 test/workers/workarea/update_email_test.rb
workarea-core-3.4.43 test/workers/workarea/update_email_test.rb