@@ -457,6 +457,10 @@ defmodule SanbaseWeb.Graphql.QueriesApiTest do
457
457
458
458
describe "Run Queries" do
459
459
test "run raw sql query" , context do
460
+ # In test env the storing runs not async and there's a 7500ms sleep
461
+ Application . put_env ( :__sanbase_queires__ , :store_execution_details , false )
462
+ on_exit ( fn -> Application . delete_env ( :__sanbase_queires__ , :store_execution_details ) end )
463
+
460
464
mock_fun =
461
465
Sanbase.Mock . wrap_consecutives (
462
466
[
@@ -498,6 +502,10 @@ defmodule SanbaseWeb.Graphql.QueriesApiTest do
498
502
end
499
503
500
504
test "run sql query by id" , context do
505
+ # In test env the storing runs not async and there's a 7500ms sleep
506
+ Application . put_env ( :__sanbase_queires__ , :store_execution_details , false )
507
+ on_exit ( fn -> Application . delete_env ( :__sanbase_queires__ , :store_execution_details ) end )
508
+
501
509
{ :ok , query } = create_query ( context . user . id )
502
510
503
511
mock_fun =
@@ -535,7 +543,60 @@ defmodule SanbaseWeb.Graphql.QueriesApiTest do
535
543
end )
536
544
end
537
545
546
+ test "delete dashboard query" , context do
547
+ { :ok , query } = create_query ( context . user . id )
548
+
549
+ { :ok , dashboard } =
550
+ Sanbase.Dashboards . create_dashboard ( % { name: "My Dashboard" } , context . user . id )
551
+
552
+ # Add a query to a dashboard
553
+ mapping =
554
+ execute_dashboard_query_mutation ( context . conn , :create_dashboard_query , % {
555
+ dashboard_id: dashboard . id ,
556
+ query_id: query . id ,
557
+ settings: % { layout: [ 0 , 1 , 2 , 3 , 4 ] }
558
+ } )
559
+ |> get_in ( [ "data" , "createDashboardQuery" ] )
560
+
561
+ # Assert that the dashboard has exactly 1 query added
562
+ assert { :ok , % { queries: [ _ ] } } =
563
+ Sanbase.Dashboards . get_dashboard ( dashboard . id , context . user . id )
564
+
565
+ result =
566
+ execute_dashboard_query_mutation ( context . conn , :delete_dashboard_query , % {
567
+ dashboard_id: dashboard . id ,
568
+ dashboard_query_mapping_id: mapping [ "id" ]
569
+ } )
570
+ |> get_in ( [ "data" , "deleteDashboardQuery" ] )
571
+
572
+ dashboard_query_mapping_id = mapping [ "id" ]
573
+
574
+ query_id = query . id
575
+ dashboard_id = dashboard . id
576
+
577
+ assert % {
578
+ "dashboard" => % { "id" => ^ dashboard_id , "parameters" => % { } } ,
579
+ "id" => ^ dashboard_query_mapping_id ,
580
+ "query" => % {
581
+ "id" => ^ query_id ,
582
+ "sqlQueryParameters" => % { "limit" => 10 , "slug" => "bitcoin" } ,
583
+ "sqlQueryText" =>
584
+ "SELECT * FROM intraday_metrics WHERE asset_id = get_asset_id({{slug}}) LIMIT {{limit}}"
585
+ } ,
586
+ "settings" => % { "layout" => [ 0 , 1 , 2 , 3 , 4 ] }
587
+ } = result
588
+
589
+ # Assert that the dashboard has no queries
590
+
591
+ assert { :ok , % { queries: [ ] } } =
592
+ Sanbase.Dashboards . get_dashboard ( dashboard_id , context . user . id )
593
+ end
594
+
538
595
test "run dashboard query (resolve global params)" , context do
596
+ # In test env the storing runs not async and there's a 7500ms sleep
597
+ Application . put_env ( :__sanbase_queires__ , :store_execution_details , false )
598
+ on_exit ( fn -> Application . delete_env ( :__sanbase_queires__ , :store_execution_details ) end )
599
+
539
600
{ :ok , query } = create_query ( context . user . id )
540
601
541
602
{ :ok , dashboard } =
@@ -644,6 +705,7 @@ defmodule SanbaseWeb.Graphql.QueriesApiTest do
644
705
645
706
describe "Caching" do
646
707
test "cache queries on a dashboard" , context do
708
+ # In test env the storing runs not async and there's a 7500ms sleep
647
709
Application . put_env ( :__sanbase_queires__ , :store_execution_details , false )
648
710
on_exit ( fn -> Application . delete_env ( :__sanbase_queires__ , :store_execution_details ) end )
649
711
0 commit comments