Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint a random file #4042

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading