-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: invoice custom sections discard mutation (#2939)
## Description - Added a mutation to trigger InvoiceCustomSection::DestroyService; - Added single invoice_custom_section resolver
- Loading branch information
1 parent
73c0021
commit ade839d
Showing
11 changed files
with
362 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Mutations | ||
module InvoiceCustomSections | ||
class Destroy < BaseMutation | ||
include AuthenticableApiUser | ||
include RequiredOrganization | ||
|
||
REQUIRED_PERMISSION = 'invoice_custom_sections:delete' | ||
|
||
graphql_name 'DestroyInvoiceCustomSection' | ||
description 'Deletes an invoice_custom_section' | ||
|
||
argument :id, ID, required: true | ||
|
||
field :id, ID, null: true | ||
|
||
def resolve(id:) | ||
invoice_custom_section = current_organization.invoice_custom_sections.find_by(id:) | ||
result = ::InvoiceCustomSections::DestroyService.call(invoice_custom_section:) | ||
|
||
result.success? ? result.invoice_custom_section : result_error(result) | ||
end | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
app/graphql/resolvers/customers/invoice_custom_sections_resolver.rb
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
module Customers | ||
class InvoiceCustomSectionsResolver < Resolvers::BaseResolver | ||
end | ||
end | ||
end |
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Resolvers | ||
class InvoiceCustomSectionResolver < Resolvers::BaseResolver | ||
include AuthenticableApiUser | ||
include RequiredOrganization | ||
|
||
description 'Query a single invoice_custom_section of an organization' | ||
|
||
argument :id, ID, required: true, description: 'Uniq ID of the invoice_custom_section' | ||
|
||
type Types::InvoiceCustomSections::Object, null: false | ||
|
||
def resolve(id: nil) | ||
current_organization.invoice_custom_sections.find(id) | ||
rescue ActiveRecord::RecordNotFound | ||
not_found_error(resource: 'invoice_custom_section') | ||
end | ||
end | ||
end |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
spec/graphql/mutations/invoice_custom_sections/destroy_spec.rb
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Mutations::InvoiceCustomSections::Destroy, type: :graphql do | ||
subject(:result) do | ||
execute_graphql( | ||
current_user: membership.user, | ||
current_organization: membership.organization, | ||
permissions: required_permission, | ||
query:, | ||
variables: {input: {id: invoice_custom_section.id}} | ||
) | ||
end | ||
|
||
let(:query) do | ||
<<-GQL | ||
mutation($input: DestroyInvoiceCustomSectionInput!) { | ||
destroyInvoiceCustomSection(input: $input) { id } | ||
} | ||
GQL | ||
end | ||
|
||
let(:required_permission) { 'invoice_custom_sections:delete' } | ||
let(:membership) { create(:membership) } | ||
let(:invoice_custom_section) { create(:invoice_custom_section, organization: membership.organization) } | ||
|
||
before { invoice_custom_section } | ||
|
||
it_behaves_like 'requires current user' | ||
it_behaves_like 'requires current organization' | ||
it_behaves_like 'requires permission', 'invoice_custom_sections:delete' | ||
|
||
context 'when invoice custom section with such ID exists in the current organization' do | ||
it 'destroys the invoice custom section' do | ||
expect { result }.to change(InvoiceCustomSection, :count).from(1).to(0) | ||
end | ||
end | ||
|
||
context 'when invoice_custom_section with such ID does not exist in the current organization' do | ||
let(:invoice_custom_section) { create(:invoice_custom_section) } | ||
|
||
it 'does not delete the invoice_custom_section' do | ||
expect { result }.not_to change(InvoiceCustomSection, :count) | ||
end | ||
|
||
it 'returns an error' do | ||
expect_graphql_error(result:, message: 'Resource not found') | ||
end | ||
end | ||
end |
Oops, something went wrong.