Module: OnlyofficeTestrailWrapper::TestrailProjectPlanHelper

Extended by:
Gem::Deprecate
Included in:
TestrailProject
Defined in:
lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb

Overview

Mehtods to help working with Plan in Project

Instance Method Summary collapse

Instance Method Details

#create_new_plan(name, entries = [], description = '', milestone_id = nil) ⇒ Object

Parameters:

  • name (String)

    of test plan

  • description (String) (defaults to: '')
  • milestone_id (Integer) (defaults to: nil)


77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 77

def create_new_plan(name, entries = [], description = '', milestone_id = nil)
  new_plan = TestrailPlan.new.init_from_hash(Testrail2.http_post("index.php?/api/v2/add_plan/#{@id}",
                                                                 name: StringHelper.warnstrip!(name),
                                                                 description: description,
                                                                 milestone_id: milestone_id,
                                                                 entries: entries))
  OnlyofficeLoggerHelper.log "Created new plan: #{new_plan.name}"
  new_plan.entries.each_with_index do |entry, i|
    new_plan.entries[i] = TestrailPlanEntry.new.init_from_hash(entry)
    new_plan.entries[i].runs.each_with_index { |run, j| new_plan.entries[i].runs[j] = TestrailRun.new.init_from_hash(run) }
  end
  @plans_names[new_plan.name] = new_plan.id
  new_plan
end

#get_plan_by_id(id) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 22

def get_plan_by_id(id)
  plan = TestrailPlan.new.init_from_hash(Testrail2.http_get("index.php?/api/v2/get_plan/#{id}"))
  OnlyofficeLoggerHelper.log("Initialized plan: #{plan.name}")
  raise("`get_plan_by_id(#{id})` return an error: `#{plan.error}`") if plan.error

  plan.entries.each_with_index do |test_entry, index|
    entry = TestrailPlanEntry.new.init_from_hash(test_entry)
    entry.runs.each_with_index { |run, i| entry.runs[i] = TestrailRun.new.init_from_hash(run) }
    plan.entries[index] = entry
  end
  plan.instance_variable_set :@project, self
  plan
end

#get_plan_by_name(name) ⇒ Object



36
37
38
39
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 36

def get_plan_by_name(name)
  get_plans if @plans_names.empty?
  @plans_names[StringHelper.warnstrip!(name.to_s)].nil? ? nil : get_plan_by_id(@plans_names[name])
end

#get_plans(filters = {}) ⇒ Array<Hash>

Get list of all TestPlans

Parameters:

  • filters (Hash) (defaults to: {})

    filter conditions

Returns:

  • (Array<Hash>)

    test plans



53
54
55
56
57
58
59
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 53

def get_plans(filters = {})
  get_url = "index.php?/api/v2/get_plans/#{@id}"
  filters.each { |key, value| get_url += "&#{key}=#{value}" }
  plans = Testrail2.http_get(get_url)
  @plans_names = name_id_pairs(plans) if @plans_names.empty?
  plans
end

#init_plan_by_name(name) ⇒ Object



17
18
19
20
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 17

def init_plan_by_name(name)
  found_plan = get_plan_by_name name
  found_plan.nil? ? create_new_plan(name) : found_plan
end

#plan(name_or_id) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 6

def plan(name_or_id)
  case name_or_id.class.to_s
  when 'Fixnum', 'Integer'
    get_plan_by_id name_or_id
  when 'String'
    init_plan_by_name name_or_id
  else
    raise 'Wrong argument. Must be name [String] or id [Integer]'
  end
end

#plan_by_name(name) ⇒ TestrailPlan?

Returns result of plan search.

Parameters:

  • name (String)

    of plan

Returns:



46
47
48
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 46

def plan_by_name(name)
  plans.find { |plan| plan.name == name }
end

#plans(filters = {}) ⇒ Array<TestrailPlan>

Get list of all TestPlans

Parameters:

  • filters (Hash) (defaults to: {})

    filter conditions

Returns:



67
68
69
70
71
72
# File 'lib/onlyoffice_testrail_wrapper/testrail_project/testrail_project_plan_helper.rb', line 67

def plans(filters = {})
  get_url = "index.php?/api/v2/get_plans/#{@id}"
  filters.each { |key, value| get_url += "&#{key}=#{value}" }
  plans = Testrail2.http_get(get_url)
  plans.map { |suite| TestrailPlan.new.init_from_hash(suite) }
end