Sha256: fbfa3315112d5eff25cd7099e0aedff03afda234fbe422157abec89c33578665

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module TwilioBase
  module Fake
    module TaskRouter
      class Workflow
        Workflow = Struct.new(:attributes) do
          def sid
            @sid ||= GlobalConfig.first&.workflow_sid ||
                     FactoryBot.generate(:workflow_sid)
          end

          def assignment_callback_url
            attributes[:assignment_callback_url]
          end

          def configuration
            attributes[:configuration]
          end

          def friendly_name
            attributes[:friendly_name]
          end

          def update(attributes)
            self.attributes = attributes
          end
        end

        cattr_accessor :sid, :workflows
        self.workflows = []

        def initialize(sid = nil)
          self.sid = sid
        end

        def create(attributes)
          workflow = Workflow.new(attributes)
          self.class.workflows << workflow
          workflow
        end

        def update(attributes)
          found_workflow = workflows.detect { |workflow| workflow.sid == sid }
          found_workflow&.update(attributes)
        end

        def list
          workflows
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
twilio_base-1.11.1101 spec/support/twilio_base/fake/task_router/workflow.rb
twilio_base-1.11.11 spec/support/twilio_base/fake/task_router/workflow.rb
twilio_base-1.9.0 spec/support/twilio_base/fake/task_router/workflow.rb
twilio_base-1.8.0 spec/support/twilio_base/fake/task_router/workflow.rb