Module: PlanMyStuff::TestHelpers
- Defined in:
- lib/plan_my_stuff/test_helpers.rb
Overview
Test support for consuming apps. Provides:
-
‘PlanMyStuff.test_mode!` to stub all API calls
-
Factory-style builders: ‘build_issue`, `build_comment`, `build_project`
-
RSpec matchers: ‘expect_pms_issue_created`, `expect_pms_comment_created`, `expect_pms_item_moved`
Usage:
require 'plan_my_stuff/test_helpers'
RSpec.configure do |config|
config.include PlanMyStuff::TestHelpers
end
Defined Under Namespace
Modules: Notifications
Class Method Summary collapse
-
.build_comment(body: 'Test comment', visibility: :public, id: 1, issue: nil, metadata: {}) ⇒ PlanMyStuff::Comment
Builds a fake persisted Comment without hitting the API.
-
.build_issue(title: 'Test Issue', body: 'Test body', state: :open, number: 1, repo: 'TestOrg/TestRepo', labels: [], metadata: {}) ⇒ PlanMyStuff::Issue
Builds a fake persisted Issue without hitting the API.
-
.build_project(title: 'Test Project', number: 1, statuses: [], items: []) ⇒ PlanMyStuff::Project
Builds a fake persisted Project without hitting the API.
- .extract_user_id(user) ⇒ Integer
-
.stub_approvals(issue, approved: [], pending: []) ⇒ Array<PlanMyStuff::Approval>
Sets approvals on an in-memory
Issuewithout hitting the API.
Instance Method Summary collapse
- #expect_pms_comment_created(**filters) ⇒ Object
- #expect_pms_comment_updated(**filters) ⇒ Object
- #expect_pms_comments_listed(**filters) ⇒ Object
- #expect_pms_issue_created(**filters) ⇒ Object
- #expect_pms_issue_found(**filters) ⇒ Object
- #expect_pms_issue_updated(**filters) ⇒ Object
- #expect_pms_issues_listed(**filters) ⇒ Object
- #expect_pms_item_assigned(**filters) ⇒ Object
- #expect_pms_item_created(**filters) ⇒ Object
- #expect_pms_item_moved(**filters) ⇒ Object
- #expect_pms_pipeline_deployment_completed(**filters) ⇒ Object
- #expect_pms_pipeline_deployment_started(**filters) ⇒ Object
- #expect_pms_pipeline_in_review(**filters) ⇒ Object
- #expect_pms_pipeline_ready_for_release(**filters) ⇒ Object
- #expect_pms_pipeline_submitted(**filters) ⇒ Object
- #expect_pms_pipeline_taken(**filters) ⇒ Object
- #expect_pms_pipeline_testing(**filters) ⇒ Object
- #expect_pms_project_found(**filters) ⇒ Object
- #expect_pms_projects_listed(**filters) ⇒ Object
- #expect_pms_viewers_added(**filters) ⇒ Object
- #expect_pms_viewers_removed(**filters) ⇒ Object
Class Method Details
.build_comment(body: 'Test comment', visibility: :public, id: 1, issue: nil, metadata: {}) ⇒ PlanMyStuff::Comment
Builds a fake persisted Comment without hitting the API.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 84 def build_comment(body: 'Test comment', visibility: :public, id: 1, issue: nil, metadata: {}) issue ||= build_issue comment = PlanMyStuff::Comment.new( body: body, id: id, issue: issue, ) comment.visibility = visibility.to_sym = PlanMyStuff::CommentMetadata.from_hash({ schema_version: PlanMyStuff::BaseMetadata::SCHEMA_VERSION, gem_version: PlanMyStuff::VERSION::STRING, visibility: visibility.to_s, custom_fields: {}, }.merge()) comment. = comment.__send__(:persisted!) comment end |
.build_issue(title: 'Test Issue', body: 'Test body', state: :open, number: 1, repo: 'TestOrg/TestRepo', labels: [], metadata: {}) ⇒ PlanMyStuff::Issue
Builds a fake persisted Issue without hitting the API.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 36 def build_issue( title: 'Test Issue', body: 'Test body', state: :open, number: 1, repo: 'TestOrg/TestRepo', labels: [], metadata: {} ) issue = PlanMyStuff::Issue.new( title: title, body: body, state: state.to_s, number: number, repo: repo, labels: labels, ) = PlanMyStuff::IssueMetadata.from_hash({ schema_version: PlanMyStuff::BaseMetadata::SCHEMA_VERSION, gem_version: PlanMyStuff::VERSION::STRING, visibility: 'public', custom_fields: {}, }.merge()) issue. = issue.__send__(:persisted!) body_comment = build_comment( body: body, issue: issue, metadata: { issue_body: true }, ) issue.instance_variable_set(:@comments, [body_comment]) issue end |
.build_project(title: 'Test Project', number: 1, statuses: [], items: []) ⇒ PlanMyStuff::Project
Builds a fake persisted Project without hitting the API.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 115 def build_project(title: 'Test Project', number: 1, statuses: [], items: []) = statuses.each_with_index.map do |name, i| { id: "status_option_#{i}", name: name } end project = PlanMyStuff::Project.new( id: "PVT_fake_#{number}", number: number, title: title, statuses: , fields: [{ id: 'field_status', name: 'Status', options: }], ) project.__send__(:persisted!) project.items = items.map do |item_hash| PlanMyStuff::ProjectItem.build( { id: item_hash[:id] || "PVTI_fake_#{rand(10_000)}", title: item_hash[:title] || 'Untitled', number: item_hash[:number], url: item_hash[:url], state: item_hash[:state], status: item_hash[:status], field_values: item_hash[:field_values] || {}, }, project: project, ) end project end |
.extract_user_id(user) ⇒ Integer
167 168 169 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 167 def extract_user_id(user) user.is_a?(Integer) ? user : PlanMyStuff::UserResolver.user_id(user) end |
.stub_approvals(issue, approved: [], pending: []) ⇒ Array<PlanMyStuff::Approval>
Sets approvals on an in-memory Issue without hitting the API. Accepts user objects or integer user_ids.
156 157 158 159 160 161 162 163 164 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 156 def stub_approvals(issue, approved: [], pending: []) records = pending.map { |u| PlanMyStuff::Approval.new(user_id: extract_user_id(u), status: 'pending') } + approved.map do |u| PlanMyStuff::Approval.new(user_id: extract_user_id(u), status: 'approved', approved_at: Time.current) end issue..approvals = records records end |
Instance Method Details
#expect_pms_comment_created(**filters) ⇒ Object
230 231 232 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 230 def expect_pms_comment_created(**filters) expect_pms_action(:comment_created, 'comment to be created', **filters) end |
#expect_pms_comment_updated(**filters) ⇒ Object
240 241 242 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 240 def expect_pms_comment_updated(**filters) expect_pms_action(:comment_updated, 'comment to be updated', **filters) end |
#expect_pms_comments_listed(**filters) ⇒ Object
235 236 237 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 235 def expect_pms_comments_listed(**filters) expect_pms_action(:comments_listed, 'comments to be listed', **filters) end |
#expect_pms_issue_created(**filters) ⇒ Object
200 201 202 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 200 def expect_pms_issue_created(**filters) expect_pms_action(:issue_created, 'issue to be created', **filters) end |
#expect_pms_issue_found(**filters) ⇒ Object
205 206 207 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 205 def expect_pms_issue_found(**filters) expect_pms_action(:issue_found, 'issue to be found', **filters) end |
#expect_pms_issue_updated(**filters) ⇒ Object
215 216 217 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 215 def expect_pms_issue_updated(**filters) expect_pms_action(:issue_updated, 'issue to be updated', **filters) end |
#expect_pms_issues_listed(**filters) ⇒ Object
210 211 212 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 210 def expect_pms_issues_listed(**filters) expect_pms_action(:issues_listed, 'issues to be listed', **filters) end |
#expect_pms_item_assigned(**filters) ⇒ Object
265 266 267 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 265 def expect_pms_item_assigned(**filters) expect_pms_action(:item_assigned, 'item to be assigned', **filters) end |
#expect_pms_item_created(**filters) ⇒ Object
260 261 262 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 260 def expect_pms_item_created(**filters) expect_pms_action(:item_created, 'item to be created', **filters) end |
#expect_pms_item_moved(**filters) ⇒ Object
255 256 257 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 255 def expect_pms_item_moved(**filters) expect_pms_action(:item_moved, 'item to be moved', **filters) end |
#expect_pms_pipeline_deployment_completed(**filters) ⇒ Object
300 301 302 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 300 def expect_pms_pipeline_deployment_completed(**filters) expect_pms_action(:pipeline_deployment_completed, 'pipeline deployment completed', **filters) end |
#expect_pms_pipeline_deployment_started(**filters) ⇒ Object
295 296 297 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 295 def expect_pms_pipeline_deployment_started(**filters) expect_pms_action(:pipeline_deployment_started, 'pipeline deployment started', **filters) end |
#expect_pms_pipeline_in_review(**filters) ⇒ Object
280 281 282 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 280 def expect_pms_pipeline_in_review(**filters) expect_pms_action(:pipeline_in_review, 'pipeline item marked in review', **filters) end |
#expect_pms_pipeline_ready_for_release(**filters) ⇒ Object
290 291 292 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 290 def expect_pms_pipeline_ready_for_release(**filters) expect_pms_action(:pipeline_ready_for_release, 'pipeline item marked ready for release', **filters) end |
#expect_pms_pipeline_submitted(**filters) ⇒ Object
270 271 272 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 270 def expect_pms_pipeline_submitted(**filters) expect_pms_action(:pipeline_submitted, 'pipeline submission', **filters) end |
#expect_pms_pipeline_taken(**filters) ⇒ Object
275 276 277 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 275 def expect_pms_pipeline_taken(**filters) expect_pms_action(:pipeline_started, 'pipeline item to be taken', **filters) end |
#expect_pms_pipeline_testing(**filters) ⇒ Object
285 286 287 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 285 def expect_pms_pipeline_testing(**filters) expect_pms_action(:pipeline_testing, 'pipeline item moved to testing', **filters) end |
#expect_pms_project_found(**filters) ⇒ Object
250 251 252 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 250 def expect_pms_project_found(**filters) expect_pms_action(:project_found, 'project to be found', **filters) end |
#expect_pms_projects_listed(**filters) ⇒ Object
245 246 247 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 245 def expect_pms_projects_listed(**filters) expect_pms_action(:projects_listed, 'projects to be listed', **filters) end |
#expect_pms_viewers_added(**filters) ⇒ Object
220 221 222 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 220 def expect_pms_viewers_added(**filters) expect_pms_action(:viewers_added, 'viewers to be added', **filters) end |
#expect_pms_viewers_removed(**filters) ⇒ Object
225 226 227 |
# File 'lib/plan_my_stuff/test_helpers.rb', line 225 def expect_pms_viewers_removed(**filters) expect_pms_action(:viewers_removed, 'viewers to be removed', **filters) end |