Add tests

This commit is contained in:
Jorge Manrubia
2025-05-06 14:09:50 +02:00
parent 279a5be717
commit 863ced55c4
8 changed files with 74 additions and 4 deletions
+23
View File
@@ -0,0 +1,23 @@
require "test_helper"
class Command::GoToCardTest < ActionDispatch::IntegrationTest
include CommandTestHelper
setup do
@card = cards(:logo)
end
test "redirects to the card perma" do
result = execute_command "#{@card.id}"
assert_equal @card, result.url
end
test "results in a regular search if the card does not exist" do
command = parse_command "123"
assert command.valid?
result = command.execute
assert_equal cards_path(indexed_by: "newest", terms: [ "123" ]), result.url
end
end
+16
View File
@@ -0,0 +1,16 @@
require "test_helper"
class Command::GoToUserTest < ActionDispatch::IntegrationTest
include CommandTestHelper
test "redirects to the user perma" do
result = execute_command "@kevin"
assert_equal users(:kevin), result.url
end
test "results in an invalid command if the user does not exist" do
command = parse_command "@not_a_user"
assert !command.valid?
end
end
+1
View File
@@ -0,0 +1 @@
# The parser is tested through the tests of specific commands. See +Command::AssignTests+, etc.
+17
View File
@@ -0,0 +1,17 @@
require "test_helper"
class Command::SearchTest < ActionDispatch::IntegrationTest
include CommandTestHelper
test "redirects to the cards index filtering by search terms" do
result = execute_command "some text"
assert_equal cards_path(indexed_by: "newest", terms: [ "some text" ]), result.url
end
test "respects existing filters" do
result = execute_command "some text", context_url: "http://37signals.fizzy.localhost:3006/cards?collection_ids%5B%5D=#{collections(:writebook).id}"
assert_equal cards_path(indexed_by: "newest", collection_ids: [collections(:writebook).id], terms: [ "some text" ]), result.url
end
end