Skip to content

Commit

Permalink
refactor: move to minitest syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
seuros committed Jan 2, 2024
1 parent 6d7e1d9 commit 04c4438
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/trailblazer/finder/utils/hash_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'test_helper'

module Trailblazer
class Finder
module Utils
class HashTest < Minitest::Test
def setup
@hash = [{ id: 1, value: 'Test 1' }, { id: 2, value: 'Test 2' }, { id: 3, value: '' },
{ id: 4, value: 'Test 4' }]
end

def test_deep_locate
expected_result = [{ id: 2, value: 'Test 2' }]
actual_result = Hash.deep_locate(->(k, v, _) { k == :value && v.to_s == 'Test 2' && !v.nil? }, @hash)
assert_equal expected_result, actual_result
end

def test_returns_empty_when_nothing_found
expected_result = []
actual_result = Hash.deep_locate(:muff, foo: 'bar')
assert_equal expected_result, actual_result
end
end
end
end
end
35 changes: 35 additions & 0 deletions test/trailblazer/finder/utils/splitter_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'test_helper'

module Trailblazer
class Finder
module Utils
class SplitterTest < Minitest::Test
def test_initialize
splitter = Splitter.new 'attribute_eq', 'value'
assert_equal 'attribute_eq', splitter.key
assert_equal 'value', splitter.value
end

def test_split_key_exists
splitter = Splitter.new 'attribute_eq', 'value'
assert_equal false, splitter.split_key('random')
assert_equal true, splitter.split_key('eq')
end

def test_field_value_when_split_key_exists
splitter = Splitter.new 'attribute_eq', 'value'
splitter.split_key('eq')
assert_equal 'attribute', splitter.field
end

def test_predicate_value_when_split_key_exists
splitter = Splitter.new 'attribute_eq', 'value'
splitter.split_key('eq')
assert_equal :eq, splitter.predicate
end
end
end
end
end
56 changes: 56 additions & 0 deletions test/trailblazer/finder/utils/string_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# frozen_string_literal: true

require 'test_helper'
module Trailblazer
class Finder
module Utils
class StringTest < Minitest::Test
def test_blank
assert_equal true, String.blank?('')
assert_equal true, String.blank?(nil)
assert_equal false, String.blank?('what')
assert_equal false, String.blank?(1)
end

def test_numeric
assert_equal false, String.numeric?('')
assert_equal false, String.numeric?(nil)
assert_equal true, String.numeric?(1)
assert_equal true, String.numeric?(0)
assert_equal true, String.numeric?(1.00000)
assert_equal true, String.numeric?('1')
end

def test_date
assert_equal true, String.date?('2024-01-01')
assert_equal false, String.date?(nil)
assert_equal false, String.date?('random')
assert_equal false, String.date?(1)
assert_equal true, String.date?('2024/01/01')
assert_equal true, String.date?('2024.01.01')
assert_equal true, String.date?('21-12-2024')
assert_equal false, String.date?('0fae2de1-6537-4d36-9cdb-30edf1e37990')
end

def test_to_date
assert_equal '2024-09-28', String.to_date('28/09/2024')
assert_equal '2024-09-28', String.to_date('2024/09/28')
assert_equal '2024-09-28', String.to_date('28 september 2024')
assert_nil String.to_date('third month of this year')
end

def test_camelize
assert_equal 'Paging', String.camelize(:paging)
assert_equal 'SomeRandomTest', String.camelize(:some_random_test)
end

def test_underscore
assert_equal 'very_popular', String.underscore(:veryPopular)
assert_equal 'very_popular', String.underscore(:VeryPopular)
assert_equal 'somethingvery_popular_but_random', String.underscore(:SomethingveryPopularButRandom)
assert_equal 'very_popular', String.underscore('Very Popular')
end
end
end
end
end

0 comments on commit 04c4438

Please sign in to comment.