@@ -26,6 +26,8 @@ defmodule Console.GraphQl.BuildQueriesTest do
2626 test "It can sideload commands for a build" do
2727 build = insert ( :build )
2828 changelogs = insert_list ( 3 , :changelog , build: build )
29+ user = insert ( :user )
30+ setup_rbac ( user , [ build . repository ] , configure: true )
2931 commands = for i <- 1 .. 3 ,
3032 do: insert ( :command , build: build , inserted_at: Timex . now ( ) |> Timex . shift ( days: - i ) )
3133 expected = commands |> Enum . map ( & & 1 . id ) |> Enum . reverse ( )
@@ -49,12 +51,48 @@ defmodule Console.GraphQl.BuildQueriesTest do
4951 }
5052 }
5153 }
52- """ , % { "id" => build . id } , % { current_user: insert ( : user) } )
54+ """ , % { "id" => build . id } , % { current_user: user } )
5355
5456 assert found [ "id" ] == build . id
5557 assert found [ "creator" ] [ "id" ] == build . creator_id
5658 assert ids_equal ( found [ "changelogs" ] , changelogs )
5759 assert from_connection ( found [ "commands" ] ) |> Enum . map ( & & 1 [ "id" ] ) == expected
5860 end
61+
62+ test "users w/o perms cannot sideload changelogs" do
63+ user = insert ( :user )
64+ build = insert ( :build )
65+ setup_rbac ( user , [ "other" ] , configure: true )
66+ insert_list ( 3 , :changelog , build: build )
67+ commands = for i <- 1 .. 3 ,
68+ do: insert ( :command , build: build , inserted_at: Timex . now ( ) |> Timex . shift ( days: - i ) )
69+ expected = commands |> Enum . map ( & & 1 . id ) |> Enum . reverse ( )
70+
71+ { :ok , % { data: % { "build" => found } , errors: [ _ | _ ] } } = run_query ( """
72+ query Build($id: ID!) {
73+ build(id: $id) {
74+ id
75+ creator {
76+ id
77+ }
78+ changelogs {
79+ id
80+ }
81+ commands(first: 10) {
82+ edges {
83+ node {
84+ id
85+ }
86+ }
87+ }
88+ }
89+ }
90+ """ , % { "id" => build . id } , % { current_user: user } )
91+
92+ assert found [ "id" ] == build . id
93+ assert found [ "creator" ] [ "id" ] == build . creator_id
94+ refute found [ "changelogs" ]
95+ assert from_connection ( found [ "commands" ] ) |> Enum . map ( & & 1 [ "id" ] ) == expected
96+ end
5997 end
6098end
0 commit comments