Skip to content

Commit 00a041e

Browse files
committed
Fix legacy publish endpoint
1 parent 6558f2c commit 00a041e

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

test/support/case.ex

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -369,38 +369,45 @@ defmodule HexTest.Case do
369369
Hex.State.put(:repos, repos)
370370
Hex.State.put(:api_url, "http://localhost:#{bypass.port}/api")
371371

372-
package_path = "/api/repos/#{repo}/packages/ecto"
373-
release_path = "/api/repos/#{repo}/publish"
374-
375372
Bypass.expect(bypass, fn conn ->
376-
case conn do
377-
%Plug.Conn{method: "GET", request_path: ^package_path} ->
378-
body = %{"meta" => %{"description" => "ecto description"}}
379-
380-
conn
381-
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
382-
|> Plug.Conn.resp(200, Hex.Utils.safe_serialize_erlang(body))
383-
384-
%Plug.Conn{method: "POST", request_path: ^release_path} ->
385-
body = %{"html_url" => "myrepo html_url"}
386-
387-
conn
388-
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
389-
|> Plug.Conn.resp(201, Hex.Utils.safe_serialize_erlang(body))
390-
391-
%Plug.Conn{method: "GET", request_path: "/api/users/me"} ->
373+
case {conn.method, conn.request_path} do
374+
{"GET", "/api/users/me"} ->
392375
body = %{"organizations" => [%{"name" => repo}]}
393376

394377
conn
395378
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
396379
|> Plug.Conn.resp(200, Hex.Utils.safe_serialize_erlang(body))
397380

398-
%Plug.Conn{method: "POST", request_path: "/api/keys"} ->
381+
{"POST", "/api/keys"} ->
399382
body = %{"secret" => "myrepo secret"}
400383

401384
conn
402385
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
403386
|> Plug.Conn.resp(201, Hex.Utils.safe_serialize_erlang(body))
387+
388+
{"GET", path} ->
389+
# Handle GET requests to /api/repos/:repo/packages/:package
390+
if String.contains?(path, "/packages/") and not String.contains?(path, "/releases") do
391+
body = %{"meta" => %{"description" => "package description"}}
392+
393+
conn
394+
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
395+
|> Plug.Conn.resp(200, Hex.Utils.safe_serialize_erlang(body))
396+
else
397+
Plug.Conn.resp(conn, 404, "")
398+
end
399+
400+
{"POST", path} ->
401+
# Handle POST requests to /api/repos/:repo/packages/:package/releases
402+
if String.contains?(path, "/packages/") and String.ends_with?(path, "/releases") do
403+
body = %{"html_url" => "myrepo html_url"}
404+
405+
conn
406+
|> Plug.Conn.put_resp_header("content-type", "application/vnd.hex+erlang")
407+
|> Plug.Conn.resp(201, Hex.Utils.safe_serialize_erlang(body))
408+
else
409+
Plug.Conn.resp(conn, 404, "")
410+
end
404411
end
405412
end)
406413

0 commit comments

Comments
 (0)