|
50 | 50 | ) |
51 | 51 | end |
52 | 52 |
|
| 53 | + fab!(:admin_key_value) do |
| 54 | + Fabricate( |
| 55 | + :ai_artifact_key_value, |
| 56 | + ai_artifact: artifact, |
| 57 | + user: admin, |
| 58 | + key: "admin_key", |
| 59 | + value: "admin_value", |
| 60 | + public: false, |
| 61 | + ) |
| 62 | + end |
| 63 | + |
53 | 64 | context "when not logged in" do |
54 | 65 | it "returns only public key values" do |
55 | | - get "/discourse-ai/ai-bot/artifact-key-values/#{artifact.id}.json" |
| 66 | + get "/discourse-ai/ai-bot/artifact-key-values/#{artifact.id}.json", |
| 67 | + params: { |
| 68 | + all_users: true, |
| 69 | + } |
56 | 70 |
|
57 | 71 | expect(response.status).to eq(200) |
58 | 72 | json = response.parsed_body |
|
86 | 100 | before { sign_in(user) } |
87 | 101 |
|
88 | 102 | it "returns public key values and own private key values" do |
89 | | - get "/discourse-ai/ai-bot/artifact-key-values/#{artifact.id}.json" |
| 103 | + get "/discourse-ai/ai-bot/artifact-key-values/#{artifact.id}.json", |
| 104 | + params: { |
| 105 | + all_users: true, |
| 106 | + } |
90 | 107 |
|
91 | 108 | expect(response.status).to eq(200) |
92 | 109 | json = response.parsed_body |
|
138 | 155 | context "when logged in as admin" do |
139 | 156 | before { sign_in(admin) } |
140 | 157 |
|
141 | | - it "returns all key values including private ones from other users" do |
| 158 | + it "returns only my own keys by default" do |
142 | 159 | get "/discourse-ai/ai-bot/artifact-key-values/#{artifact.id}.json" |
143 | 160 |
|
144 | 161 | expect(response.status).to eq(200) |
145 | 162 | json = response.parsed_body |
146 | | - expect(json["key_values"].length).to eq(3) |
147 | | - expect(json["key_values"].map { |kv| kv["key"] }).to contain_exactly( |
148 | | - "test_key", |
149 | | - "private_key", |
150 | | - "other_key", |
151 | | - ) |
| 163 | + expect(json["key_values"].length).to eq(1) |
| 164 | + expect(json["key_values"].map { |kv| kv["key"] }).to contain_exactly("admin_key") |
152 | 165 | end |
153 | 166 |
|
154 | 167 | it "can access private artifacts" do |
|
420 | 433 | end |
421 | 434 | end |
422 | 435 | end |
423 | | - |
424 | | - describe "private methods" do |
425 | | - let(:controller) { described_class.new } |
426 | | - |
427 | | - before do |
428 | | - controller.instance_variable_set(:@artifact, artifact) |
429 | | - allow(controller).to receive(:params).and_return( |
430 | | - ActionController::Parameters.new(test_params), |
431 | | - ) |
432 | | - end |
433 | | - |
434 | | - describe "#key_value_params" do |
435 | | - let(:test_params) { { key: "test", value: "value", public: true, extra: "ignored" } } |
436 | | - |
437 | | - it "permits only allowed parameters" do |
438 | | - # This would need to be tested by calling the actual method or through integration tests |
439 | | - # since private methods are typically tested through their public interfaces |
440 | | - end |
441 | | - end |
442 | | - end |
443 | 436 | end |
0 commit comments