|
24 | 24 | let(:resource_with_ids) do |
25 | 25 | resource.merge('@id' => full_id, 'ceterms:ctid' => ctid) |
26 | 26 | end |
| 27 | + let(:extract_resources) { false } |
| 28 | + let(:request_params) { {} } |
| 29 | + let(:request_path) do |
| 30 | + path = "/resources/#{CGI.escape(id).upcase}" |
| 31 | + return path if request_params.empty? |
| 32 | + |
| 33 | + "#{path}?#{Rack::Utils.build_query(request_params)}" |
| 34 | + end |
27 | 35 |
|
28 | 36 | before do |
29 | 37 | allow_any_instance_of(EnvelopeCommunity) # rubocop:todo RSpec/AnyInstance |
30 | 38 | .to receive(:id_field).and_return(id_field) |
31 | 39 |
|
32 | | - create( |
| 40 | + envelope = create( |
33 | 41 | :envelope, |
34 | 42 | :from_cer, |
35 | 43 | :with_cer_credential, |
36 | 44 | envelope_community: ec, |
37 | 45 | processed_resource: resource_with_ids |
38 | 46 | ) |
39 | 47 |
|
40 | | - get "/resources/#{CGI.escape(id).upcase}" |
| 48 | + ExtractEnvelopeResources.call(envelope:) if extract_resources |
| 49 | + |
| 50 | + get request_path |
41 | 51 | end |
42 | 52 |
|
43 | 53 | # rubocop:todo RSpec/MultipleMemoizedHelpers |
|
257 | 267 | end |
258 | 268 | # rubocop:enable RSpec/MultipleMemoizedHelpers |
259 | 269 | end |
| 270 | + |
| 271 | + # rubocop:todo RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |
| 272 | + context 'with `depth` query param' do # rubocop:todo RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups |
| 273 | + # rubocop:enable RSpec/NestedGroups, RSpec/MultipleMemoizedHelpers |
| 274 | + let(:id_field) { 'ceterms:ctid' } |
| 275 | + let(:id) { ctid } |
| 276 | + let(:extract_resources) { true } |
| 277 | + let(:parent_bnode_id) { "_:#{Envelope.generate_ctid}" } |
| 278 | + let(:child_bnode_id) { "_:#{Envelope.generate_ctid}" } |
| 279 | + let(:request_params) { { depth: depth } } |
| 280 | + let(:resource_with_ids) do |
| 281 | + { |
| 282 | + '@id' => "https://credentialengineregistry.org/graph/#{ctid}", |
| 283 | + '@type' => 'ceasn:CompetencyFramework', |
| 284 | + '@context' => 'http://credreg.net/ctdlasn/schema/context/json', |
| 285 | + '@graph' => [main_resource, parent_nested_resource, child_nested_resource] |
| 286 | + } |
| 287 | + end |
| 288 | + let(:main_resource) do |
| 289 | + { |
| 290 | + '@id' => full_id, |
| 291 | + '@type' => 'ceasn:CompetencyFramework', |
| 292 | + 'ceterms:ctid' => ctid, |
| 293 | + 'ceasn:hasTopChild' => [{ '@id' => parent_bnode_id }] |
| 294 | + } |
| 295 | + end |
| 296 | + let(:parent_nested_resource) do |
| 297 | + { |
| 298 | + '@id' => parent_bnode_id, |
| 299 | + '@type' => 'ceasn:Competency', |
| 300 | + 'ceasn:narrowAlignment' => [{ '@id' => child_bnode_id }] |
| 301 | + } |
| 302 | + end |
| 303 | + let(:child_nested_resource) do |
| 304 | + { |
| 305 | + '@id' => child_bnode_id, |
| 306 | + '@type' => 'ceasn:Competency' |
| 307 | + } |
| 308 | + end |
| 309 | + |
| 310 | + # rubocop:todo RSpec/NestedGroups |
| 311 | + # rubocop:todo RSpec/MultipleMemoizedHelpers |
| 312 | + context 'when depth is 0' do # rubocop:todo RSpec/NestedGroups |
| 313 | + # rubocop:enable RSpec/NestedGroups |
| 314 | + let(:depth) { 0 } |
| 315 | + |
| 316 | + it 'does not include nested blank nodes' do |
| 317 | + expect_status(:ok) |
| 318 | + expect(JSON(response.body).fetch('@included', [])).to be_empty |
| 319 | + end |
| 320 | + end |
| 321 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
| 322 | + |
| 323 | + # rubocop:todo RSpec/NestedGroups |
| 324 | + # rubocop:todo RSpec/MultipleMemoizedHelpers |
| 325 | + context 'when depth is omitted' do # rubocop:todo RSpec/NestedGroups |
| 326 | + # rubocop:enable RSpec/NestedGroups |
| 327 | + let(:request_params) { {} } |
| 328 | + |
| 329 | + it 'defaults to 0 depth' do |
| 330 | + expect_status(:ok) |
| 331 | + expect(JSON(response.body).fetch('@included', [])).to be_empty |
| 332 | + end |
| 333 | + end |
| 334 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
| 335 | + |
| 336 | + # rubocop:todo RSpec/NestedGroups |
| 337 | + # rubocop:todo RSpec/MultipleMemoizedHelpers |
| 338 | + context 'when depth is 1' do # rubocop:todo RSpec/NestedGroups |
| 339 | + # rubocop:enable RSpec/NestedGroups |
| 340 | + let(:depth) { 1 } |
| 341 | + |
| 342 | + it 'includes first-level blank nodes only' do |
| 343 | + expect_status(:ok) |
| 344 | + included_ids = JSON(response.body) |
| 345 | + .fetch('@included', []) |
| 346 | + .map { |item| item.fetch('@id') } |
| 347 | + expect( |
| 348 | + included_ids |
| 349 | + ).to contain_exactly(parent_bnode_id) |
| 350 | + end |
| 351 | + end |
| 352 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
| 353 | + |
| 354 | + # rubocop:todo RSpec/NestedGroups |
| 355 | + # rubocop:todo RSpec/MultipleMemoizedHelpers |
| 356 | + context 'when depth is 2' do # rubocop:todo RSpec/NestedGroups |
| 357 | + # rubocop:enable RSpec/NestedGroups |
| 358 | + let(:depth) { 2 } |
| 359 | + |
| 360 | + it 'includes nested blank nodes up to the requested depth' do |
| 361 | + expect_status(:ok) |
| 362 | + included_ids = JSON(response.body) |
| 363 | + .fetch('@included', []) |
| 364 | + .map { |item| item.fetch('@id') } |
| 365 | + expect( |
| 366 | + included_ids |
| 367 | + ).to contain_exactly(parent_bnode_id, child_bnode_id) |
| 368 | + end |
| 369 | + end |
| 370 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
| 371 | + |
| 372 | + # rubocop:todo RSpec/NestedGroups |
| 373 | + # rubocop:todo RSpec/MultipleMemoizedHelpers |
| 374 | + context 'when depth is negative' do # rubocop:todo RSpec/NestedGroups |
| 375 | + # rubocop:enable RSpec/NestedGroups |
| 376 | + let(:depth) { -1 } |
| 377 | + |
| 378 | + it 'returns bad_request' do |
| 379 | + expect_status(:bad_request) |
| 380 | + end |
| 381 | + end |
| 382 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
| 383 | + end |
260 | 384 | end |
261 | 385 | # rubocop:enable RSpec/MultipleMemoizedHelpers |
262 | 386 |
|
|
0 commit comments