mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
(test) update an availability
This commit is contained in:
parent
f1ef6d0391
commit
6c53b01741
@ -51,6 +51,7 @@ class API::AvailabilitiesController < API::ApiController
|
||||
end
|
||||
end
|
||||
|
||||
# This endpoint is used to remove a machine or a plan from the given availability
|
||||
def update
|
||||
authorize Availability
|
||||
if @availability.update(availability_params)
|
||||
|
36
test/integration/availabilities/update_test.rb
Normal file
36
test/integration/availabilities/update_test.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
# module definition
|
||||
module Availabilities; end
|
||||
|
||||
class Availabilities::UpdateTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
admin = User.with_role(:admin).first
|
||||
login_as(admin, scope: :user)
|
||||
end
|
||||
|
||||
test 'update an availability to remove an associated machine' do
|
||||
availability = Availability.find(4)
|
||||
machine = Machine.find(2)
|
||||
patch "/api/availabilities/#{availability.id}",
|
||||
params: {
|
||||
availability: {
|
||||
machines_attributes: [
|
||||
{ id: machine.id, _destroy: true }
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
assert_response :success
|
||||
assert_equal Mime[:json], response.content_type
|
||||
|
||||
res = json_response(response.body)
|
||||
assert_not_includes res[:machine_ids], machine.id
|
||||
|
||||
availability.reload
|
||||
|
||||
assert_empty availability.machines_availabilities.where(machine: machine)
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user