Sha256: a32c69dcb49f33a8e9d3a43fb6c070e62eb3cd646db8e8711b0cc9f9a5bce61c

Contents?: true

Size: 1.15 KB

Versions: 38

Compression:

Stored size: 1.15 KB

Contents

require 'test_helper'

module Workarea
  module Admin
    class CodeListViewModelTest < TestCase
      setup :code_list

      def code_list
        @code_list ||= create_code_list(
          count: 4,
          prefix: 'test',
          expires_at: 1.day.from_now
        ).tap(&:generate_promo_codes!)
      end

      def test_used_count
        view_model = CodeListViewModel.wrap(code_list)
        assert_equal(0, view_model.used_count)

        code_list.promo_codes.sample.update(used_at: Time.now)

        view_model = CodeListViewModel.wrap(code_list)
        assert_equal(1, view_model.used_count)
      end

      def test_last_used_at
        view_model = CodeListViewModel.wrap(code_list)
        assert_nil(view_model.last_used_at)

        yesterday = 1.day.ago
        code_list.promo_codes.unused.sample.update(used_at: yesterday)

        view_model = CodeListViewModel.wrap(code_list)
        assert_equal(yesterday.to_i, view_model.last_used_at.to_i)

        code_list.promo_codes.unused.sample.used!

        view_model = CodeListViewModel.wrap(code_list)
        refute_equal(yesterday.to_i, view_model.last_used_at.to_i)
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
workarea-admin-3.5.13 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.34 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.12 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.33 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.11 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.10 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.32 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.9 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.31 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.8 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.30 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.7 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.29 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.6 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.28 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.5 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.27 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.4 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.26 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.3 test/view_models/workarea/admin/code_list_view_model_test.rb