-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount_test.rb
79 lines (68 loc) · 2.84 KB
/
account_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#--------------------------------------------------------------#
# Sample test for the Recurly API
#
# Purpose: to verify that a Recurly API user can:
# * create a new account,
# * view the new account,
# * receive expected errors when submitting invalid requests.
#--------------------------------------------------------------#
require "minitest/autorun"
require 'rubygems'
require 'recurly'
require 'factory_girl'
require_relative 'subscriber_factory'
require_relative 'subscriber'
class AccountTest < MiniTest::Test
Recurly.subdomain = 'karentobo'
Recurly.api_key = '8fdab4fe0b2b42b6bfad6deca636aa1a'
=begin
def setup
@subscriber = FactoryGirl.build(:subscriber)
end
=end
def test_create_account
subscriber = FactoryGirl.build(:subscriber)
account = Recurly::Account.create(
:account_code => subscriber.account_code,
:email => subscriber.email,
:first_name => subscriber.first_name,
:last_name => subscriber.last_name
)
assert_equal subscriber.account_code, account.account_code, "account code was not as expected"
assert_equal subscriber.email, account.email, "email was not as expected"
assert_equal subscriber.first_name, account.first_name, "first_name was not as expected"
assert_equal subscriber.last_name, account.last_name, "last_name was not as expected"
assert_empty account.errors, "create account returned errors: #{account.errors}"
account = Recurly::Account.find subscriber.account_code
assert_equal subscriber.account_code, account.account_code, "account code was not as expected"
assert_equal subscriber.email, account.email, "email was not as expected"
assert_equal subscriber.first_name, account.first_name, "first_name was not as expected"
assert_equal subscriber.last_name, account.last_name, "last_name was not as expected"
assert_empty account.errors, "view account returned errors: #{account.errors}"
account.destroy
end
def test_create_without_account_code
subscriber = FactoryGirl.build(:subscriber)
account = Recurly::Account.create(
:email => subscriber.email,
:first_name => subscriber.first_name,
:last_name => subscriber.last_name
)
assert_includes account.errors["account_code"], "can't be blank", "no error message about blank account code"
end
def test_account_code_unique
subscriber = FactoryGirl.build(:subscriber)
account = Recurly::Account.create(
:account_code => subscriber.account_code,
)
#attempt to create another account with the same account code
account = Recurly::Account.create(
:account_code => subscriber.account_code,
)
assert_includes account.errors["account_code"], "has already been taken", "no error message about non-unique account code"
account.destroy
end
def test_account_not_found
assert_raises(Recurly::Resource::NotFound) {Recurly::Account.find 'NonexistentAccountCode123' }
end
end