-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix optimisitic update when deleting moves
- Loading branch information
1 parent
6e317d4
commit f0348c2
Showing
9 changed files
with
418 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
api/src/core/tests/schema/mutation/test_mutate_beta_move.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import pytest | ||
from pytest_factoryboy import LazyFixture | ||
from strawberry import relay | ||
from strawberry.django.context import StrawberryDjangoContext | ||
|
||
from core.models import BetaMove | ||
from core.schema import schema | ||
from core.schema.query import BetaMoveNode | ||
from core.tests.schema.conftest import assert_graphql_result | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
create_beta_move_mutation = """ | ||
mutation($input: CreateBetaMoveInput!) { | ||
createBetaMove(input: $input) { | ||
id | ||
order | ||
bodyPart | ||
isStart | ||
annotation | ||
target | ||
permissions { | ||
canEdit | ||
canDelete | ||
} | ||
beta { | ||
moves { | ||
edges { | ||
node { | ||
id | ||
order | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
update_beta_move_mutation = """ | ||
mutation($input: UpdateBetaMoveInput!) { | ||
updateBetaMove(input: $input) { | ||
id | ||
order | ||
bodyPart | ||
isStart | ||
annotation | ||
target { | ||
__typename | ||
} | ||
permissions { | ||
canEdit | ||
canDelete | ||
} | ||
beta { | ||
moves { | ||
edges { | ||
node { | ||
id | ||
order | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
delete_beta_move_mutation = """ | ||
mutation($input: NodeInput!) { | ||
deleteBetaMove(input: $input) { | ||
id | ||
beta { | ||
moves { | ||
edges { | ||
node { | ||
id | ||
order | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
|
||
|
||
def test_delete_beta_move( | ||
context: StrawberryDjangoContext, beta_move: BetaMove | ||
) -> None: | ||
beta_move_id = relay.to_base64(BetaMoveNode, beta_move.id) | ||
assert_graphql_result( | ||
schema.execute_sync( | ||
delete_beta_move_mutation, | ||
context_value=context, | ||
variable_values={"input": {"id": beta_move_id}}, | ||
), | ||
# This returns the *old* value | ||
{ | ||
"deleteBetaMove": { | ||
"id": beta_move_id, | ||
"beta": { | ||
"moves": { | ||
"edges": [ | ||
{ | ||
"node": { | ||
"id": beta_move_id, | ||
"order": beta_move.order, | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
} | ||
}, | ||
) | ||
assert BetaMove.objects.filter(id=beta_move.id).count() == 0 | ||
|
||
|
||
@pytest.mark.parametrize("beta__owner", [LazyFixture("other_user")]) | ||
def test_delete_beta_move_no_permission( | ||
context: StrawberryDjangoContext, beta_move: BetaMove | ||
) -> None: | ||
beta_move_id = relay.to_base64(BetaMoveNode, beta_move.id) | ||
assert_graphql_result( | ||
schema.execute_sync( | ||
delete_beta_move_mutation, | ||
context_value=context, | ||
variable_values={"input": {"id": beta_move_id}}, | ||
), | ||
None, | ||
["You don't have permission"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.