|
119 | 119 | "custom instructions new", |
120 | 120 | ) |
121 | 121 | end |
| 122 | + |
| 123 | + it "logs staff action when custom_instructions change" do |
| 124 | + put "/admin/plugins/discourse-ai/ai-spam.json", |
| 125 | + params: { |
| 126 | + is_enabled: true, |
| 127 | + llm_model_id: llm_model.id, |
| 128 | + custom_instructions: "updated instructions" |
| 129 | + } |
| 130 | + |
| 131 | + expect(response.status).to eq(200) |
| 132 | + |
| 133 | + # Verify the log was created with the right subject |
| 134 | + history = UserHistory.where(action: UserHistory.actions[:custom_staff], custom_type: "update_ai_spam_settings").last |
| 135 | + expect(history).to be_present |
| 136 | + expect(history.subject).to eq("AI Spam Detection") |
| 137 | + expect(history.details).to include("custom_instructions_changed") |
| 138 | + end |
| 139 | + |
| 140 | + it "logs staff action when llm_model_id changes" do |
| 141 | + # Create another model to change to |
| 142 | + new_llm_model = Fabricate(:llm_model, name: "New Test Model", display_name: "New Test Model") |
| 143 | + |
| 144 | + put "/admin/plugins/discourse-ai/ai-spam.json", |
| 145 | + params: { |
| 146 | + llm_model_id: new_llm_model.id |
| 147 | + } |
| 148 | + |
| 149 | + expect(response.status).to eq(200) |
| 150 | + |
| 151 | + # Verify the log was created with the right subject |
| 152 | + history = UserHistory.where(action: UserHistory.actions[:custom_staff], custom_type: "update_ai_spam_settings").last |
| 153 | + expect(history).to be_present |
| 154 | + expect(history.subject).to eq("AI Spam Detection") |
| 155 | + expect(history.details).to include("llm_model_id") |
| 156 | + end |
| 157 | + |
| 158 | + it "does not log staff action when only is_enabled changes" do |
| 159 | + # Check initial count of logs |
| 160 | + initial_count = UserHistory.where(action: UserHistory.actions[:custom_staff], custom_type: "update_ai_spam_settings").count |
| 161 | + |
| 162 | + # Update only the is_enabled setting |
| 163 | + put "/admin/plugins/discourse-ai/ai-spam.json", |
| 164 | + params: { |
| 165 | + is_enabled: false |
| 166 | + } |
| 167 | + |
| 168 | + expect(response.status).to eq(200) |
| 169 | + |
| 170 | + # Verify no new log was created |
| 171 | + current_count = UserHistory.where(action: UserHistory.actions[:custom_staff], custom_type: "update_ai_spam_settings").count |
| 172 | + expect(current_count).to eq(initial_count) |
| 173 | + end |
| 174 | + |
| 175 | + it "logs both custom_instructions and llm_model_id changes in one entry" do |
| 176 | + # Create another model to change to |
| 177 | + new_llm_model = Fabricate(:llm_model, name: "Another Test Model", display_name: "Another Test Model") |
| 178 | + |
| 179 | + put "/admin/plugins/discourse-ai/ai-spam.json", |
| 180 | + params: { |
| 181 | + llm_model_id: new_llm_model.id, |
| 182 | + custom_instructions: "new instructions for both changes" |
| 183 | + } |
| 184 | + |
| 185 | + expect(response.status).to eq(200) |
| 186 | + |
| 187 | + # Verify the log was created with all changes |
| 188 | + history = UserHistory.where(action: UserHistory.actions[:custom_staff], custom_type: "update_ai_spam_settings").last |
| 189 | + expect(history).to be_present |
| 190 | + expect(history.subject).to eq("AI Spam Detection") |
| 191 | + expect(history.details).to include("llm_model_id") |
| 192 | + expect(history.details).to include("custom_instructions_changed") |
| 193 | + end |
122 | 194 | end |
123 | 195 | end |
124 | 196 | end |
|
0 commit comments