1
0
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:
Sylvain 2023-02-17 13:34:34 +01:00
parent f1ef6d0391
commit 6c53b01741
2 changed files with 37 additions and 0 deletions

View File

@ -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)

View 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