mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 05:05:45 +02:00
added endpoint for get cancelled invoices
This commit is contained in:
parent
5a19149129
commit
62ce5ff561
4 changed files with 70 additions and 4 deletions
|
@ -0,0 +1,32 @@
|
|||
module Api
|
||||
module V1
|
||||
module AccreditationCenter
|
||||
class InvoiceStatusController < ::Api::V1::AccreditationCenter::BaseController
|
||||
def index
|
||||
username, password = Base64.urlsafe_decode64(basic_token).split(':')
|
||||
@current_user ||= ApiUser.find_by(username: username, plain_text_password: password)
|
||||
|
||||
return render json: { errors: 'No user found' }, status: :not_found if @current_user.nil?
|
||||
|
||||
@invoices = @current_user.registrar.invoices.select { |i| i.cancelled_at != nil }
|
||||
|
||||
if @invoices
|
||||
render json: { code: 1000, invoices: @invoices },
|
||||
status: :found
|
||||
else
|
||||
render json: { errors: 'No invoices' }, status: :not_found
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def basic_token
|
||||
pattern = /^Basic /
|
||||
header = request.headers['Authorization']
|
||||
header = header.gsub(pattern, '') if header&.match(pattern)
|
||||
header.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -127,6 +127,9 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
namespace :accreditation_center do
|
||||
# At the moment invoice_status endpoint returns only cancelled invoices. But in future logic of this enpoint can change.
|
||||
# And it will need to return invoices of different statuses. I decided to leave the name of the endpoint "invoice_status"
|
||||
resources :invoice_status, only: [ :index ]
|
||||
resource :domains, only: [ :show ], param: :name
|
||||
resource :contacts, only: [ :show ], param: :id
|
||||
# resource :auth, only: [ :index ]
|
||||
|
|
|
@ -2,16 +2,14 @@ require 'test_helper'
|
|||
|
||||
class DomainsTest < ApplicationIntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@domain = domains(:shop)
|
||||
end
|
||||
|
||||
def test_get_domain_info
|
||||
get "/api/v1/accreditation_center/domains/?name=#{@domain.name}"
|
||||
get "/api/v1/accreditation_center/domains/?name=shop.test"
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal json[:domain][:name], @domain.name
|
||||
assert_equal json[:domain][:name], "shop.test"
|
||||
end
|
||||
|
||||
def test_return_code_error_if_valid_domain_name
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
require 'test_helper'
|
||||
|
||||
class DomainsTest < ApplicationIntegrationTest
|
||||
def setup
|
||||
super
|
||||
|
||||
@user = users(:api_bestnames)
|
||||
@header = { 'Authorization' => "Basic #{generate_base64}" }
|
||||
end
|
||||
|
||||
def test_should_return_cancelled_invoices
|
||||
date_now = Time.now
|
||||
|
||||
get "/api/v1/accreditation_center/invoice_status", headers: @header
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal json[:invoices].count, 0
|
||||
|
||||
invoice = @user.registrar.invoices.last
|
||||
invoice.update(cancelled_at: date_now)
|
||||
|
||||
get "/api/v1/accreditation_center/invoice_status", headers: @header
|
||||
json = JSON.parse(response.body, symbolize_names: true)
|
||||
|
||||
assert_equal json[:invoices].count, 1
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_base64
|
||||
Base64.encode64("#{@user.username}:#{@user.plain_text_password}")
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue