Class: ZeebeBpmnRspec::ActivatedJob

Inherits:
Object
  • Object
show all
Includes:
Zeebe::Client::GatewayProtocol
Defined in:
lib/zeebe_bpmn_rspec/activated_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, type:, workflow_instance_key:, client:, context:, validate:) ⇒ ActivatedJob

rubocop:disable Metrics/ParameterLists



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 13

def initialize(job, type:, workflow_instance_key:, client:, context:, validate:) # rubocop:disable Metrics/ParameterLists
  @job = job
  @type = type
  @workflow_instance_key = workflow_instance_key
  @client = client
  @context = context

  if validate
    context.instance_eval do
      expect(job).not_to be_nil, "expected to receive job of type '#{type}' but received none"
      aggregate_failures do
        expect(job.workflowInstanceKey).to eq(workflow_instance_key)
        expect(job.type).to eq(type)
      end
    end
  end
end

Instance Attribute Details

#jobObject (readonly)

Returns the value of attribute job.



11
12
13
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 11

def job
  @job
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 11

def type
  @type
end

#workflow_instance_keyObject (readonly)

Returns the value of attribute workflow_instance_key.



11
12
13
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 11

def workflow_instance_key
  @workflow_instance_key
end

Instance Method Details

#and_complete(variables = {}) ⇒ Object Also known as: complete



93
94
95
96
97
98
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 93

def and_complete(variables = {})
  client.complete_job(CompleteJobRequest.new(
                        jobKey: job.key,
                        variables: variables.to_json
                      ))
end

#and_fail(message = nil, retries: nil) ⇒ Object Also known as: fail



82
83
84
85
86
87
88
89
90
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 82

def and_fail(message = nil, retries: nil)
  client.fail_job(FailJobRequest.new(
                    {
                      jobKey: job.key,
                      retries: retries || 0,
                      errorMessage: message,
                    }.compact
                  ))
end

#and_throw_error(error_code, message = nil) ⇒ Object Also known as: throw_error



71
72
73
74
75
76
77
78
79
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 71

def and_throw_error(error_code, message = nil)
  client.throw_error(ThrowErrorRequest.new(
                       {
                         jobKey: job.key,
                         errorCode: error_code,
                         errorMessage: message,
                       }.compact
                     ))
end

#expect_headers(headers) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 61

def expect_headers(headers)
  job_headers = self.headers
  headers = headers.stringify_keys if headers.is_a?(Hash)
  context.instance_eval do
    expect(job_headers).to match(headers)
  end

  self
end

#expect_input(data) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 51

def expect_input(data)
  job_variables = variables
  data = data.stringify_keys if data.is_a?(Hash)
  context.instance_eval do
    expect(job_variables).to match(data)
  end

  self
end

#headersObject



47
48
49
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 47

def headers
  @_headers ||= JSON.parse(job.customHeaders)
end

#keyObject



35
36
37
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 35

def key
  job.key
end

#rawObject



31
32
33
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 31

def raw
  job
end

#to_sObject



39
40
41
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 39

def to_s
  raw.to_s
end

#variablesObject



43
44
45
# File 'lib/zeebe_bpmn_rspec/activated_job.rb', line 43

def variables
  @_variables ||= JSON.parse(job.variables)
end