|
| 1 | +use dal::attribute::prototype::argument::AttributePrototypeArgument; |
1 | 2 | use dal::diagram::Diagram; |
2 | 3 | use dal::{ |
3 | 4 | AttributeValue, Component, DalContext, InputSocket, OutputSocket, Schema, SchemaVariant, |
@@ -217,3 +218,197 @@ async fn connect_to_one_destination_with_multiple_candidates_of_same_schema_vari |
217 | 218 | assert_eq!(edge.from_component_id, source.id()); |
218 | 219 | assert_eq!(edge.to_component_id, destination.id()); |
219 | 220 | } |
| 221 | + |
| 222 | +#[test] |
| 223 | +async fn remove_connection(ctx: &mut DalContext) { |
| 224 | + // Get the source schema variant id. |
| 225 | + let docker_image_schema = Schema::find_by_name(ctx, "Docker Image") |
| 226 | + .await |
| 227 | + .expect("could not perform find by name") |
| 228 | + .expect("no schema found"); |
| 229 | + let mut docker_image_schema_variants = |
| 230 | + SchemaVariant::list_for_schema(ctx, docker_image_schema.id()) |
| 231 | + .await |
| 232 | + .expect("could not list schema variants for schema"); |
| 233 | + let docker_image_schema_variant = docker_image_schema_variants |
| 234 | + .pop() |
| 235 | + .expect("schema variants are empty"); |
| 236 | + let docker_image_schema_variant_id = docker_image_schema_variant.id(); |
| 237 | + |
| 238 | + // Get the destination schema variant id. |
| 239 | + let butane_schema = Schema::find_by_name(ctx, "Butane") |
| 240 | + .await |
| 241 | + .expect("could not perform find by name") |
| 242 | + .expect("no schema found"); |
| 243 | + let mut butane_schema_variants = SchemaVariant::list_for_schema(ctx, butane_schema.id()) |
| 244 | + .await |
| 245 | + .expect("could not list schema variants for schema"); |
| 246 | + let butane_schema_variant = butane_schema_variants |
| 247 | + .pop() |
| 248 | + .expect("schema variants are empty"); |
| 249 | + let butane_schema_variant_id = butane_schema_variant.id(); |
| 250 | + |
| 251 | + // Find the sockets we want to use. |
| 252 | + let output_socket = |
| 253 | + OutputSocket::find_with_name(ctx, "Container Image", docker_image_schema_variant_id) |
| 254 | + .await |
| 255 | + .expect("could not perform find output socket") |
| 256 | + .expect("output socket not found"); |
| 257 | + let input_socket = |
| 258 | + InputSocket::find_with_name(ctx, "Container Image", butane_schema_variant_id) |
| 259 | + .await |
| 260 | + .expect("could not perform find input socket") |
| 261 | + .expect("input socket not found"); |
| 262 | + |
| 263 | + // Create a component for both the source and the destination |
| 264 | + let oysters_component = |
| 265 | + Component::new(ctx, "oysters in my pocket", docker_image_schema_variant_id) |
| 266 | + .await |
| 267 | + .expect("could not create component"); |
| 268 | + |
| 269 | + ctx.blocking_commit() |
| 270 | + .await |
| 271 | + .expect("blocking commit after component creation"); |
| 272 | + |
| 273 | + ctx.update_snapshot_to_visibility() |
| 274 | + .await |
| 275 | + .expect("update_snapshot_to_visibility"); |
| 276 | + |
| 277 | + // Create a second component for a second source |
| 278 | + let lunch_component = |
| 279 | + Component::new(ctx, "were saving for lunch", docker_image_schema_variant_id) |
| 280 | + .await |
| 281 | + .expect("could not create component"); |
| 282 | + |
| 283 | + ctx.blocking_commit() |
| 284 | + .await |
| 285 | + .expect("blocking commit after component 2 creation"); |
| 286 | + |
| 287 | + ctx.update_snapshot_to_visibility() |
| 288 | + .await |
| 289 | + .expect("update_snapshot_to_visibility"); |
| 290 | + |
| 291 | + let royel_component = Component::new(ctx, "royel otis", butane_schema_variant_id) |
| 292 | + .await |
| 293 | + .expect("could not create component"); |
| 294 | + |
| 295 | + ctx.blocking_commit() |
| 296 | + .await |
| 297 | + .expect("blocking commit after butane component creation"); |
| 298 | + |
| 299 | + ctx.update_snapshot_to_visibility() |
| 300 | + .await |
| 301 | + .expect("update_snapshot_to_visibility"); |
| 302 | + |
| 303 | + // Connect the components! |
| 304 | + let inter_component_attribute_prototype_argument_id = Component::connect( |
| 305 | + ctx, |
| 306 | + oysters_component.id(), |
| 307 | + output_socket.id(), |
| 308 | + royel_component.id(), |
| 309 | + input_socket.id(), |
| 310 | + ) |
| 311 | + .await |
| 312 | + .expect("could not connect components"); |
| 313 | + |
| 314 | + ctx.blocking_commit().await.expect("blocking commit failed"); |
| 315 | + |
| 316 | + ctx.update_snapshot_to_visibility() |
| 317 | + .await |
| 318 | + .expect("update_snapshot_to_visibility"); |
| 319 | + |
| 320 | + // Connect component 2 |
| 321 | + let _inter_component_attribute_prototype_argument_id = Component::connect( |
| 322 | + ctx, |
| 323 | + lunch_component.id(), |
| 324 | + output_socket.id(), |
| 325 | + royel_component.id(), |
| 326 | + input_socket.id(), |
| 327 | + ) |
| 328 | + .await |
| 329 | + .expect("could not connect components"); |
| 330 | + |
| 331 | + ctx.blocking_commit().await.expect("blocking commit failed"); |
| 332 | + |
| 333 | + ctx.update_snapshot_to_visibility() |
| 334 | + .await |
| 335 | + .expect("update_snapshot_to_visibility"); |
| 336 | + |
| 337 | + //dbg!(royel_component.incoming_connections(ctx).await.expect("ok")); |
| 338 | + |
| 339 | + let units_value_id = royel_component |
| 340 | + .attribute_values_for_prop(ctx, &["root", "domain", "systemd", "units"]) |
| 341 | + .await |
| 342 | + .expect("able to get values for units") |
| 343 | + .first() |
| 344 | + .copied() |
| 345 | + .expect("has a value"); |
| 346 | + |
| 347 | + let materialized_view = AttributeValue::get_by_id(ctx, units_value_id) |
| 348 | + .await |
| 349 | + .expect("value exists") |
| 350 | + .materialized_view(ctx) |
| 351 | + .await |
| 352 | + .expect("able to get units materialized_view") |
| 353 | + .expect("units has a materialized_view"); |
| 354 | + |
| 355 | + dbg!(lunch_component |
| 356 | + .materialized_view(ctx) |
| 357 | + .await |
| 358 | + .expect("get docker image materialized_view")); |
| 359 | + |
| 360 | + assert!(matches!(materialized_view, serde_json::Value::Array(_))); |
| 361 | + |
| 362 | + if let serde_json::Value::Array(units_array) = materialized_view { |
| 363 | + assert_eq!(2, units_array.len()) |
| 364 | + } |
| 365 | + |
| 366 | + // Assemble the diagram and check the edges. |
| 367 | + let diagram = Diagram::assemble(ctx) |
| 368 | + .await |
| 369 | + .expect("could not assemble the diagram"); |
| 370 | + assert_eq!(2, diagram.edges.len()); |
| 371 | + |
| 372 | + // Disconnect Component 1 |
| 373 | + AttributePrototypeArgument::remove(ctx, inter_component_attribute_prototype_argument_id) |
| 374 | + .await |
| 375 | + .expect("Unable to remove inter component attribute prototype argument"); |
| 376 | + |
| 377 | + ctx.blocking_commit().await.expect("blocking commit failed"); |
| 378 | + ctx.update_snapshot_to_visibility() |
| 379 | + .await |
| 380 | + .expect("Unable to update snapshot to visibility"); |
| 381 | + |
| 382 | + let units_value_id = royel_component |
| 383 | + .attribute_values_for_prop(ctx, &["root", "domain", "systemd", "units"]) |
| 384 | + .await |
| 385 | + .expect("able to get values for units") |
| 386 | + .first() |
| 387 | + .copied() |
| 388 | + .expect("has a value"); |
| 389 | + |
| 390 | + let materialized_view = AttributeValue::get_by_id(ctx, units_value_id) |
| 391 | + .await |
| 392 | + .expect("value exists") |
| 393 | + .materialized_view(ctx) |
| 394 | + .await |
| 395 | + .expect("able to get units materialized_view") |
| 396 | + .expect("units has a materialized_view"); |
| 397 | + |
| 398 | + dbg!(lunch_component |
| 399 | + .materialized_view(ctx) |
| 400 | + .await |
| 401 | + .expect("get docker image materialized_view")); |
| 402 | + |
| 403 | + assert!(matches!(materialized_view, serde_json::Value::Array(_))); |
| 404 | + |
| 405 | + if let serde_json::Value::Array(units_array) = materialized_view { |
| 406 | + assert_eq!(1, units_array.len()) |
| 407 | + } |
| 408 | + |
| 409 | + // Assemble the diagram and check the edges. |
| 410 | + let diagram = Diagram::assemble(ctx) |
| 411 | + .await |
| 412 | + .expect("could not assemble the diagram"); |
| 413 | + assert_eq!(1, diagram.edges.len()); |
| 414 | +} |
0 commit comments