diff --git a/openlobby/core/api/mutations.py b/openlobby/core/api/mutations.py index ec297e01a6353a5149e2851d293ca8577985db15..afd86b293c9ffcf5815005da509b0445100de2b8 100644 --- a/openlobby/core/api/mutations.py +++ b/openlobby/core/api/mutations.py @@ -108,6 +108,7 @@ class CreateReport(relay.ClientIDMutation): our_participants = graphene.String() other_participants = graphene.String() date = DateTime(required=True) + is_draft = graphene.Boolean(default_value=False) report = graphene.Field(types.Report) @@ -127,6 +128,7 @@ class CreateReport(relay.ClientIDMutation): provided_benefit=strip_all_tags(input.get('provided_benefit', '')), our_participants=strip_all_tags(input.get('our_participants', '')), other_participants=strip_all_tags(input.get('other_participants', '')), + is_draft=input.get('is_draft'), ) return CreateReport(report=types.Report.from_db(report)) diff --git a/tests/mutations/snapshots/snap_test_create_report.py b/tests/mutations/snapshots/snap_test_create_report.py index 1ad80469591726bd2f26f510f7edc20f8c6c0e26..5d774db5884c4cb35f494597e53db2aaee0095e0 100644 --- a/tests/mutations/snapshots/snap_test_create_report.py +++ b/tests/mutations/snapshots/snap_test_create_report.py @@ -48,3 +48,28 @@ snapshots['test_full_report 1'] = { } } } + +snapshots['test_is_draft 1'] = { + 'data': { + 'createReport': { + 'report': { + 'author': { + 'extra': None, + 'firstName': 'Winston', + 'id': 'QXV0aG9yOjE=', + 'lastName': 'Wolfe' + }, + 'body': 'Niel deGrasse Tyson just visited me...', + 'date': '2018-01-03 00:00:00+00:00', + 'extra': None, + 'id': '__STRIPPED__', + 'otherParticipants': 'Neil deGrasse Tyson', + 'ourParticipants': 'myself', + 'providedBenefit': 'coffee', + 'published': '__STRIPPED__', + 'receivedBenefit': 'touch of the God', + 'title': 'Visited by old friend' + } + } + } +} diff --git a/tests/mutations/test_create_report.py b/tests/mutations/test_create_report.py index e1a32c837efdaa8008f7468527cc6f947c8b5548..f2121dabc7b6d65338f3c906b868dc2925af0f52 100644 --- a/tests/mutations/test_create_report.py +++ b/tests/mutations/test_create_report.py @@ -148,3 +148,74 @@ def test_input_sanitization(client): assert report.provided_benefit == 'tea' assert report.our_participants == 'me, myself' assert report.other_participants == 'you!' + + +def test_is_draft(client, snapshot): + query = """ + mutation createReport ($input: CreateReportInput!) { + createReport (input: $input) { + report { + id + date + published + title + body + receivedBenefit + providedBenefit + ourParticipants + otherParticipants + extra + author { + id + firstName + lastName + extra + } + } + } + } + """ + date = arrow.get(2018, 1, 3) + title = 'Visited by old friend' + body = 'Niel deGrasse Tyson just visited me...' + received_benefit = 'touch of the God' + provided_benefit = 'coffee' + our_participants = 'myself' + other_participants = 'Neil deGrasse Tyson' + input = { + 'title': title, + 'body': body, + 'receivedBenefit': received_benefit, + 'providedBenefit': provided_benefit, + 'ourParticipants': our_participants, + 'otherParticipants': other_participants, + 'date': date.isoformat(), + 'isDraft': True, + } + + response = call_api(client, query, input, 'wolfe') + + # published date is set on save, changing between test runs, so we strip it + # from snapshot + published = response['data']['createReport']['report']['published'] + response['data']['createReport']['report']['published'] = '__STRIPPED__' + + # strip random ID from snapshot and check it + id = response['data']['createReport']['report']['id'] + response['data']['createReport']['report']['id'] = '__STRIPPED__' + assert re.match(r'\w+', id) + + snapshot.assert_match(response) + + report = Report.objects.get() + assert report.author_id == 1 + assert report.date == date.datetime + assert report.published == arrow.get(published).datetime + assert report.title == title + assert report.body == body + assert report.received_benefit == received_benefit + assert report.provided_benefit == provided_benefit + assert report.our_participants == our_participants + assert report.other_participants == other_participants + assert report.extra is None + assert report.is_draft is True