class Auchandirect::ScrAPI::DummyCart

A mock for Auchandirect::ScrAPI::Cart It provides a call log as a way of testing

Attributes

log[R]

Accessors to the login and passwords used to login And to the received messages log

login[R]

Accessors to the login and passwords used to login And to the received messages log

password[R]

Accessors to the login and passwords used to login And to the received messages log

Public Class Methods

login_parameter() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 51
def self.login_parameter
  'login'
end
login_parameters(login,password) click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 46
def self.login_parameters(login,password)
  [{'name' => 'session_data', 'value' => 'crypted_data', 'type' => 'hidden'},
   {'name' => login_parameter, 'value' => login, 'type' => 'text'},
   {'name' => password_parameter, 'value' => password, 'type' => 'password'}]
end
login_url() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 43
def self.login_url
  url+"/login"
end
logout_url() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 40
def self.logout_url
  url+"/logout"
end
new(login = nil, password = nil) click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 65
def initialize(login = nil, password = nil)
  @log = []
  @login = ""
  @password = ""
  @unavailable_items = {}

  if !login.nil? || !password.nil?
    relog(login, password)
  end
end
password_parameter() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 54
def self.password_parameter
  'password'
end
url() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 28
def self.url
  "http://www.#{Storexplore::Testing::DummyStoreConstants::NAME}.com"
end
valid_email() click to toggle source

The valid login to log into this dummy store

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 32
def self.valid_email
  "valid@mail.com"
end
valid_password() click to toggle source

The valid password to log into this dummy store

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 36
def self.valid_password
  "valid-password"
end

Public Instance Methods

add_to_cart(quantity, item) click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 96
def add_to_cart(quantity, item)
  if available?(item)
    @log.push(:add_to_cart)
    @@content[item] += quantity
  end
end
add_unavailable_item(item) click to toggle source

Makes an item temporarily unavailable

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 130
def add_unavailable_item(item)
  @unavailable_items[item] = true
end
available?(item) click to toggle source

Is the given item available at this moment ?

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 135
def available?(item)
  !@unavailable_items[item]
end
cart_value() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 103
def cart_value
  @@content.to_a.inject(0.0) do |amount,id_and_quantity|
    item = id_and_quantity.first
    quantity = id_and_quantity.last

    unit_price = item.hash.abs.to_f/1e7

    amount + quantity * unit_price
  end
end
containing?(item, quantity) click to toggle source

Does the cart contain the specified quantity of this item ?

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 125
def containing?(item, quantity)
  @@content[item] == quantity
end
content() click to toggle source

Collection of all the different items in the cart

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 115
def content
  @@content.keys
end
empty?() click to toggle source

Is the cart empty ?

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 120
def empty?
  @@content.empty?
end
empty_the_cart() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 91
def empty_the_cart
  @log.push(:empty_the_cart)
  @@content.clear
end
logout() click to toggle source
# File lib/auchandirect/scrAPI/dummy_cart.rb, line 87
def logout
  @log.push(:logout)
end
relog(login, password) click to toggle source

Resets the session as if a new one was started

# File lib/auchandirect/scrAPI/dummy_cart.rb, line 77
def relog(login, password)
  if login != DummyCart.valid_email
    raise InvalidAccountError.new
  end

  @log.push(:login)
  @login = login
  @password = password
end