diff --git a/api/src/core/schema/mutation.py b/api/src/core/schema/mutation.py index e18c426..70ba0a2 100644 --- a/api/src/core/schema/mutation.py +++ b/api/src/core/schema/mutation.py @@ -346,7 +346,8 @@ def create_beta_move( previous_beta_move: Annotated[ Optional[relay.GlobalID], strawberry.argument( - description="Move prior to this one in the beta" + description="Move prior to this one in the beta " + "(null for first move)" ), ], ) -> BetaMoveNode: @@ -357,13 +358,9 @@ def create_beta_move( # Convert GQL IDs to PKs beta_dj: Beta = beta.resolve_node_sync(info, ensure_type=Beta) - hold_dj: Hold | None = ( - hold.resolve_node_sync(info, ensure_type=Hold) if hold else None - ) - previous_beta_move_dj: BetaMove | None = ( + hold_dj = hold and (hold.resolve_node_sync(info, ensure_type=Hold)) + previous_beta_move_dj = previous_beta_move and ( previous_beta_move.resolve_node_sync(info, ensure_type=BetaMove) - if previous_beta_move - else None ) # Convert position from SVG coords to normalized [0,1] @@ -423,9 +420,7 @@ def update_beta_move( beta_move_dj: BetaMove = id.resolve_node_sync( info, ensure_type=BetaMove ) - hold_dj: Hold | None = ( - hold.resolve_node_sync(info, ensure_type=Hold) if hold else None - ) + hold_dj = hold and (hold.resolve_node_sync(info, ensure_type=Hold)) normal_position = position and position.to_normalized( beta_move_dj.beta.problem.boulder.image ) diff --git a/api/src/core/tests/factories.py b/api/src/core/tests/factories.py index 565d631..059a845 100644 --- a/api/src/core/tests/factories.py +++ b/api/src/core/tests/factories.py @@ -1,4 +1,5 @@ import factory +import factory.fuzzy import factory.random from django.contrib.auth.models import User from factory import Factory @@ -11,6 +12,7 @@ from core.models import ( Beta, BetaMove, + BodyPart, Boulder, Hold, HoldAnnotationSource, @@ -103,6 +105,10 @@ class Params: beta = factory.SubFactory(BetaFactory, moves=[]) order = factory.Sequence(lambda n: n) + body_part = Faker( + "random_element", + elements=[key for key, _ in BodyPart.choices], + ) hold = factory.Maybe( "is_free", yes_declaration=None, diff --git a/api/src/core/tests/schema/mutation/test_mutate_beta_move.py b/api/src/core/tests/schema/mutation/test_mutate_beta_move.py index 12a4ea9..5fa2f53 100644 --- a/api/src/core/tests/schema/mutation/test_mutate_beta_move.py +++ b/api/src/core/tests/schema/mutation/test_mutate_beta_move.py @@ -18,50 +18,29 @@ bodyPart isStart annotation - target + target { + __typename + ... on HoldNode { + id + } + ... on SVGPosition { + x + y + } + } permissions { canEdit canDelete } - beta { - moves { - edges { - node { - id - order - } - } - } - } } } """ -update_beta_move_mutation = """ +update_annotation_mutation = """ mutation($input: UpdateBetaMoveInput!) { updateBetaMove(input: $input) { id - order - bodyPart - isStart annotation - target { - __typename - } - permissions { - canEdit - canDelete - } - beta { - moves { - edges { - node { - id - order - } - } - } - } } } """ @@ -85,6 +64,28 @@ """ +@pytest.mark.parametrize( + "beta_move__is_free", [False, True], ids=["hold", "free"] +) +def test_update_annotation( + context: StrawberryDjangoContext, beta_move: BetaMove +) -> None: + beta_move_id = relay.to_base64(BetaMoveNode, beta_move.id) + assert_graphql_result( + schema.execute_sync( + update_annotation_mutation, + context_value=context, + variable_values={ + "input": {"id": beta_move_id, "annotation": "new value"} + }, + ), + {"updateBetaMove": {"id": beta_move_id, "annotation": "new value"}}, + ) + + +# TODO test missing permissions + + def test_delete_beta_move( context: StrawberryDjangoContext, beta_move: BetaMove ) -> None: diff --git a/api/src/schema.graphql b/api/src/schema.graphql index 699f3fc..cb0d3b9 100644 --- a/api/src/schema.graphql +++ b/api/src/schema.graphql @@ -134,7 +134,7 @@ input CreateBetaMoveInput { hold: ID position: SVGPositionInput - """Move prior to this one in the beta""" + """Move prior to this one in the beta (null for first move)""" previousBetaMove: ID }