|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | RSpec.describe Cms::DynamicComponents::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) } |
4 | 7 | let(:valid_course_card) { Cms::Mocks::DynamicComponents::CourseCard.generate_data(course_code: "CP228") } |
| 8 | + let(:replaced_course_card) { Cms::Mocks::DynamicComponents::CourseCard.generate_data(course_code: "RP228") } |
5 | 9 | let(:invalid_course_card) { Cms::Mocks::DynamicComponents::CourseCard.generate_data(course_code: "NV228") } |
6 | 10 |
|
7 | 11 | before do |
8 | 12 | stub_course_templates |
9 | 13 | stub_duration_units |
| 14 | + allow(Sentry).to receive(:capture_message) |
10 | 15 | end |
11 | 16 |
|
12 | 17 | context "with valid activity" do |
13 | | - before do |
14 | | - @card_section = Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::CourseCardSection.generate_raw_data(cards: [valid_course_card])) |
15 | | - end |
| 18 | + let(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::CourseCardSection.generate_raw_data(cards: [valid_course_card])) } |
| 19 | + let(:first_block) { card_section.cards_block.first } |
16 | 20 |
|
17 | 21 | it "should render as Cms::CardWrapperComponent" do |
18 | | - expect(@card_section.render).to be_a(Cms::CardWrapperComponent) |
| 22 | + expect(card_section.render).to be_a(Cms::CardWrapperComponent) |
19 | 23 | end |
20 | 24 |
|
21 | 25 | it "should render cards as Cms::DynamicsComponents::CourseCard" do |
22 | | - expect(@card_section.cards_block.first.render).to be_a(Cms::CourseCardComponent) |
| 26 | + expect(first_block.render).to be_a(Cms::CourseCardComponent) |
23 | 27 | end |
24 | 28 |
|
25 | 29 | it "should return true for valid code" do |
26 | | - expect(@card_section.cards_block.first.render.render?).to be true |
| 30 | + expect(first_block.render.render?).to be true |
| 31 | + end |
| 32 | + |
| 33 | + it "should have correct course instance" do |
| 34 | + expect(first_block.course.activity_code).to eq("CP228") |
| 35 | + end |
| 36 | + |
| 37 | + it "should not send sentry notification" do |
| 38 | + expect(Sentry).not_to have_received(:capture_message) |
27 | 39 | end |
28 | 40 | end |
29 | 41 |
|
30 | 42 | context "with invalid activity" do |
31 | | - before do |
32 | | - @card_section = Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::CourseCardSection.generate_raw_data(cards: [invalid_course_card])) |
33 | | - end |
| 43 | + let(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::CourseCardSection.generate_raw_data(cards: [invalid_course_card])) } |
| 44 | + let(:first_block) { card_section.cards_block.first } |
34 | 45 |
|
35 | 46 | it "should return false for invalid code" do |
36 | | - expect(@card_section.cards_block.first.render.render?).to be false |
| 47 | + expect(first_block.render.render?).to be false |
| 48 | + end |
| 49 | + |
| 50 | + it "should have no course instance" do |
| 51 | + expect(first_block.course).to be_nil |
| 52 | + end |
| 53 | + |
| 54 | + it "should not send sentry notification" do |
| 55 | + expect(Sentry).not_to have_received(:capture_message) |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context "with replaced activity" do |
| 60 | + let!(:card_section) { Cms::Providers::Strapi::Factories::ComponentFactory.process_component(Cms::Mocks::CourseCardSection.generate_raw_data(cards: [replaced_course_card])) } |
| 61 | + let(:first_block) { card_section.cards_block.first } |
| 62 | + |
| 63 | + it "should render as Cms::CardWrapperComponent" do |
| 64 | + expect(card_section.render).to be_a(Cms::CardWrapperComponent) |
| 65 | + end |
| 66 | + |
| 67 | + it "should render cards as Cms::DynamicsComponents::CourseCard" do |
| 68 | + expect(first_block.render).to be_a(Cms::CourseCardComponent) |
| 69 | + end |
| 70 | + |
| 71 | + it "should return true for valid code" do |
| 72 | + expect(first_block.render.render?).to be true |
| 73 | + end |
| 74 | + |
| 75 | + it "should have correct course instance" do |
| 76 | + expect(first_block.course.activity_code).to eq("CP229") |
| 77 | + end |
| 78 | + |
| 79 | + it "should send sentry notification" do |
| 80 | + 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") |
37 | 81 | end |
38 | 82 | end |
39 | 83 | end |
0 commit comments