Skip to content

Commit b1eb896

Browse files
test: verify SubgraphNotFound error for non-existent subgraph removal
Signed-off-by: Maksim Dimitrov <dimitrov.maksim@gmail.com>
1 parent 122cffc commit b1eb896

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

server/graphman/tests/deployment_mutation.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,44 @@ fn graphql_cannot_remove_subgraph_with_invalid_name() {
403403
)
404404
.await;
405405

406-
let success_resp = json!({
407-
"data": {
408-
"deployment": {
409-
"remove": {
410-
"success": true,
406+
let data = &resp["data"]["deployment"];
407+
let errors = resp["errors"].as_array().unwrap();
408+
409+
assert!(data.is_null());
410+
assert_eq!(errors.len(), 1);
411+
assert_eq!(
412+
errors[0]["message"].as_str().unwrap(),
413+
"store error: Subgraph name must contain only a-z, A-Z, 0-9, '-' and '_'"
414+
);
415+
});
416+
}
417+
418+
#[test]
419+
fn graphql_remove_returns_error_for_non_existing_subgraph() {
420+
run_test(|| async {
421+
let resp = send_graphql_request(
422+
json!({
423+
"query": r#"mutation RemoveNonExistingSubgraph {
424+
deployment {
425+
remove(name: "non_existing_subgraph") {
426+
success
427+
}
411428
}
412-
}
413-
}
414-
});
429+
}"#
430+
}),
431+
VALID_TOKEN,
432+
)
433+
.await;
415434

416-
assert_ne!(resp, success_resp);
435+
let data = &resp["data"]["deployment"];
436+
let errors = resp["errors"].as_array().unwrap();
437+
438+
assert!(data.is_null());
439+
assert_eq!(errors.len(), 1);
440+
assert_eq!(
441+
errors[0]["message"].as_str().unwrap(),
442+
"store error: subgraph not found: non_existing_subgraph"
443+
);
417444
});
418445
}
419446

store/test-store/tests/postgres/subgraph.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,3 +1232,18 @@ fn fail_unfail_non_deterministic_error_noop() {
12321232
test_store::remove_subgraphs().await;
12331233
})
12341234
}
1235+
1236+
#[test]
1237+
fn remove_nonexistent_subgraph_returns_not_found() {
1238+
test_store::run_test_sequentially(|store| async move {
1239+
remove_subgraphs().await;
1240+
1241+
let name = SubgraphName::new("nonexistent/subgraph").unwrap();
1242+
let result = store.subgraph_store().remove_subgraph(name.clone()).await;
1243+
1244+
assert!(matches!(
1245+
result,
1246+
Err(StoreError::SubgraphNotFound(n)) if n == name.to_string()
1247+
));
1248+
})
1249+
}

0 commit comments

Comments
 (0)