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.4.25 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.2 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.24 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.1 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.23 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.22 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.0 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.21 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.5.0.beta.1 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.20 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.19 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.18 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.17 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.16 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.15 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.14 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.13 test/view_models/workarea/admin/code_list_view_model_test.rb
workarea-admin-3.4.12 test/view_models/workarea/admin/code_list_view_model_test.rb