Skip to content

Commit

Permalink
lint a random file (#4042)
Browse files Browse the repository at this point in the history
  • Loading branch information
osc-bot authored Jan 2, 2025
1 parent 5efb65a commit c6a7304
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions apps/dashboard/test/apps/token_matcher_test.rb
Original file line number Diff line number Diff line change
@@ -1,74 +1,77 @@
# frozen_string_literal: true

require 'test_helper'

class TokenMatcherTest < ActiveSupport::TestCase
test 'token should return token parameter' do
target = TokenMatcher.new('sys/app')
assert_equal('sys/app', target.token)

test "token should return token parameter" do
target = TokenMatcher.new("sys/app")
assert_equal("sys/app" , target.token)

target = TokenMatcher.new({token: "sys/app", type: "sys"})
assert_equal({token: "sys/app", type: "sys"} , target.token)
target = TokenMatcher.new({ token: 'sys/app', type: 'sys' })
assert_equal({ token: 'sys/app', type: 'sys' }, target.token)
end

test "app token should match app" do
target = TokenMatcher.new("sys/app")
app = OodApp.new(Router.router_from_token("sys/app"))
test 'app token should match app' do
target = TokenMatcher.new('sys/app')
app = OodApp.new(Router.router_from_token('sys/app'))
assert_equal true, target.matches_app?(app)
end

test "app token should not match app with the same prefix" do
target = TokenMatcher.new("sys/app")
app = OodApp.new(Router.router_from_token("sys/app_prefix"))
test 'app token should not match app with the same prefix' do
target = TokenMatcher.new('sys/app')
app = OodApp.new(Router.router_from_token('sys/app_prefix'))
assert_equal false, target.matches_app?(app)
end

test "app token with asterisk should match app with the same prefix" do
target = TokenMatcher.new("sys/app*")
app = OodApp.new(Router.router_from_token("sys/app_prefix"))
test 'app token with asterisk should match app with the same prefix' do
target = TokenMatcher.new('sys/app*')
app = OodApp.new(Router.router_from_token('sys/app_prefix'))
assert_equal true, target.matches_app?(app)
end

test "app token should match sub app" do
target = TokenMatcher.new("sys/app")
app = BatchConnect::App.from_token("sys/app/sub_app")
test 'app token should match sub app' do
target = TokenMatcher.new('sys/app')
app = BatchConnect::App.from_token('sys/app/sub_app')
assert_equal true, target.matches_app?(app)
end

test "app token with trailing slash should match sub app" do
target = TokenMatcher.new("sys/app/")
app = BatchConnect::App.from_token("sys/app/sub_app")
test 'app token with trailing slash should match sub app' do
target = TokenMatcher.new('sys/app/')
app = BatchConnect::App.from_token('sys/app/sub_app')
assert_equal true, target.matches_app?(app)
end

test "sub app token should match sub app" do
target = TokenMatcher.new("sys/app/sub_app")
app = BatchConnect::App.from_token("sys/app/sub_app")
test 'sub app token should match sub app' do
target = TokenMatcher.new('sys/app/sub_app')
app = BatchConnect::App.from_token('sys/app/sub_app')
assert_equal true, target.matches_app?(app)
end

test "sub app token should not match different sub app" do
target = TokenMatcher.new("sys/app/sub_app")
app = BatchConnect::App.from_token("sys/app/different_sub_app")
test 'sub app token should not match different sub app' do
target = TokenMatcher.new('sys/app/sub_app')
app = BatchConnect::App.from_token('sys/app/different_sub_app')
assert_equal false, target.matches_app?(app)
end

test "sub app token should not match app" do
target = TokenMatcher.new("sys/app/sub_app")
app = OodApp.new(Router.router_from_token("sys/app"))
test 'sub app token should not match app' do
target = TokenMatcher.new('sys/app/sub_app')
app = OodApp.new(Router.router_from_token('sys/app'))
assert_equal false, target.matches_app?(app)
end


test "type, category, and subcategory should not trigger metadata match" do
%i[other items should match].each do |item|
target = TokenMatcher.new({ item => "value" })
assert_equal true, target.matchers.any?{|matcher| matcher == 'metadata_match?'}, "Expected field: #{item} to create a metadata_match? matcher"
test 'type, category, and subcategory should not trigger metadata match' do
[:other, :items, :should, :match].each do |item|
target = TokenMatcher.new({ item => 'value' })
assert_equal true, target.matchers.any? { |matcher|
matcher == 'metadata_match?'
}, "Expected field: #{item} to create a metadata_match? matcher"
end

%i[type category subcategory].each do |item|
target = TokenMatcher.new({ item => "value" })
assert_equal false, target.matchers.any?{|matcher| matcher == 'metadata_match?'}, "Expected field: #{item} not to create a metadata_match? matcher"
[:type, :category, :subcategory].each do |item|
target = TokenMatcher.new({ item => 'value' })
assert_equal false, target.matchers.any? { |matcher|
matcher == 'metadata_match?'
}, "Expected field: #{item} not to create a metadata_match? matcher"
end
end

end
end

0 comments on commit c6a7304

Please sign in to comment.