Skip to content

Commit 2b60f8d

Browse files
committed
server: graphman graphql api tests added for unassign/reassign
1 parent a772f64 commit 2b60f8d

File tree

1 file changed

+321
-0
lines changed

1 file changed

+321
-0
lines changed

server/graphman/tests/deployment_mutation.rs

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,324 @@ fn graphql_allows_tracking_restart_deployment_executions() {
266266
assert_eq!(resp, expected_resp);
267267
});
268268
}
269+
<<<<<<< HEAD
270+
=======
271+
272+
#[test]
273+
fn graphql_can_create_new_subgraph() {
274+
run_test(|| async {
275+
let resp = send_graphql_request(
276+
json!({
277+
"query": r#"mutation CreateSubgraph {
278+
deployment {
279+
create(name: "subgraph_1") {
280+
success
281+
}
282+
}
283+
}"#
284+
}),
285+
VALID_TOKEN,
286+
)
287+
.await;
288+
289+
let expected_resp = json!({
290+
"data": {
291+
"deployment": {
292+
"create": {
293+
"success": true,
294+
}
295+
}
296+
}
297+
});
298+
299+
assert_eq!(resp, expected_resp);
300+
});
301+
}
302+
303+
#[test]
304+
fn graphql_cannot_create_new_subgraph_with_invalid_name() {
305+
run_test(|| async {
306+
let resp = send_graphql_request(
307+
json!({
308+
"query": r#"mutation CreateInvalidSubgraph {
309+
deployment {
310+
create(name: "*@$%^subgraph") {
311+
success
312+
}
313+
}
314+
}"#
315+
}),
316+
VALID_TOKEN,
317+
)
318+
.await;
319+
320+
let success_resp = json!({
321+
"data": {
322+
"deployment": {
323+
"create": {
324+
"success": true,
325+
}
326+
}
327+
}
328+
});
329+
330+
assert_ne!(resp, success_resp);
331+
});
332+
}
333+
334+
#[test]
335+
fn graphql_can_remove_subgraph() {
336+
run_test(|| async {
337+
let resp = send_graphql_request(
338+
json!({
339+
"query": r#"mutation RemoveSubgraph {
340+
deployment {
341+
remove(name: "subgraph_1") {
342+
success
343+
}
344+
}
345+
}"#
346+
}),
347+
VALID_TOKEN,
348+
)
349+
.await;
350+
351+
let expected_resp = json!({
352+
"data": {
353+
"deployment": {
354+
"remove": {
355+
"success": true,
356+
}
357+
}
358+
}
359+
});
360+
361+
assert_eq!(resp, expected_resp);
362+
});
363+
}
364+
365+
#[test]
366+
fn graphql_cannot_remove_subgraph_with_invalid_name() {
367+
run_test(|| async {
368+
let resp = send_graphql_request(
369+
json!({
370+
"query": r#"mutation RemoveInvalidSubgraph {
371+
deployment {
372+
remove(name: "*@$%^subgraph") {
373+
success
374+
}
375+
}
376+
}"#
377+
}),
378+
VALID_TOKEN,
379+
)
380+
.await;
381+
382+
let success_resp = json!({
383+
"data": {
384+
"deployment": {
385+
"remove": {
386+
"success": true,
387+
}
388+
}
389+
}
390+
});
391+
392+
assert_ne!(resp, success_resp);
393+
});
394+
}
395+
396+
#[test]
397+
fn graphql_can_unassign_deployments() {
398+
run_test(|| async {
399+
let deployment_hash = DeploymentHash::new("subgraph_1").unwrap();
400+
create_test_subgraph(&deployment_hash, TEST_SUBGRAPH_SCHEMA).await;
401+
402+
let unassign_req = send_graphql_request(
403+
json!({
404+
"query": r#"mutation {
405+
deployment {
406+
unassign(deployment: { hash: "subgraph_1" }){
407+
success
408+
}
409+
}
410+
}"#
411+
}),
412+
VALID_TOKEN,
413+
)
414+
.await;
415+
416+
let expected_resp = json!({
417+
"data": {
418+
"deployment": {
419+
"unassign": {
420+
"success": true,
421+
}
422+
}
423+
}
424+
});
425+
426+
let subgraph_node_id = send_graphql_request(
427+
json!({
428+
"query": r#"query Deployment {
429+
deployment {
430+
info(deployment: { hash: "subgraph_1" }) {
431+
nodeId
432+
}
433+
}
434+
}"#
435+
}),
436+
VALID_TOKEN,
437+
)
438+
.await;
439+
440+
let is_node_null = subgraph_node_id["data"]["deployment"]["info"][0]["nodeId"].is_null();
441+
442+
assert_eq!(unassign_req, expected_resp);
443+
assert_eq!(is_node_null, true);
444+
});
445+
}
446+
447+
#[test]
448+
fn graphql_cannot_unassign_deployments_twice() {
449+
run_test(|| async {
450+
let deployment_hash = DeploymentHash::new("subgraph_1").unwrap();
451+
create_test_subgraph(&deployment_hash, TEST_SUBGRAPH_SCHEMA).await;
452+
453+
send_graphql_request(
454+
json!({
455+
"query": r#"mutation {
456+
deployment {
457+
unassign(deployment: { hash: "subgraph_1" }){
458+
success
459+
}
460+
}
461+
}"#
462+
}),
463+
VALID_TOKEN,
464+
)
465+
.await;
466+
467+
let unassign_again = send_graphql_request(
468+
json!({
469+
"query": r#"mutation {
470+
deployment {
471+
unassign(deployment: { hash: "subgraph_1" }){
472+
success
473+
}
474+
}
475+
}"#
476+
}),
477+
VALID_TOKEN,
478+
)
479+
.await;
480+
481+
let expected_resp = json!({
482+
"data": {
483+
"deployment": {
484+
"unassign": {
485+
"success": true,
486+
}
487+
}
488+
}
489+
});
490+
491+
assert_ne!(unassign_again, expected_resp);
492+
});
493+
}
494+
495+
#[test]
496+
fn graphql_can_reassign_deployment() {
497+
run_test(|| async {
498+
let deployment_hash = DeploymentHash::new("subgraph_1").unwrap();
499+
create_test_subgraph(&deployment_hash, TEST_SUBGRAPH_SCHEMA).await;
500+
501+
let deployment_hash = DeploymentHash::new("subgraph_2").unwrap();
502+
create_test_subgraph(&deployment_hash, TEST_SUBGRAPH_SCHEMA).await;
503+
504+
send_graphql_request(
505+
json!({
506+
"query": r#"mutation {
507+
deployment {
508+
unassign(deployment: { hash: "subgraph_1" }){
509+
success
510+
}
511+
}
512+
}"#
513+
}),
514+
VALID_TOKEN,
515+
)
516+
.await;
517+
518+
let reassign = send_graphql_request(
519+
json!({
520+
"query": r#"mutation {
521+
deployment {
522+
reassign(deployment: { hash: "subgraph_1" }, node: "test") {
523+
... on EmptyResponse {
524+
success
525+
}
526+
... on CompletedWithWarnings {
527+
warnings
528+
}
529+
}
530+
}
531+
}"#
532+
}),
533+
VALID_TOKEN,
534+
)
535+
.await;
536+
537+
let expected_resp = json!({
538+
"data": {
539+
"deployment": {
540+
"reassign": {
541+
"success": true,
542+
}
543+
}
544+
}
545+
});
546+
547+
assert_eq!(reassign, expected_resp);
548+
});
549+
}
550+
551+
#[test]
552+
fn graphql_warns_reassign_on_wrong_node_id() {
553+
run_test(|| async {
554+
let deployment_hash = DeploymentHash::new("subgraph_1").unwrap();
555+
create_test_subgraph(&deployment_hash, TEST_SUBGRAPH_SCHEMA).await;
556+
557+
let reassign = send_graphql_request(
558+
json!({
559+
"query": r#"mutation {
560+
deployment {
561+
reassign(deployment: { hash: "subgraph_1" }, node: "invalid_node") {
562+
... on EmptyResponse {
563+
success
564+
}
565+
... on CompletedWithWarnings {
566+
warnings
567+
}
568+
}
569+
}
570+
}"#
571+
}),
572+
VALID_TOKEN,
573+
)
574+
.await;
575+
576+
let expected_resp = json!({
577+
"data": {
578+
"deployment": {
579+
"reassign": {
580+
"warnings": ["warning: this is the only deployment assigned to 'invalid_node'. Are you sure it is spelled correctly?"],
581+
}
582+
}
583+
}
584+
});
585+
586+
assert_eq!(reassign, expected_resp);
587+
});
588+
}
589+
>>>>>>> 5ab559557 (server: graphman graphql api tests added for unassign/reassign)

0 commit comments

Comments
 (0)