File: test_case_entity.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (30 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class TestCaseEntity < Grape::Entity
  include API::Helpers::RelatedResourcesHelpers

  expose :status, documentation: { type: 'string', example: 'success' }
  expose :name, default: "(No name)",
    documentation: { type: 'string', example: 'Security Reports can create an auto-remediation MR' }
  expose :classname, documentation: { type: 'string', example: 'vulnerability_management_spec' }
  expose :file, documentation: { type: 'string', example: './spec/test_spec.rb' }
  expose :execution_time, documentation: { type: 'integer', example: 180 }
  expose :system_output, documentation: { type: 'string', example: 'Failure/Error: is_expected.to eq(3)' }
  expose :stack_trace, documentation: { type: 'string', example: 'Failure/Error: is_expected.to eq(3)' }
  expose :recent_failures, documentation: { example: { count: 3, base_branch: 'develop' } }
  expose(
    :attachment_url,
    if: ->(*) { can_read_screenshots? },
    documentation: { type: 'string', example: 'http://localhost/namespace1/project1/-/jobs/1/artifacts/file/some/path.png' }
  ) do |test_case|
    expose_url(test_case.attachment_url)
  end

  private

  alias_method :test_case, :object

  def can_read_screenshots?
    test_case.has_attachment?
  end
end