-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VACMS-19453: Banner endpoint (#19342)
* VACMS-19453: Adds initial route for banners. * VACMS-19453: Updates banner endpoint to respond with banners for a given path. * VACMS-19453: Adds db seed script for banners. It does not automatically seed with db:seed. * VACMS-19453: Adds test for .by_path_and_type scope. * VACMS-19453: Adds test for controller. * VACMS-19453: Updates CODEOWNERS. * VACMS-19453: Move CODEOWNERS change to alphabetical. * VACMS-19453: Adds missing frozen string literal comment. * VACMS-19453: Adds support for subpage matching.
- Loading branch information
Showing
9 changed files
with
218 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module V0 | ||
class BannersController < ApplicationController | ||
service_tag 'banners' | ||
skip_before_action :authenticate | ||
|
||
def by_path | ||
path = params[:path] | ||
# Default to 'full_width_banner_alert' banner (bundle) type. | ||
banner_type = params.fetch(:type, 'full_width_banner_alert') | ||
banners = [] | ||
banners = Banner.by_path_and_type(path, banner_type) if path && banner_type | ||
response = { banners: banners, path: path, banner_type: banner_type } | ||
render json: response | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
# Create sample Banner records | ||
puts 'Creating sample banners...' | ||
|
||
Banner.create!( | ||
entity_id: 1, | ||
entity_bundle: 'full_width_banner_alert', | ||
headline: 'Important Update', | ||
alert_type: 'warning', | ||
show_close: true, | ||
content: 'Please be aware of system maintenance scheduled for tomorrow.', | ||
context: | ||
[ | ||
{ | ||
entity: { | ||
title: 'Operating status | VA Facility health care', | ||
entityUrl: { | ||
path: '/va-facility-health-care/operating-status' | ||
}, | ||
fieldOffice: { | ||
entity: { | ||
fieldVamcEhrSystem: 'vista', | ||
title: 'VA Facility health care', | ||
entityUrl: { | ||
path: '/va-facility-health-care' | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
entity: { | ||
title: 'Operating status | VAMC health care', | ||
entityUrl: { | ||
path: '/vamc-health-care/operating-status' | ||
}, | ||
fieldOffice: { | ||
entity: { | ||
fieldVamcEhrSystem: 'vista', | ||
title: 'VAMC health care', | ||
entityUrl: { | ||
path: '/vamc-health-care' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
operating_status_cta: true, | ||
email_updates_button: true, | ||
find_facilities_cta: false, | ||
limit_subpage_inheritance: false | ||
) | ||
|
||
puts 'Sample banners created!' |
38 changes: 38 additions & 0 deletions
38
modules/banners/spec/controllers/v0/banners_controller_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe V0::BannersController, type: :controller do | ||
describe 'GET #by_path' do | ||
let(:path) { '/sample/path' } | ||
let(:banner_type) { 'full_width_banner_alert' } | ||
|
||
# Create banners that should match the query | ||
let!(:matching_banner) do | ||
create(:banner, entity_bundle: banner_type, context: [{ entity: { entityUrl: { path: path } } }]) | ||
end | ||
let!(:non_matching_banner) do | ||
create(:banner, entity_bundle: 'different_type', context: [{ entity: { entityUrl: { path: '/other/path' } } }]) | ||
end | ||
|
||
it 'returns banners matching the specified path and banner type' do | ||
get :by_path, params: { path: path, type: banner_type } | ||
|
||
expect(response).to have_http_status(:ok) | ||
json_response = JSON.parse(response.body) | ||
|
||
# Ensure only the matching banner is returned | ||
expect(json_response['banners'].length).to eq(1) | ||
expect(json_response['banners'][0]['id']).to eq(matching_banner.id) | ||
end | ||
|
||
it 'returns an empty array if no banners match the criteria' do | ||
get :by_path, params: { path: '/nonexistent/path', type: 'nonexistent_type' } | ||
|
||
expect(response).to have_http_status(:ok) | ||
json_response = JSON.parse(response.body) | ||
|
||
expect(json_response['banners']).to eq([]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters