|
267 | 267 | end |
268 | 268 | end |
269 | 269 | end |
| 270 | + |
| 271 | + describe "government observation validations" do |
| 272 | + it "should be invalid when government observation has operator_id" do |
| 273 | + country = create(:country) |
| 274 | + observation = build(:gov_observation, country: country) |
| 275 | + observation.operator = create(:operator, country: country) |
| 276 | + |
| 277 | + expect(observation.valid?).to eq(false) |
| 278 | + expect(observation.errors[:operator_id]).to include("must be blank") |
| 279 | + end |
| 280 | + end |
| 281 | + |
| 282 | + describe "required fields for non-Created and non-Rejected statuses" do |
| 283 | + it "allows missing required fields when status is Created or Rejected" do |
| 284 | + created_obs = build(:observation, |
| 285 | + validation_status: "Created", |
| 286 | + subcategory: nil, |
| 287 | + severity: nil, |
| 288 | + observation_report: nil, |
| 289 | + evidence_type: nil) |
| 290 | + expect(created_obs).to be_valid |
| 291 | + |
| 292 | + rejected_obs = build(:observation, |
| 293 | + validation_status: "Rejected", |
| 294 | + subcategory: nil, |
| 295 | + severity: nil, |
| 296 | + observation_report: nil, |
| 297 | + evidence_type: nil) |
| 298 | + expect(rejected_obs).to be_valid |
| 299 | + end |
| 300 | + |
| 301 | + it "requires subcategory, severity, observation_report, and evidence_type for other statuses" do |
| 302 | + observation = build(:observation, |
| 303 | + validation_status: "Ready for QC2", |
| 304 | + subcategory: nil, |
| 305 | + severity: nil, |
| 306 | + observation_report: nil, |
| 307 | + evidence_type: nil) |
| 308 | + |
| 309 | + expect(observation.valid?).to eq(false) |
| 310 | + expect(observation.errors[:subcategory]).to include("can't be blank") |
| 311 | + expect(observation.errors[:severity]).to include("can't be blank") |
| 312 | + expect(observation.errors[:observation_report]).to include("can't be blank") |
| 313 | + expect(observation.errors[:evidence_type]).to include("can't be blank") |
| 314 | + end |
| 315 | + end |
270 | 316 | end |
271 | 317 |
|
272 | 318 | describe "Hooks" do |
|
0 commit comments