Skip to content

Commit

Permalink
Merge pull request #4 from automation-wizards/develop
Browse files Browse the repository at this point in the history
Update documentation
  • Loading branch information
frbk authored May 25, 2017
2 parents 8aa5ba8 + e96e0b5 commit f1e6a1c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 28 deletions.
121 changes: 94 additions & 27 deletions lib/tmj_ruby/services/test_run.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,113 @@
module TMJ
module Services
# TNJ::Services::TestRun
# TMJ::Services::TestRun provides methods for working with test runs
#
# @see https://www.kanoah.com/docs/public-api/1.0/ more info regarding test cases can be found here
#
class TestRun < TMJ::Services::Base
attr_reader :test_run_id

def initialize(options = {})
@test_run_id = options[:test_run_id]
super(options)
end


# Creates new test run
#
# @param [Hash] test_run_data
#
# @example Create new test case
# TMJ::Client.new.TestRun.create({"name": "Full regression","projectKey": "JQA"})
#
def create(test_run_data)
self.class.post("/rest/kanoahtests/1.0/testrun", body: body.to_json, headers: @header)
#raise TMJ::TestRunError, response unless response.code == 201
self.class.post("/rest/kanoahtests/1.0/testrun", body: body.to_json, headers: @header).tap do |response|
raise TMJ::TestRunError, response unless response.code == 201
end
end


# Retrive specific test run
#
# @param [String] test_run_id
#
# @example Create new test case
# TMJ::Client.new.TestRun.find('DD-R123')
#
def find(test_run_id)
self.class.get("/rest/kanoahtests/1.0/testrun/#{test_run_id}", headers: @header)
#raise TMJ::TestRunError, response unless response.code == 200
self.class.get("/rest/kanoahtests/1.0/testrun/#{test_run_id}", headers: @header).tap do |response|
raise TMJ::TestRunError, response unless response.code == 200
end
end


# Delete specific test run
#
# @param [String] test_run_id
#
# @example Create new test case
# TMJ::Client.new.TestRun.delete('DD-R123')
#
def delete(test_run_id)
self.class.get("/rest/kanoahtests/1.0/testrun/#{test_run_id}", headers: @header)
#raise TMJ::TestRunError, response unless response.code == 204
self.class.get("/rest/kanoahtests/1.0/testrun/#{test_run_id}", headers: @header).tap do |response|
raise TMJ::TestRunError, response unless response.code == 204
end
end

def search(project_id)
self.class.get("/rest/kanoahtests/1.0/testrun/search?query=projectKey = '#{project_id}'", headers: @header)
#raise TMJ::TestRunError, response unless response.code == 200

# Searches for a testrun based on the provided quiry
#
# @param [String] test_run_id
#
# @example Create new test case
# TMJ::Client.new.TestRun.search('projectKey = "JQA"')
#
def search(query_string)
self.class.get("/rest/kanoahtests/1.0/testrun/search?query=#{query_string}", headers: @header).tap do |response|
raise TMJ::TestRunError, response unless response.code == 200
end
end


# Create new result for a test run
#
# @param [String] test_run_key
# @param [String] test_case_id
# @param [Hash] test_data
#
# @example
# test_data = {
# "status": "Fail",
# "scriptResults": [
# {
# "index": 0,
# "status": "Fail",
# "comment": "This steps has failed."
# }
# ]
# }
# TMJ::Client.new.TestRun.create_new_test_run_result('DD-R123','DD-T123', test_data)
#
def create_new_test_run_result(test_run_key = @test_run_id, test_case_id, test_data)
body = process_result(test_data)
self.class.post("/rest/kanoahtests/1.0/testrun/#{test_run_key}/testcase/#{test_case_id}/testresult", body: body.to_json, headers: @header)
#raise TMJ::TestRunError, response unless response.code == 201
end


# Update latest result for a test run
#
# @param [String] test_run_key
# @param [String] test_case_id
# @param [Hash] test_data
#
# @example
# test_data = {
# "status": "Fail",
# "scriptResults": [
# {
# "index": 0,
# "status": "Fail",
# "comment": "This steps has failed."
# }
# ]
# }
# TMJ::Client.new.TestRun.update_last_test_run_result('DD-R123','DD-T123', test_data)
#
def update_last_test_run_result(test_run_key = @test_run_id, test_case_id, test_data)
body = process_result(test_data)
self.class.post("/rest/kanoahtests/1.0/testrun/#{test_run_key}/testcase/#{test_case_id}/testresult", body: body.to_json, headers: @header)
Expand All @@ -45,20 +118,14 @@ def update_last_test_run_result(test_run_key = @test_run_id, test_case_id, test_
def process_result(test_data)
{
'status' => test_data[:status],
'environment' => configure_env(test_data),
'comment' => test_data[:comment],
'executionTime' => test_data[:execution_time],
'environment' => test_data.fetch(:environment, @environment),
'comment' => test_data.fetch(:comment, nil),
'userKey' => test_data.fetch(:username, nil),
'executionTime' => test_data.fetch(:execution_time, nil),
'executionDate' => test_data.fetch(:execution_date, nil),
'scriptResults' => test_data[:script_results]
}.delete_if { |k, v| v.nil? }
end

def configure_env(test_data)
if test_data[:environment].nil?
@environment
else
test_data[:environment]
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/tmj_ruby/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TMJ
VERSION = '0.1.7'.freeze
VERSION = '0.1.8'.freeze
end

0 comments on commit f1e6a1c

Please sign in to comment.