|
384 | 384 |
|
385 | 385 | describe 'POST /v3/service_plans/:guid/visibility' do |
386 | 386 | let(:third_org) { VCAP::CloudController::Organization.make } |
| 387 | + let(:yet_another_org) { VCAP::CloudController::Organization.make } |
387 | 388 | let(:api_url) { "/v3/service_plans/#{guid}/visibility" } |
388 | 389 | let(:api_call) { lambda { |user_headers| post api_url, req_body.to_json, user_headers } } |
389 | 390 | let(:guid) { service_plan.guid } |
390 | | - |
391 | 391 | let(:service_plan) do |
392 | 392 | plan = VCAP::CloudController::ServicePlan.make(public: false) |
393 | 393 | VCAP::CloudController::ServicePlanVisibility.make(organization: org, service_plan: plan) |
394 | 394 | VCAP::CloudController::ServicePlanVisibility.make(organization: other_org, service_plan: plan) |
395 | 395 | plan |
396 | 396 | end |
| 397 | + let(:body) { { type: 'organization', organizations: [{ guid: third_org.guid }, { guid: yet_another_org.guid }] } } |
397 | 398 |
|
398 | 399 | context 'when the plan current visibility is "organization"' do |
399 | 400 | it 'can add new organizations' do |
400 | | - yet_another_org = VCAP::CloudController::Organization.make |
401 | | - body = { type: 'organization', organizations: [{ guid: third_org.guid }, { guid: yet_another_org.guid }] }.to_json |
402 | 401 | expected_orgs = [org, other_org, third_org, yet_another_org].map do |o| |
403 | 402 | { 'guid' => o.guid, 'name' => o.name } |
404 | 403 | end |
405 | 404 |
|
406 | | - post api_url, body, admin_headers |
| 405 | + post api_url, body.to_json, admin_headers |
407 | 406 | expect(last_response).to have_status_code(200) |
408 | 407 | expect(parsed_response['type']).to eq 'organization' |
409 | 408 | expect(parsed_response['organizations']).to match_array(expected_orgs) |
|
413 | 412 | expect(parsed_response['organizations']).to match_array(expected_orgs) |
414 | 413 | end |
415 | 414 |
|
| 415 | + it 'creates an audit event' do |
| 416 | + post api_url, body.to_json, admin_headers |
| 417 | + event = VCAP::CloudController::Event.find(type: 'audit.service_plan_visibility.update') |
| 418 | + expect(event).to be |
| 419 | + expect(event.actee).to eq(service_plan.guid) |
| 420 | + expect(event.data).to include({ |
| 421 | + 'request' => body.with_indifferent_access |
| 422 | + }) |
| 423 | + end |
| 424 | + |
416 | 425 | it 'ignores organizations that already have visibility' do |
417 | 426 | body = { type: 'organization', organizations: [{ guid: org.guid }, { guid: third_org.guid }] }.to_json |
418 | 427 | expected_orgs = [ |
|
442 | 451 |
|
443 | 452 | context 'when the current visibility type is not organization' do |
444 | 453 | let(:service_plan) { VCAP::CloudController::ServicePlan.make(public: true) } |
| 454 | + let(:body) { { type: 'organization', organizations: [{ guid: org.guid }] } } |
445 | 455 |
|
446 | 456 | it 'updates the visibility type AND add the orgs' do |
447 | | - body = { type: 'organization', organizations: [{ guid: org.guid }] }.to_json |
448 | | - post api_url, body, admin_headers |
| 457 | + post api_url, body.to_json, admin_headers |
449 | 458 |
|
450 | 459 | expect(parsed_response['type']).to eq 'organization' |
451 | 460 | expect(parsed_response['organizations']).to contain_exactly({ 'guid' => org.guid, 'name' => org.name }) |
452 | 461 | end |
| 462 | + |
| 463 | + it 'creates an audit event' do |
| 464 | + post api_url, body.to_json, admin_headers |
| 465 | + event = VCAP::CloudController::Event.find(type: 'audit.service_plan_visibility.update') |
| 466 | + expect(event).to be |
| 467 | + expect(event.actee).to eq(service_plan.guid) |
| 468 | + expect(event.data).to include({ |
| 469 | + 'request' => body.with_indifferent_access |
| 470 | + }) |
| 471 | + end |
453 | 472 | end |
454 | 473 |
|
455 | 474 | context 'when an org in the list does not exist' do |
|
497 | 516 | end |
498 | 517 |
|
499 | 518 | context 'when request type is not "organization"' do |
| 519 | + let(:body) { { type: 'public' } } |
| 520 | + |
500 | 521 | it 'behaves like a PATCH' do |
501 | | - body = { type: 'public' }.to_json |
502 | | - post api_url, body, admin_headers |
| 522 | + post api_url, body.to_json, admin_headers |
503 | 523 | expect(last_response).to have_status_code(200) |
504 | 524 |
|
505 | 525 | get api_url, {}, admin_headers |
506 | 526 | expect(parsed_response).to eq({ 'type' => 'public' }) |
507 | 527 | visibilities = VCAP::CloudController::ServicePlanVisibility.where(service_plan: service_plan).all |
508 | 528 | expect(visibilities).to be_empty |
509 | 529 | end |
| 530 | + |
| 531 | + it 'creates an audit event' do |
| 532 | + post api_url, body.to_json, admin_headers |
| 533 | + event = VCAP::CloudController::Event.find(type: 'audit.service_plan_visibility.update') |
| 534 | + expect(event).to be |
| 535 | + expect(event.actee).to eq(service_plan.guid) |
| 536 | + expect(event.data).to include({ |
| 537 | + 'request' => body.with_indifferent_access |
| 538 | + }) |
| 539 | + end |
510 | 540 | end |
511 | 541 |
|
512 | 542 | context 'permissions' do |
|
607 | 637 |
|
608 | 638 | it_behaves_like 'permissions for delete endpoint', ALL_PERMISSIONS |
609 | 639 | end |
| 640 | + |
| 641 | + it 'creates an audit event' do |
| 642 | + delete api_url, {}, admin_headers |
| 643 | + expect(last_response).to have_status_code(204) |
| 644 | + event = VCAP::CloudController::Event.find(type: 'audit.service_plan_visibility.delete') |
| 645 | + expect(event).to be |
| 646 | + expect(event.actee).to eq(service_plan.guid) |
| 647 | + expect(event.organization_guid).to eq(org.guid) |
| 648 | + end |
610 | 649 | end |
611 | 650 | end |
0 commit comments