|
5 | 5 | from infrahub.core.branch import Branch |
6 | 6 | from infrahub.core.manager import NodeManager |
7 | 7 | from infrahub.core.node import Node |
| 8 | +from infrahub.core.registry import registry |
| 9 | +from infrahub.core.schema import SchemaRoot |
8 | 10 | from infrahub.database import InfrahubDatabase |
9 | 11 | from infrahub.graphql import prepare_graphql_params |
| 12 | +from tests.constants import TestKind |
| 13 | +from tests.helpers.schema import TICKET |
10 | 14 |
|
11 | 15 |
|
12 | 16 | async def test_upsert_existing_simple_object_by_id(db: InfrahubDatabase, person_john_main: Node, branch: Branch): |
@@ -393,3 +397,52 @@ async def test_with_constructed_hfid(db: InfrahubDatabase, default_branch, anima |
393 | 397 | "name": {"value": "Ghost"}, |
394 | 398 | "weight": {"value": updated_weight}, |
395 | 399 | } |
| 400 | + |
| 401 | + |
| 402 | +async def test_with_constructed_hfid_with_numbers( |
| 403 | + db: InfrahubDatabase, default_branch: Branch, data_schema: None |
| 404 | +) -> None: |
| 405 | + """Validate that we can construct an HFID out of the payload without specifying all parts.""" |
| 406 | + registry.schema.register_schema(schema=SchemaRoot(nodes=[TICKET]), branch=default_branch.name) |
| 407 | + |
| 408 | + first_ticket = await Node.init(schema=TestKind.TICKET, db=db) |
| 409 | + await first_ticket.new(db=db, title="first", ticket_id=1, description="Add more info") |
| 410 | + await first_ticket.save(db=db) |
| 411 | + |
| 412 | + query = """ |
| 413 | + mutation UpsertTicket { |
| 414 | + TestingTicketUpsert(data: { |
| 415 | + title: { value: "first" }, |
| 416 | + ticket_id: { value: 1 }, |
| 417 | + description: { value: "Here is the update" }, |
| 418 | + }) { |
| 419 | + ok |
| 420 | + object { |
| 421 | + id |
| 422 | + title { |
| 423 | + value |
| 424 | + } |
| 425 | + description { |
| 426 | + value |
| 427 | + } |
| 428 | + } |
| 429 | + } |
| 430 | + } |
| 431 | + """ |
| 432 | + gql_params = prepare_graphql_params(db=db, include_subscription=False, branch=default_branch) |
| 433 | + |
| 434 | + update_result = await graphql( |
| 435 | + schema=gql_params.schema, |
| 436 | + source=query, |
| 437 | + context_value=gql_params.context, |
| 438 | + root_value=None, |
| 439 | + ) |
| 440 | + |
| 441 | + assert update_result.errors is None |
| 442 | + assert update_result.data |
| 443 | + assert update_result.data["TestingTicketUpsert"]["ok"] is True |
| 444 | + assert update_result.data["TestingTicketUpsert"]["object"] == { |
| 445 | + "title": {"value": "first"}, |
| 446 | + "description": {"value": "Here is the update"}, |
| 447 | + "id": first_ticket.id, |
| 448 | + } |
0 commit comments