Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoice pagination #756

Open
wants to merge 1 commit into
base: 4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module MnoEnterprise
class Jpi::V1::InvoicesController < ApplicationController
class Jpi::V1::InvoicesController < Jpi::V1::BaseResourceController
include MnoEnterprise::Concerns::Controllers::Jpi::V1::InvoicesController
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
json.invoices do
json.array! @invoices do |invoice|
json.started_at invoice.started_at
json.ended_at invoice.ended_at
json.amount AccountingjsSerializer.serialize(invoice.total_due)
json.paid invoice.paid?
json.link mno_enterprise.jpi_v1_invoice_path(invoice.slug)
end
end
2 changes: 2 additions & 0 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@
end
end

resources :invoices, only: [:index]

resources :app_instances_sync, only: [:create, :index]

resources :audit_events, only: [:index]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ module MnoEnterprise::Concerns::Controllers::Jpi::V1::InvoicesController
# context where it is included rather than being executed in the module's context

included do
before_filter :authenticate_user!
before_filter :redirect_to_lounge_if_unconfirmed
before_filter :authenticate_user!, only: :show
before_filter :redirect_to_lounge_if_unconfirmed, only: :show
before_filter :check_authorization, only: :index
end

#==================================================================
# Instance methods
#================================================================
#==================================================================
def index
authorize! :manage_billing, parent_organization
# @invoices = MnoEnterprise::Invoice.find('organization.id': parent_organization.id)
query = MnoEnterprise::Invoice.apply_query_params(params,MnoEnterprise::Invoice.where('organization.id': parent_organization.id))
@invoices = query.to_a
response.headers['X-Total-Count'] = query.meta.record_count
end

# GET /mnoe/jpi/v1/invoices/201504-NU4
# Invoices endpoint for admins of an organization, rather than admin of a tenant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module MnoEnterprise
describe Jpi::V1::InvoicesController, type: :controller do
include MnoEnterprise::TestingSupport::JpiV1TestHelper

render_views
routes { MnoEnterprise::Engine.routes }

Expand All @@ -14,13 +16,14 @@ module MnoEnterprise
let(:user) { build(:user, organizations: [organization]) }
let(:invoice) {build(:invoice, organization: organization, organization_id: organization.id)}

let!(:current_user_stub) { stub_user(user) }
before do
stub_api_v2(:get, '/invoices', [invoice], [:organization], {filter:{slug:invoice.slug}, page:{number: 1, size: 1}})
organization.orga_relations << build(:orga_relation, user_id: user.id, organization_id: organization.id, role: "Super Admin")
end

let!(:current_user_stub) { stub_user(user) }

describe "GET #show" do
before do
stub_api_v2(:get, '/invoices', [invoice], [:organization], {filter:{slug:invoice.slug}, page:{number: 1, size: 1}})
end
before { sign_in user }
subject { get :show, id: invoice.slug }

Expand All @@ -30,6 +33,27 @@ module MnoEnterprise
it { subject; expect(response).to be_success }
end

describe "GET #index" do
before { request.env['HTTP_ACCEPT'] = 'application/json' }
before do
stub_api_v2(:get, "/organizations/#{organization.id}", [organization], [:orga_relations, :users])
stub_api_v2(:get, "/invoices", [invoice], [], {filter:{'organization.id':organization.id}})
end

before { sign_in user }
subject { get :index, organization_id: organization.id }

# it_behaves_like "a navigatable protected user action"
# it_behaves_like "a user protected resource"
it_behaves_like "jpi v1 protected action"

it { subject; expect(response).to be_success }
it 'returns the correct invoices' do
subject
expect(assigns(:invoices).first.slug).to eq invoice.slug
end

end
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module MnoEnterprise
RSpec.describe Jpi::V1::InvoicesController, type: :routing do
routes { MnoEnterprise::Engine.routes }

it "routes to #index" do
expect(get("/jpi/v1/organizations/1233/invoices")).to route_to("mno_enterprise/jpi/v1/invoices#index", organization_id: "1233")
end

it "routes to #show" do
expect(get("/jpi/v1/invoices/201504-NU4")).to route_to("mno_enterprise/jpi/v1/invoices#show", id: '201504-NU4')
end
Expand Down
Empty file removed api/{
Empty file.