Skip to content

Commit

Permalink
Fix updating hold-attached moves
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPickering committed Aug 19, 2023
1 parent 9cde50a commit 0934881
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 43 deletions.
15 changes: 5 additions & 10 deletions api/src/core/schema/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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
)
Expand Down
6 changes: 6 additions & 0 deletions api/src/core/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import factory
import factory.fuzzy
import factory.random
from django.contrib.auth.models import User
from factory import Factory
Expand All @@ -11,6 +12,7 @@
from core.models import (
Beta,
BetaMove,
BodyPart,
Boulder,
Hold,
HoldAnnotationSource,
Expand Down Expand Up @@ -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,
Expand Down
65 changes: 33 additions & 32 deletions api/src/core/tests/schema/mutation/test_mutate_beta_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}
}
"""
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion api/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 0934881

Please sign in to comment.