Module: Webhookdb::IntegrationSpecHelpers

Includes:
Appydays::Configurable, Appydays::Loggable
Defined in:
lib/webhookdb/spec_helpers/integration.rb

Class Method Summary collapse

Class Method Details

.auth_customer(customer = nil) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/webhookdb/spec_helpers/integration.rb', line 67

module_function def auth_customer(customer=nil)
  if customer.nil?
    customer = Webhookdb::Fixtures.customer.instance
    resp = post("/v1/auth", body: {email: customer.email})
    expect(resp).to party_status(202)
    customer = Webhookdb::Customer[email: customer.email]
  end

  code = Webhookdb::Fixtures.reset_code(customer:).create
  resp = post("/v1/auth", body: {email: customer.email, token: code.token})
  expect(resp).to party_status(200)

  return customer.refresh
end

.included(context) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/webhookdb/spec_helpers/integration.rb', line 18

def self.included(context)
  # We run few workers on staging so need time to process things.
  Rspec::Eventually.timeout = 60
  # We're in no rush for integration tests.
  Rspec::Eventually.pause = 1

  context.before(:each) do |example|
    raise "Unit tests should not be run during integration tests (or this test needs an :integration flag" unless
      example.[:integration]

    @to_destroy = []
    WebMock.allow_net_connect! if defined?(WebMock)
  end

  context.after(:each) do
    @to_destroy.each(&:destroy)
    WebMock.disable_net_connect! if defined?(WebMock)
  end
  super
end


50
51
52
53
54
# File 'lib/webhookdb/spec_helpers/integration.rb', line 50

module_function def parse_cookie(resp)
  cookie_hash = HTTParty::CookieHash.new
  resp.get_fields("Set-Cookie")&.each { |c| cookie_hash.add_cookies(c) }
  return cookie_hash
end

.store_cookiesObject



56
57
58
59
60
61
# File 'lib/webhookdb/spec_helpers/integration.rb', line 56

module_function def store_cookies
  response = yield()
  @stored_cookies = parse_cookie(response)
  Webhookdb::IntegrationSpecHelpers.logger.debug "Got cookies: %p" % [stored_cookies]
  return response
end

.stored_cookiesObject



63
64
65
# File 'lib/webhookdb/spec_helpers/integration.rb', line 63

module_function def stored_cookies
  return @stored_cookies
end

.url(more) ⇒ Object



46
47
48
# File 'lib/webhookdb/spec_helpers/integration.rb', line 46

module_function def url(more)
  return "#{Webhookdb.api_url}#{more}"
end

.with_async_publisherObject



39
40
41
42
43
44
# File 'lib/webhookdb/spec_helpers/integration.rb', line 39

module_function def with_async_publisher
  Amigo.install_amigo_jobs
  yield
ensure
  Amigo.subscribers.clear
end