Skip to content

Feat/213 bling order items controller #214

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

Merged
merged 6 commits into from
Mar 5, 2024
Merged
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
18 changes: 18 additions & 0 deletions app/controllers/bling_order_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ class BlingOrderItemsController < ApplicationController
before_action :default_initial_date, :disable_initial_date, :default_final_date
include Pagy::Backend
inherit_resources
actions :all, except: %i[new create]
decorates_assigned :bling_order_item

def index
authorize Customer
index!
end

def show
authorize Customer
show!
end

def edit
authorize Customer
edit!
end

def update
authorize Customer
update! do |success, failure|
success.html do
flash[:notice] = t('flash.success.update', model: bling_order_item.class_name)
Expand All @@ -18,6 +35,7 @@ def update
end

def destroy
authorize Customer
if resource.deleted_at_bling!
redirect_to resource, notice: t('flash.success.destroy.bling_order_item')
else
Expand Down
160 changes: 108 additions & 52 deletions spec/requests/bling_order_items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,113 +10,169 @@
FactoryBot.create_list(:bling_order_item, 2, account_id: user.account.id)
end

context 'when there is no filter' do
before { get bling_order_items_path }
context 'when authorized' do
include_context 'with bling feature'

it 'is success' do
get bling_order_items_path
expect(response).to be_successful
end
end

context 'when unauthorized' do
it 'redirects to products path' do
get bling_order_items_path
expect(response).to redirect_to(products_path)
end
end
end

describe 'GET /show' do
let(:bling_order_item) { FactoryBot.create(:bling_order_item) }

before do
get bling_order_item_path(bling_order_item)
context 'when authorized' do
include_context 'with bling feature'

it 'is success' do
get bling_order_item_path(bling_order_item)
expect(response).to be_successful
end
end

it 'is success' do
expect(response).to be_successful
context 'when unauthorized' do
it 'redirects to products path' do
get bling_order_item_path(bling_order_item)
expect(response).to redirect_to(products_path)
end
end
end

describe 'GET /edit' do
let(:bling_order_item) { FactoryBot.create(:bling_order_item) }

before do
get edit_bling_order_item_path(bling_order_item)
context 'when authorized' do
include_context 'with bling feature'

it 'is success' do
get edit_bling_order_item_path(bling_order_item)
expect(response).to be_successful
end
end

it 'is success' do
expect(response).to be_successful
context 'when unauthorized' do
it 'redirects to products path' do
get edit_bling_order_item_path(bling_order_item)
expect(response).to redirect_to(products_path)
end
end
end

describe 'GET /update' do
let(:bling_order_item) { FactoryBot.create(:bling_order_item) }
let(:situation_id) { '99' }

context 'when authorized' do
include_context 'with bling feature'
context 'when permitted attribute' do
before do
patch bling_order_item_path(bling_order_item), params: { bling_order_item: { situation_id: } }
end

context 'when permitted attribute' do
before do
patch bling_order_item_path(bling_order_item), params: { bling_order_item: { situation_id: } }
end
it 'is found' do
expect(response).to have_http_status(:found)
end

it 'is found' do
expect(response).to have_http_status(:found)
it 'is 99' do
expect(bling_order_item.reload.situation_id).to eq(situation_id)
end
end

it 'is 99' do
expect(bling_order_item.reload.situation_id).to eq(situation_id)
end
end
context 'when not permitted attribute' do
let(:alteration_date) { '2024-1-1' }

context 'when not permitted attribute' do
let(:alteration_date) { '2024-1-1' }
before do
patch bling_order_item_path(bling_order_item), params: { bling_order_item: { alteration_date: } }
end

before do
patch bling_order_item_path(bling_order_item), params: { bling_order_item: { alteration_date: } }
it 'is found' do
expect(response).to have_http_status(:found)
end

it 'does not change alteration date' do
expect(bling_order_item.reload.alteration_date.to_date).not_to eq(alteration_date.to_date)
end
end
end

it 'is found' do
expect(response).to have_http_status(:found)
context 'when unauthorized' do
before do
patch bling_order_item_path(bling_order_item), params: { bling_order_item: { situation_id: } }
end

it 'does not change alteration date' do
expect(bling_order_item.reload.alteration_date.to_date).not_to eq(alteration_date.to_date)
it 'redirects to products path' do
expect(response).to redirect_to(products_path)
end
end
end

describe 'DELETE /destroy' do
let(:bling_order_item) { FactoryBot.create(:bling_order_item) }

context 'when not found at bling' do
let(:not_found_bling_order_id) { '9829778376' }
context 'when authorized' do
include_context 'with bling feature'
context 'when not found at bling' do
let(:not_found_bling_order_id) { '9829778376' }

before do
bling_order_item.update(bling_order_id: not_found_bling_order_id)
VCR.use_cassette('not_found_at_bling', erb: true) do
delete bling_order_item_path(bling_order_item)
before do
bling_order_item.update(bling_order_id: not_found_bling_order_id)
VCR.use_cassette('not_found_at_bling', erb: true) do
delete bling_order_item_path(bling_order_item)
end
end
end

it 'is found' do
expect(response).to have_http_status(:found)
end
it 'is found' do
expect(response).to have_http_status(:found)
end

it 'changes status to deleted at bling' do
expect(bling_order_item.reload.situation_id).to eq(BlingOrderItemStatus::DELETE_IN_PROGRESS)
it 'changes status to deleted at bling' do
expect(bling_order_item.reload.situation_id).to eq(BlingOrderItemStatus::DELETE_IN_PROGRESS)
end
end
end

context 'when it is found at bling' do
let(:found_bling_order_id) { '9447042612' }
context 'when it is found at bling' do
let(:found_bling_order_id) { '9447042612' }

before do
bling_order_item.update(bling_order_id: found_bling_order_id)
VCR.use_cassette('found_at_bling', erb: true) do
delete bling_order_item_path(bling_order_item)
before do
bling_order_item.update(bling_order_id: found_bling_order_id)
VCR.use_cassette('found_at_bling', erb: true) do
delete bling_order_item_path(bling_order_item)
end
end
end

it 'is found' do
expect(response).to have_http_status(:found)
it 'is found' do
expect(response).to have_http_status(:found)
end

it 'keeps status as original' do
expect(bling_order_item.reload.situation_id).to eq(BlingOrderItemStatus::DELETE_IN_PROGRESS)
end
end
end

context 'whe unauthorized' do
context 'when not found at bling' do
let(:not_found_bling_order_id) { '9829778376' }

it 'keeps status as original' do
expect(bling_order_item.reload.situation_id).to eq(BlingOrderItemStatus::DELETE_IN_PROGRESS)
before do
bling_order_item.update(bling_order_id: not_found_bling_order_id)
VCR.use_cassette('not_found_at_bling', erb: true) do
delete bling_order_item_path(bling_order_item)
end
end

it 'redirects to products path' do
expect(response).to redirect_to(products_path)
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/requests/suppliers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Suppliers', type: :request do
include_context 'with user signed in'

describe 'GET /suppliers' do
it 'is success' do
get suppliers_url
expect(response).to have_http_status(:success)
end
end
end