| 73 | |
| 74 | #[test] |
| 75 | fn foreign_key_violation() { |
| 76 | let (state, cs) = setup(); |
| 77 | let validator = Validator::new(cs, 100); |
| 78 | |
| 79 | let change = ProposedChange { |
| 80 | collection: "posts".into(), |
| 81 | row_id: "p1".into(), |
| 82 | surrogate: nodedb_types::Surrogate::ZERO, |
| 83 | fields: vec![("author_id".into(), LoroValue::String("u1".into()))], |
| 84 | }; |
| 85 | |
| 86 | match validator.validate(&state, &change) { |
| 87 | ValidationOutcome::Rejected(v) => { |
| 88 | assert_eq!(v[0].constraint_name, "posts_author_fk"); |
| 89 | assert!(matches!( |
| 90 | v[0].hint, |
| 91 | CompensationHint::CreateReferencedRow { .. } |
| 92 | )); |
| 93 | } |
| 94 | _ => panic!("expected FK violation"), |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | #[test] |
| 99 | fn foreign_key_passes_when_parent_exists() { |