fix(tests): insert prerequisite node/repo for FK constraints in db tests

Author: Aaron Steven White
Commit 3192bdaf777d4d5b63659efefd5525d079b93bb0
Parent: d3288dddac
Structural diff unavailable

These commits were pushed via plain git push, so no pre-parsed schemas are available. Install git-remote-cospan and re-push via panproto:// to see scope-level changes, breaking change detection, and semantic diffs.

brew install panproto/tap/git-remote-cospan
1 file changed +52 -0
@@ -84,9 +84,58 @@ async fn actor_profile_upsert_and_get(pool: PgPool) {
8484 
8585 // ─── Repos ───────────────────────────────────────────────────────
8686 
87+/// Insert a prerequisite node so repos can satisfy the node_did FK.
88+async fn insert_test_node(pool: &PgPool) {
89+    let now = Utc::now();
90+    db::node::upsert(
91+        pool,
92+        &db::node::NodeRow {
93+            did: "did:plc:node1".to_string(),
94+            rkey: "self".to_string(),
95+            public_endpoint: Some("https://node1.example.com".to_string()),
96+            created_at: now,
97+            indexed_at: now,
98+        },
99+    )
100+    .await
101+    .unwrap();
102+}
103+
104+/// Insert a prerequisite repo so child tables (ref_updates, issues, stars) can satisfy FKs.
105+async fn insert_test_repo(pool: &PgPool, did: &str, name: &str) {
106+    let now = Utc::now();
107+    insert_test_node(pool).await;
108+    db::repo::upsert(
109+        pool,
110+        &db::repo::RepoRow {
111+            did: did.to_string(),
112+            rkey: "rkey1".to_string(),
113+            name: name.to_string(),
114+            description: None,
115+            protocol: "typescript".to_string(),
116+            node_did: "did:plc:node1".to_string(),
117+            node_url: "https://node1.example.com".to_string(),
118+            default_branch: "main".to_string(),
119+            visibility: "public".to_string(),
120+            source_repo: None,
121+            star_count: 0,
122+            fork_count: 0,
123+            open_issue_count: 0,
124+            open_mr_count: 0,
125+            source: "cospan".to_string(),
126+            source_uri: None,
127+            created_at: now,
128+            indexed_at: now,
129+        },
130+    )
131+    .await
132+    .unwrap();
133+}
134+
87135 #[sqlx::test(migrator = "cospan_appview::MIGRATOR")]
88136 async fn repo_upsert_get_and_list_recent(pool: PgPool) {
89137     let now = Utc::now();
138+    insert_test_node(&pool).await;
90139 
91140     let repo = db::repo::RepoRow {
92141         did: "did:plc:alice".to_string(),
@@ -158,6 +207,7 @@ async fn repo_upsert_get_and_list_recent(pool: PgPool) {
158207 #[sqlx::test(migrator = "cospan_appview::MIGRATOR")]
159208 async fn ref_update_upsert_and_list_for_repo(pool: PgPool) {
160209     let now = Utc::now();
210+    insert_test_repo(&pool, "did:plc:alice", "my-project").await;
161211 
162212     let update = db::ref_update::RefUpdateRow {
163213         id: 0,
@@ -212,6 +262,7 @@ async fn ref_update_upsert_and_list_for_repo(pool: PgPool) {
212262 #[sqlx::test(migrator = "cospan_appview::MIGRATOR")]
213263 async fn issue_upsert_get_and_list_for_repo(pool: PgPool) {
214264     let now = Utc::now();
265+    insert_test_repo(&pool, "did:plc:bob", "my-project").await;
215266 
216267     let issue = db::issue::IssueRow {
217268         did: "did:plc:alice".to_string(),
@@ -267,6 +318,7 @@ async fn issue_upsert_get_and_list_for_repo(pool: PgPool) {
267318 #[sqlx::test(migrator = "cospan_appview::MIGRATOR")]
268319 async fn star_upsert_and_list_by_user_with_count(pool: PgPool) {
269320     let now = Utc::now();
321+    insert_test_node(&pool).await;
270322 
271323     // First, create the repo to star
272324     let repo = db::repo::RepoRow {
cospan · schematic version control on atproto built on AT Protocol