|
3 | 3 | require 'test_helper' |
4 | 4 |
|
5 | 5 | class Admin::Api::ApplicationPlansControllerTest < ActionDispatch::IntegrationTest |
| 6 | + include ActiveJob::TestHelper |
6 | 7 |
|
7 | 8 | def setup |
8 | 9 | Settings::Switch.any_instance.stubs(:allowed?).returns(true) |
@@ -77,6 +78,20 @@ def test_index_json |
77 | 78 | assert_equal 2, JSON.parse(response.body)['plans'].length |
78 | 79 | end |
79 | 80 |
|
| 81 | + def test_update_syncs_plan_name_to_backend |
| 82 | + application_plan = FactoryBot.create(:application_plan, name: 'old name', issuer: service) |
| 83 | + cinstances = FactoryBot.create_list(:simple_cinstance, 2, plan: application_plan) |
| 84 | + |
| 85 | + ThreeScale::Core::Application.expects(:save_batch) |
| 86 | + .with(service.backend_id, expected_backend_applications(cinstances, application_plan, 'new name')) |
| 87 | + |
| 88 | + Sidekiq::Testing.inline! do |
| 89 | + put admin_api_service_application_plan_path(application_plan, service_id: service.id, format: :json, access_token: @token, |
| 90 | + application_plan: { name: 'new name' }) |
| 91 | + assert_response :success |
| 92 | + end |
| 93 | + end |
| 94 | + |
80 | 95 | def test_approval_required |
81 | 96 | assert_difference service.application_plans.method(:count) do |
82 | 97 | post admin_api_service_application_plans_path(application_plan_params(approval_required: true)) |
@@ -160,6 +175,15 @@ def current_account |
160 | 175 |
|
161 | 176 | attr_reader :service |
162 | 177 |
|
| 178 | + def expected_backend_applications(cinstances, plan, plan_name) |
| 179 | + cinstances.map do |cinstance| |
| 180 | + state = cinstance.state |
| 181 | + state = :active if cinstance.live? |
| 182 | + { service_id: plan.service.backend_id, id: cinstance.application_id, state: state, |
| 183 | + plan_id: plan.id, plan_name: plan_name, redirect_url: cinstance.redirect_url } |
| 184 | + end |
| 185 | + end |
| 186 | + |
163 | 187 | def application_plan_params(state_event: 'publish', approval_required: 0) |
164 | 188 | @application_plan_params ||= { |
165 | 189 | service_id: service.id, |
|
0 commit comments