Class: JayAPI::IDBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/jay_api/id_builder.rb

Overview

Provides methods to calculate special identifiers for Test Case for Jay.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_case_id: nil, project: nil, software_version: nil, result: nil) ⇒ IDBuilder

Returns a new instance of IDBuilder.



13
14
15
16
17
18
# File 'lib/jay_api/id_builder.rb', line 13

def initialize(test_case_id: nil, project: nil, software_version: nil, result: nil)
  @test_case_id = test_case_id
  @project = project
  @software_version = software_version
  @result = result
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



11
12
13
# File 'lib/jay_api/id_builder.rb', line 11

def project
  @project
end

#resultObject (readonly)

Returns the value of attribute result.



11
12
13
# File 'lib/jay_api/id_builder.rb', line 11

def result
  @result
end

#software_versionObject (readonly)

Returns the value of attribute software_version.



11
12
13
# File 'lib/jay_api/id_builder.rb', line 11

def software_version
  @software_version
end

#test_case_idObject (readonly)

Returns the value of attribute test_case_id.



11
12
13
# File 'lib/jay_api/id_builder.rb', line 11

def test_case_id
  @test_case_id
end

Instance Method Details

#secure_idArray

Returns An array with two elements:

  • The secure Seed (A Version 4 UUID)

  • The secure Hash composed by concatenating the Software Version, the secure Seed and the result of the Test Case.

This Secure ID is meant for end-to-end verification of the test results.

Returns:

  • (Array)

    An array with two elements:

    • The secure Seed (A Version 4 UUID)

    • The secure Hash composed by concatenating the Software Version, the secure Seed and the result of the Test Case.

    This Secure ID is meant for end-to-end verification of the test results.



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jay_api/id_builder.rb', line 39

def secure_id
  unless software_version && result
    raise ArgumentError,
          'The Software Version (software_version) and the Result ' \
          '(result) are required to calculate the Secure ID'
  end

  [
    uuid = SecureRandom.uuid,
    Digest::MD5.hexdigest("#{software_version}:#{uuid}:#{result}")
  ]
end

#short_idString

noinspection RubyNilAnalysis

Returns:

  • (String)

    The Sort ID for the Test Case (composed from the Project’s name and a clean version of the full Test Case Identifier)



23
24
25
26
27
28
29
30
31
32
# File 'lib/jay_api/id_builder.rb', line 23

def short_id
  unless test_case_id && project
    raise ArgumentError,
          "The Test Case ID (test_case_id) and the Project's name " \
          '(project) are required to calculate the Short ID'
  end

  clean_id = test_case_id.downcase.gsub(/[^a-z0-9-]/, '')
  "#{project.underscore}_#{Digest::SHA1.new.update(clean_id).hexdigest[0...12]}"
end