Skip to content

Commit

Permalink
Implement graphql mutation node for delete lead in bulk (#1460)
Browse files Browse the repository at this point in the history
Add mutation for bulk delete lead
* remove the count from login
  • Loading branch information
susilnem authored Sep 20, 2024
1 parent 2e1bfeb commit 1ad6182
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/lead/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class BulkLeadInputType(LeadInputType):
class BulkLead(LeadMutationMixin, PsBulkGrapheneMutation):
class Arguments:
items = graphene.List(graphene.NonNull(BulkLeadInputType))
delete_ids = graphene.List(graphene.NonNull(graphene.ID))

result = graphene.List(LeadType)
deleted_result = graphene.List(graphene.NonNull(LeadType))
Expand Down
63 changes: 63 additions & 0 deletions apps/lead/tests/test_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,69 @@ def _query_check(**kwargs):
self.assertMatchSnapshot(response, 'success')
self.assertEqual(lead_count + 2, Lead.objects.count())

def test_lead_bulk_delete_validation(self):
query = '''
mutation MyMutation ($projectId: ID! $input: [ID!]) {
project(id: $projectId) {
leadBulk(deleteIds: $input) {
errors
deletedResult {
id
title
}
}
}
}
'''

project = ProjectFactory.create()
non_member_user = UserFactory.create()
read_only_member_user = UserFactory.create()
member_user = UserFactory.create()
project.add_member(member_user, role=self.project_role_member)
project.add_member(read_only_member_user, role=self.project_role_reader_non_confidential)

lead1, lead2, _ = LeadFactory.create_batch(3, project=project)

lead_count = Lead.objects.count()

minput = [
str(lead1.pk),
str(lead2.pk),
]

def _query_check(**kwargs):
return self.query_check(query, minput=minput, variables={'projectId': project.pk}, **kwargs)

# Error without login
_query_check(assert_for_error=True)

# -- With login (non-member)
self.force_login(non_member_user)
_query_check(assert_for_error=True)
self.assertEqual(lead_count, Lead.objects.count())

# --- login as read-only member
self.force_login(read_only_member_user)
_query_check(assert_for_error=True)
self.assertEqual(lead_count, Lead.objects.count())

# --- login (member)
self.force_login(member_user)
# Success with normal lead (with project membership)
result = _query_check()['data']['project']['leadBulk']
self.assertEqual(
result,
{
'errors': [],
'deletedResult': [
dict(id=str(lead1.pk), title=lead1.title),
dict(id=str(lead2.pk), title=lead2.title),
],
},
)
self.assertEqual(1, Lead.objects.count())


class TestLeadGroupMutation(GraphQLTestCase):
def test_lead_group_delete(self):
Expand Down
2 changes: 1 addition & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5488,7 +5488,7 @@ type ProjectMutationType {
leadCreate(data: LeadInputType!): CreateLead
leadUpdate(data: LeadInputType!, id: ID!): UpdateLead
leadDelete(id: ID!): DeleteLead
leadBulk(items: [BulkLeadInputType!]): BulkLead
leadBulk(deleteIds: [ID!], items: [BulkLeadInputType!]): BulkLead
leadGroupDelete(id: ID!): DeleteLeadGroup
leadCopy(data: LeadCopyInputType!): LeadCopy
leadFilterSave(data: UserSavedLeadFilterInputType!): SaveUserSavedLeadFilter
Expand Down

0 comments on commit 1ad6182

Please sign in to comment.