Skip to content

Commit 2a753c0

Browse files
committed
334 - added more tests
1 parent 8126cdd commit 2a753c0

File tree

3 files changed

+183
-0
lines changed

3 files changed

+183
-0
lines changed

lib/rig_api/v1/apis_test.exs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,67 @@ defmodule RigApi.V1.APIsTest do
374374
}
375375
end
376376

377+
test "should return 400 when 'endpoint' has 'path' and 'path_regex' set at the same time" do
378+
endpoints = [
379+
%{
380+
"id" => @invalid_config_id <> "1",
381+
"method" => "GET",
382+
"path" => "/",
383+
"path_regex" => "/"
384+
}
385+
]
386+
387+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
388+
conn = build_conn() |> put("/v1/apis/#{@invalid_config_id}", new_api)
389+
response = json_response(conn, 400)
390+
391+
assert response == %{
392+
"invalid-config/invalid-config1" => [
393+
%{"path, path_regex" => "You can't set path and path_regex at the same time"}
394+
]
395+
}
396+
end
397+
398+
test "should return 400 when when 'path' is set, but incorrect" do
399+
endpoints = [
400+
%{
401+
"id" => @invalid_config_id <> "1",
402+
"method" => "GET",
403+
"path" => ""
404+
}
405+
]
406+
407+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
408+
conn = build_conn() |> put("/v1/apis/#{@invalid_config_id}", new_api)
409+
response = json_response(conn, 400)
410+
411+
assert response == %{
412+
"invalid-config/invalid-config1" => [
413+
%{"path" => "must have a length of at least 1"}
414+
]
415+
}
416+
end
417+
418+
test "should return 400 when when 'path_regex' is set, but incorrect" do
419+
endpoints = [
420+
%{
421+
"id" => @invalid_config_id <> "1",
422+
"method" => "GET",
423+
"path_regex" => ""
424+
}
425+
]
426+
427+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
428+
conn = build_conn() |> put("/v1/apis/#{@invalid_config_id}", new_api)
429+
response = json_response(conn, 400)
430+
431+
assert response == %{
432+
"invalid-config/invalid-config1" => [
433+
%{"path_regex" => "must have a length of at least 1"}
434+
]
435+
}
436+
end
437+
377438
test "should return 400 when target is set to kafka or kinesis, but topic is not" do
378439
# kinesis topic not set
379440
endpoints = [

lib/rig_api/v2/apis_test.exs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,67 @@ defmodule RigApi.V2.APIsTest do
374374
}
375375
end
376376

377+
test "should return 400 when 'endpoint' has 'path' and 'path_regex' set at the same time" do
378+
endpoints = [
379+
%{
380+
"id" => @invalid_config_id <> "1",
381+
"method" => "GET",
382+
"path" => "/",
383+
"path_regex" => "/"
384+
}
385+
]
386+
387+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
388+
conn = build_conn() |> put("/v2/apis/#{@invalid_config_id}", new_api)
389+
response = json_response(conn, 400)
390+
391+
assert response == %{
392+
"invalid-config/invalid-config1" => [
393+
%{"path, path_regex" => "You can't set path and path_regex at the same time"}
394+
]
395+
}
396+
end
397+
398+
test "should return 400 when when 'path' is set, but incorrect" do
399+
endpoints = [
400+
%{
401+
"id" => @invalid_config_id <> "1",
402+
"method" => "GET",
403+
"path" => ""
404+
}
405+
]
406+
407+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
408+
conn = build_conn() |> put("/v2/apis/#{@invalid_config_id}", new_api)
409+
response = json_response(conn, 400)
410+
411+
assert response == %{
412+
"invalid-config/invalid-config1" => [
413+
%{"path" => "must have a length of at least 1"}
414+
]
415+
}
416+
end
417+
418+
test "should return 400 when when 'path_regex' is set, but incorrect" do
419+
endpoints = [
420+
%{
421+
"id" => @invalid_config_id <> "1",
422+
"method" => "GET",
423+
"path_regex" => ""
424+
}
425+
]
426+
427+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
428+
conn = build_conn() |> put("/v2/apis/#{@invalid_config_id}", new_api)
429+
response = json_response(conn, 400)
430+
431+
assert response == %{
432+
"invalid-config/invalid-config1" => [
433+
%{"path_regex" => "must have a length of at least 1"}
434+
]
435+
}
436+
end
437+
377438
test "should return 400 when target is set to kafka or kinesis, but topic is not" do
378439
# kinesis topic not set
379440
endpoints = [

lib/rig_api/v3/apis_test.exs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,67 @@ defmodule RigApi.V3.APIsTest do
374374
}
375375
end
376376

377+
test "should return 400 when 'endpoint' has 'path' and 'path_regex' set at the same time" do
378+
endpoints = [
379+
%{
380+
"id" => @invalid_config_id <> "1",
381+
"method" => "GET",
382+
"path" => "/",
383+
"path_regex" => "/"
384+
}
385+
]
386+
387+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
388+
conn = build_conn() |> put("/v3/apis/#{@invalid_config_id}", new_api)
389+
response = json_response(conn, 400)
390+
391+
assert response == %{
392+
"invalid-config/invalid-config1" => [
393+
%{"path, path_regex" => "You can't set path and path_regex at the same time"}
394+
]
395+
}
396+
end
397+
398+
test "should return 400 when when 'path' is set, but incorrect" do
399+
endpoints = [
400+
%{
401+
"id" => @invalid_config_id <> "1",
402+
"method" => "GET",
403+
"path" => ""
404+
}
405+
]
406+
407+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
408+
conn = build_conn() |> put("/v3/apis/#{@invalid_config_id}", new_api)
409+
response = json_response(conn, 400)
410+
411+
assert response == %{
412+
"invalid-config/invalid-config1" => [
413+
%{"path" => "must have a length of at least 1"}
414+
]
415+
}
416+
end
417+
418+
test "should return 400 when when 'path_regex' is set, but incorrect" do
419+
endpoints = [
420+
%{
421+
"id" => @invalid_config_id <> "1",
422+
"method" => "GET",
423+
"path_regex" => ""
424+
}
425+
]
426+
427+
new_api = ProxyConfig.create_proxy_config(@invalid_config_id, endpoints)
428+
conn = build_conn() |> put("/v3/apis/#{@invalid_config_id}", new_api)
429+
response = json_response(conn, 400)
430+
431+
assert response == %{
432+
"invalid-config/invalid-config1" => [
433+
%{"path_regex" => "must have a length of at least 1"}
434+
]
435+
}
436+
end
437+
377438
test "should return 400 when target is set to kafka or kinesis, but topic is not" do
378439
# kinesis topic not set
379440
endpoints = [

0 commit comments

Comments
 (0)