|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe Cms::Models::DynamicComponents::ContentBlocks::CourseCard do |
| 4 | + let!(:activity) { Activity.find_by(stem_activity_code: "CP228") || create(:activity, stem_activity_code: "CP228") } |
| 5 | + let!(:new_activity) { Activity.find_by(stem_activity_code: "CP229") || create(:activity, stem_activity_code: "CP229") } |
| 6 | + let!(:replaced_activity) { create(:activity, stem_activity_code: "RP228", replaced_by: new_activity) } |
| 7 | + let(:valid_course_card) { Cms::Mocks::DynamicComponents::ContentBlocks::CourseCard.generate_data(course_code: "CP228") } |
| 8 | + let(:replaced_course_card) { Cms::Mocks::DynamicComponents::ContentBlocks::CourseCard.generate_data(course_code: "RP228") } |
| 9 | + let(:invalid_course_card) { Cms::Mocks::DynamicComponents::ContentBlocks::CourseCard.generate_data(course_code: "NV228") } |
| 10 | + |
| 11 | + context "with achiever match" do |
| 12 | + before do |
| 13 | + stub_course_templates |
| 14 | + stub_duration_units |
| 15 | + allow(Sentry).to receive(:capture_message) |
| 16 | + end |
| 17 | + |
| 18 | + context "with valid activity" do |
| 19 | + let(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::DynamicComponents::Blocks::CourseCardSection.generate_raw_data(cards: [valid_course_card])) } |
| 20 | + let(:first_block) { card_section.cards_block.first } |
| 21 | + |
| 22 | + it "should render as Cms::CardWrapperComponent" do |
| 23 | + expect(card_section.render).to be_a(Cms::CardWrapperComponent) |
| 24 | + end |
| 25 | + |
| 26 | + it "should render cards as Cms::DynamicsComponents::CourseCard" do |
| 27 | + expect(first_block.render).to be_a(Cms::CourseCardComponent) |
| 28 | + end |
| 29 | + |
| 30 | + it "should return true for valid code" do |
| 31 | + expect(first_block.render.render?).to be true |
| 32 | + end |
| 33 | + |
| 34 | + it "should have correct course instance" do |
| 35 | + expect(first_block.course.activity_code).to eq("CP228") |
| 36 | + end |
| 37 | + |
| 38 | + it "should not send sentry notification" do |
| 39 | + expect(Sentry).not_to have_received(:capture_message) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context "with invalid activity" do |
| 44 | + let(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::DynamicComponents::Blocks::CourseCardSection.generate_raw_data(cards: [invalid_course_card])) } |
| 45 | + let(:first_block) { card_section.cards_block.first } |
| 46 | + |
| 47 | + it "should return false for invalid code" do |
| 48 | + expect(first_block.render.render?).to be false |
| 49 | + end |
| 50 | + |
| 51 | + it "should have no course instance" do |
| 52 | + expect(first_block.course).to be_nil |
| 53 | + end |
| 54 | + |
| 55 | + it "should not send sentry notification" do |
| 56 | + expect(Sentry).not_to have_received(:capture_message) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + context "with replaced activity" do |
| 61 | + let!(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::DynamicComponents::Blocks::CourseCardSection.generate_raw_data(cards: [replaced_course_card])) } |
| 62 | + let(:first_block) { card_section.cards_block.first } |
| 63 | + |
| 64 | + it "should render as Cms::CardWrapperComponent" do |
| 65 | + expect(card_section.render).to be_a(Cms::CardWrapperComponent) |
| 66 | + end |
| 67 | + |
| 68 | + it "should render cards as Cms::DynamicsComponents::CourseCard" do |
| 69 | + expect(first_block.render).to be_a(Cms::CourseCardComponent) |
| 70 | + end |
| 71 | + |
| 72 | + it "should return true for valid code" do |
| 73 | + expect(first_block.render.render?).to be true |
| 74 | + end |
| 75 | + |
| 76 | + it "should have correct course instance" do |
| 77 | + expect(first_block.course.activity_code).to eq("CP229") |
| 78 | + end |
| 79 | + |
| 80 | + it "should send sentry notification" do |
| 81 | + expect(Sentry).to have_received(:capture_message).once.with("Course card has been found with a now replaced course (RP228 -> CP229) - get comms to update Strapi to new course instance") |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context "without achiever" do |
| 87 | + before do |
| 88 | + stub_failed_course_templates |
| 89 | + end |
| 90 | + |
| 91 | + context "with valid activity" do |
| 92 | + let(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::DynamicComponents::Blocks::CourseCardSection.generate_raw_data(cards: [valid_course_card])) } |
| 93 | + let(:first_block) { card_section.cards_block.first } |
| 94 | + |
| 95 | + it "should render as Cms::CardWrapperComponent" do |
| 96 | + expect(card_section.render).to be_a(Cms::CardWrapperComponent) |
| 97 | + end |
| 98 | + |
| 99 | + it "should set course to nil" do |
| 100 | + expect(first_block.course).to be nil |
| 101 | + end |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments