Skip to content

Commit 5c4e145

Browse files
committed
Sort out issues after rebasing
1 parent 46cbff2 commit 5c4e145

File tree

8 files changed

+132
-126
lines changed

8 files changed

+132
-126
lines changed

app/jobs/send_cms_emails_job.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ def perform
44
page = 1
55
loop do
66
email_templates = Cms::Collections::EmailTemplate.all(page, PER_PAGE)
7-
break if email_templates.resources.empty?
8-
97
email_templates.resources.each { process_template(_1) }
8+
break if (page * PER_PAGE) > email_templates.total_records
109
page += 1
1110
end
1211
end

app/services/cms/collections/email_template.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ module Collections
33
class EmailTemplate < Resource
44
def self.is_collection = true
55

6-
def self.collection_attribute_mapping
6+
def self.collection_attribute_mappings
77
[
88
{model: Cms::Models::EmailTemplate, key: nil, param_name: :template},
9-
{model: Cms::Models::Slug, key: nil, param_name: :slug}
109
]
1110
end
1211

spec/components/cms/rich_text_block_component_spec.rb

Lines changed: 115 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
]
3232
]))
3333

34-
expect(page).to have_text("Hello world!")
34+
expect(page).to have_css("p", text: "Hello world!")
3535
end
3636

3737
it "renders a large heading" do
@@ -43,7 +43,31 @@
4343
]
4444
]))
4545

46-
expect(page).to have_text("Heading world!")
46+
expect(page).to have_css(".govuk-heading-l", text: "Heading world!")
47+
end
48+
49+
it "renders a medium heading" do
50+
render_inline(described_class.new(blocks: [
51+
type: "heading",
52+
level: 2,
53+
children: [
54+
{type: "text", text: "Heading world!"}
55+
]
56+
]))
57+
58+
expect(page).to have_css(".govuk-heading-m", text: "Heading world!")
59+
end
60+
61+
it "renders a small heading" do
62+
render_inline(described_class.new(blocks: [
63+
type: "heading",
64+
level: 3,
65+
children: [
66+
{type: "text", text: "Heading world!"}
67+
]
68+
]))
69+
70+
expect(page).to have_css(".govuk-heading-s", text: "Heading world!")
4771
end
4872

4973
it "renders some text" do
@@ -54,6 +78,46 @@
5478
expect(page).to have_text("Just text")
5579
end
5680

81+
it "renders bold text" do
82+
render_inline(described_class.new(blocks: [
83+
{type: "text", text: "Bold text", bold: true}
84+
]))
85+
86+
expect(page).to have_css(".cms-rich-text-block-component__text--bold", text: "Bold text")
87+
end
88+
89+
it "renders italic text" do
90+
render_inline(described_class.new(blocks: [
91+
{type: "text", text: "Italic text", italic: true}
92+
]))
93+
94+
expect(page).to have_css(".cms-rich-text-block-component__text--italic", text: "Italic text")
95+
end
96+
97+
it "renders underlined text" do
98+
render_inline(described_class.new(blocks: [
99+
{type: "text", text: "Underlined text", underline: true}
100+
]))
101+
102+
expect(page).to have_css(".cms-rich-text-block-component__text--underline", text: "Underlined text")
103+
end
104+
105+
it "renders strikethrough text" do
106+
render_inline(described_class.new(blocks: [
107+
{type: "text", text: "Strikethrough text", strikethrough: true}
108+
]))
109+
110+
expect(page).to have_css(".cms-rich-text-block-component__text--strikethrough", text: "Strikethrough text")
111+
end
112+
113+
it "renders code text" do
114+
render_inline(described_class.new(blocks: [
115+
{type: "text", text: "Code text", code: true}
116+
]))
117+
118+
expect(page).to have_css(".cms-rich-text-block-component__text--code", text: "Code text")
119+
end
120+
57121
it "renders a link" do
58122
render_inline(described_class.new(blocks: [
59123
{
@@ -65,7 +129,7 @@
65129
}
66130
]))
67131

68-
expect(page).to have_text("A link to google (https://www.google.com)")
132+
expect(page).to have_link("A link to google", href: "https://www.google.com")
69133
end
70134

71135
it "renders an ordered list" do
@@ -80,8 +144,10 @@
80144
}
81145
]))
82146

83-
expect(page).to have_text("1. Item 1")
84-
expect(page).to have_text("2. Item 2")
147+
expect(page).to have_css("ol.govuk-list--number")
148+
expect(page).to have_css("ol", count: 1)
149+
expect(page).to have_css("ol li", text: "Item 1")
150+
expect(page).to have_css("ol li", text: "Item 2")
85151
end
86152

87153
it "renders an unordered list" do
@@ -96,7 +162,49 @@
96162
}
97163
]))
98164

99-
expect(page).to have_text("* Item 1")
100-
expect(page).to have_text("* Item 2")
165+
expect(page).to have_css("ul", count: 1)
166+
expect(page).to have_css("ul li", text: "Item 1")
167+
expect(page).to have_css("ul li", text: "Item 2")
168+
end
169+
170+
it "renders an image" do
171+
formats = {
172+
medium: {url: "/an-image-medium.png"},
173+
large: {url: "/an-image-large.png"}
174+
}
175+
render_inline(described_class.new(blocks: [
176+
{
177+
type: "image",
178+
image: Cms::Models::Image.new(url: "/an-image.png", alt: "", caption: "", formats: formats, default_size: :medium)
179+
}
180+
]))
181+
182+
expect(page).to have_css("img[src='/an-image-medium.png']")
183+
end
184+
185+
it "renders a quote" do
186+
render_inline(described_class.new(blocks: [
187+
{
188+
type: "quote",
189+
children: [
190+
{type: "text", text: "Quoted"}
191+
]
192+
}
193+
]))
194+
195+
expect(page).to have_css("blockquote", text: "Quoted")
196+
end
197+
198+
it "renders a hr when given three consecutive hyphens" do
199+
render_inline(described_class.new(blocks: [
200+
{
201+
type: "paragraph",
202+
children: [
203+
{type: "text", text: "---"}
204+
]
205+
}
206+
]))
207+
208+
expect(page).to have_css("hr")
101209
end
102210
end

spec/components/cms/rich_text_block_text_component_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "rails_helper"
22

3-
RSpec.describe Cms::RichTextBlockTextComponent, type: :component do
3+
RSpec.describe CmsRichTextBlockTextComponent, type: :component do
44
it "renders a paragraph" do
55
render_inline(described_class.new(blocks: [
66
type: "paragraph",

spec/components/cms_email_course_list_component_spec.rb

Lines changed: 0 additions & 15 deletions
This file was deleted.

spec/components/cms_rich_text_block_text_component_spec.rb

Lines changed: 0 additions & 93 deletions
This file was deleted.

spec/jobs/send_cms_emails_job_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
before do
1616
stub_strapi_email_template(email_template_1_slug, email_template: email_template_1)
1717
stub_strapi_email_template(email_template_2_slug, email_template: email_template_2)
18-
stub_strapi_email_templates(email_templates: [email_template_1, email_template_2])
18+
stub_strapi_email_templates(email_templates: [email_template_1, email_template_2], page: 1, page_size: 50)
1919

2020
allow_any_instance_of(Programmes::ProgressQuery).to receive(:call).and_return(users)
2121
end

spec/support/cms/providers/strapi/strapi_stubs.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,28 @@ def stub_strapi_web_page_not_found(key)
162162
end
163163
end
164164

165-
def stub_strapi_email_template(key, email_template: Cms::Mocks::EmailTemplate.generate_raw_data)
165+
def stub_strapi_email_templates(email_templates: Array.new(4) { Cms::Mocks::EmailTemplate.generate_raw_data }, page: 1, page_size: 10)
166166
if as_graphql
167-
stub_strapi_graphql_query("emailTemplates", email_template, unique_key: key)
167+
stub_strapi_graphql_collection_query("emailTemplates", email_templates)
168168
else
169-
stub_request(:get, /^https:\/\/strapi.teachcomputing.org\/api\/email-templates\/#{key}/).to_return_json(body: {data: email_template})
169+
stub_request(:get, /^https:\/\/strapi.teachcomputing.org\/api\/email-templates/).to_return_json(body: to_strapi_collection(email_templates, page:, page_size:))
170170
end
171171
end
172172

173173
def stub_strapi_email_template(key, email_template: Cms::Mocks::EmailTemplate.generate_raw_data)
174-
stub_request(:get, /^https:\/\/strapi.teachcomputing.org\/api\/email-templates\/#{key}/).to_return_json(body: {data: email_template})
174+
if as_graphql
175+
stub_strapi_graphql_query("emailTemplates", email_template, unique_key: key)
176+
else
177+
stub_request(:get, /^https:\/\/strapi.teachcomputing.org\/api\/email-templates\/#{key}/).to_return_json(body: {data: email_template})
178+
end
175179
end
176180

177181
def stub_strapi_email_template_missing(key)
178-
stub_request(:get, /^https:\/\/strapi.teachcomputing.org\/api\/email-templates\/#{key}/).to_return_json(body: not_found_response, status: 404)
182+
if as_graphql
183+
stub_strapi_graphql_query_missing("emailTemplates")
184+
else
185+
stub_request(:get, /^https:\/\/strapi.teachcomputing.org\/api\/email-templates\/#{key}/).to_return_json(body: not_found_response, status: 404)
186+
end
179187
end
180188

181189
def stub_strapi_programme(key, programme: Cms::Mocks::Programme.generate_raw_data)

0 commit comments

Comments
 (0)