amiando 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +17 -0
  3. data/Guardfile +11 -0
  4. data/README.md +26 -0
  5. data/Rakefile +12 -0
  6. data/amiando.gemspec +27 -0
  7. data/lib/amiando.rb +59 -0
  8. data/lib/amiando/api_key.rb +35 -0
  9. data/lib/amiando/boolean.rb +33 -0
  10. data/lib/amiando/event.rb +131 -0
  11. data/lib/amiando/request.rb +38 -0
  12. data/lib/amiando/resource.rb +152 -0
  13. data/lib/amiando/result.rb +33 -0
  14. data/lib/amiando/ticket_category.rb +99 -0
  15. data/lib/amiando/ticket_shop.rb +63 -0
  16. data/lib/amiando/user.rb +148 -0
  17. data/lib/amiando/version.rb +3 -0
  18. data/test/amiando/amiando_test.rb +13 -0
  19. data/test/amiando/api_key_test.rb +58 -0
  20. data/test/amiando/boolean_test.rb +21 -0
  21. data/test/amiando/event_test.rb +141 -0
  22. data/test/amiando/resource_test.rb +68 -0
  23. data/test/amiando/result_test.rb +25 -0
  24. data/test/amiando/ticket_category_test.rb +89 -0
  25. data/test/amiando/ticket_shop_test.rb +42 -0
  26. data/test/amiando/user_test.rb +130 -0
  27. data/test/fixtures/ApiKey/018fa0a2281ec9026bc122bc346366f6.yml +60 -0
  28. data/test/fixtures/ApiKey/1f62195e173114773b3ec2613582ece9.yml +60 -0
  29. data/test/fixtures/ApiKey/76860dbafe66279f25f56cd66b3f6ba1.yml +62 -0
  30. data/test/fixtures/ApiKey/97d82801a10696aaf385bf5873034b60.yml +60 -0
  31. data/test/fixtures/ApiKey/a703d1fcec1576fa8cb4ca1c5f53f545.yml +62 -0
  32. data/test/fixtures/ApiKey/a948a98b153ab66978e37160f352bfbc.yml +60 -0
  33. data/test/fixtures/ApiKey/b7ecc9e79dd856dec661554cd00490ed.yml +62 -0
  34. data/test/fixtures/ApiKey/ded8694c21d2e1c0cec845f72ba452b5.yml +60 -0
  35. data/test/fixtures/ApiKey/fa883db60c0390aa8948098d32497015.yml +60 -0
  36. data/test/fixtures/Event/29a95cd545b2fba8121dce97a3c859e3.yml +60 -0
  37. data/test/fixtures/Event/361940ebc5f074b1d6d96c2dbeb573ab.yml +60 -0
  38. data/test/fixtures/Event/3a90bf0a17eb1d647f1496d04640797a.yml +60 -0
  39. data/test/fixtures/Event/3b8ae154ad13c7152366b79c0d34b053.yml +60 -0
  40. data/test/fixtures/Event/49877df5f8c251e3364a3560ab1ab46c.yml +60 -0
  41. data/test/fixtures/Event/50cb3d76b40032b0fa5731ce7d2ae2f6.yml +62 -0
  42. data/test/fixtures/Event/5d6016557d86e7b7ff83d07d1ef4bf44.yml +60 -0
  43. data/test/fixtures/Event/67e55d2f91fa702eb8dc612cbfa661f9.yml +60 -0
  44. data/test/fixtures/Event/813535fc6ee153c1a6d8e826f1fe04dc.yml +60 -0
  45. data/test/fixtures/Event/8eabb0f839e03cde5818397c7121e6b4.yml +61 -0
  46. data/test/fixtures/Event/96a5ccd0281a67a4bdb276516b77e756.yml +62 -0
  47. data/test/fixtures/Event/9e689bd5495dc898a710cba8e6d1d779.yml +62 -0
  48. data/test/fixtures/Event/a816e5664ff66b8e3d27b74435a0c123.yml +60 -0
  49. data/test/fixtures/Event/c5ad7e1d1c160d7d1132297892a9ec94.yml +60 -0
  50. data/test/fixtures/Event/c88c85889575508f75deee325e16e49d.yml +60 -0
  51. data/test/fixtures/Event/d6a585196f1a2a94d22f22a2140d4c07.yml +60 -0
  52. data/test/fixtures/Event/e00eebd4faf194fe592fa6e7615909b8.yml +60 -0
  53. data/test/fixtures/Event/e753b6f404795c6635856ea43b0c7d35.yml +60 -0
  54. data/test/fixtures/Event/eb341dbccefaad75aad439f10cc7d82d.yml +60 -0
  55. data/test/fixtures/Event/ebab641e40ca57f8e0883d8ea003bd78.yml +60 -0
  56. data/test/fixtures/Event/ef17351e4bbc84eb776fe16dda31e1e4.yml +62 -0
  57. data/test/fixtures/Global/505952258352958b3b59a3812372ed02.yml +60 -0
  58. data/test/fixtures/Global/d41a6ca323b5db99b4e3c06e108c52cc.yml +60 -0
  59. data/test/fixtures/TicketCategory/0412c9d453efd804e171c6ba57fd980a.yml +66 -0
  60. data/test/fixtures/TicketCategory/49877df5f8c251e3364a3560ab1ab46c.yml +60 -0
  61. data/test/fixtures/TicketCategory/4d3f8d9ff3fb728fc37aaa6e40355a00.yml +62 -0
  62. data/test/fixtures/TicketCategory/5d4fdfda01ed8193c6bbc5e089db5a4b.yml +60 -0
  63. data/test/fixtures/TicketCategory/655e7a8089d67b8eeea1176398e4b289.yml +60 -0
  64. data/test/fixtures/TicketCategory/a9b19dc83437d00ffc4603c04f78159f.yml +62 -0
  65. data/test/fixtures/TicketCategory/bee3d6eb4247fec0849d91fb2f768524.yml +60 -0
  66. data/test/fixtures/TicketCategory/c6f8563714904f006b28ac06312b107d.yml +60 -0
  67. data/test/fixtures/TicketCategory/e6076c26b1b75eec091c5b91c9f75ad9.yml +62 -0
  68. data/test/fixtures/TicketCategory/ebfcf07be91b8cb6d05156713592abc9.yml +60 -0
  69. data/test/fixtures/TicketCategory/fe63648cf867613ec93b380e06257349.yml +60 -0
  70. data/test/fixtures/TicketShop/03d35073550910e61201cf425b4ff73e.yml +60 -0
  71. data/test/fixtures/TicketShop/0524d80dc6e3fad88d49adf71ffa2ab9.yml +60 -0
  72. data/test/fixtures/TicketShop/09729fb0d9f1490bec3acfa0e6742190.yml +60 -0
  73. data/test/fixtures/TicketShop/15c36c73e9f1d3255a61a559e3b98562.yml +60 -0
  74. data/test/fixtures/TicketShop/4605dd240202cd7510bfecaf474ac615.yml +62 -0
  75. data/test/fixtures/TicketShop/5c1f5488a196f44f2c18cc186816fd42.yml +60 -0
  76. data/test/fixtures/TicketShop/71f80402a72be32fdd34074d4426b765.yml +62 -0
  77. data/test/fixtures/TicketShop/bc24338e918c6edb07a55f4d580c5af3.yml +60 -0
  78. data/test/fixtures/TicketShop/d095062bf22d235f277c979b025e5cac.yml +60 -0
  79. data/test/fixtures/TicketShop/ece5150c24e5000bf4eff8dcdb6311bb.yml +60 -0
  80. data/test/fixtures/User/0b4a60c6c962b4b3af9ab21832cd76b2.yml +60 -0
  81. data/test/fixtures/User/0f635f4bb82fdc84af205efe76f43ae0.yml +60 -0
  82. data/test/fixtures/User/1c2f2c8a5372e998f38b9d387107cee2.yml +60 -0
  83. data/test/fixtures/User/1e3ab0fb92b5b1992f35256b4be7497b.yml +71 -0
  84. data/test/fixtures/User/3bac6d29256056f2b9a1ea6fad26966d.yml +60 -0
  85. data/test/fixtures/User/3ffaba64188557400a8678dbefd75990.yml +60 -0
  86. data/test/fixtures/User/5a26c7f9edf6d6027b19b57feda4a96f.yml +60 -0
  87. data/test/fixtures/User/5c17b4b5287f5d0ba390e25e99cf2270.yml +49 -0
  88. data/test/fixtures/User/6501a4db53a97afe6f7b9afeeb996888.yml +60 -0
  89. data/test/fixtures/User/6ad0dd77081f413e3df25d6a625d38cd.yml +60 -0
  90. data/test/fixtures/User/7d493f7758d9795ad522bc827cb51b77.yml +60 -0
  91. data/test/fixtures/User/89e6cb6ae39e29a154c99e0e33bb1b91.yml +60 -0
  92. data/test/fixtures/User/90a3bfe214f17305e356ad3f1a9c9ce7.yml +60 -0
  93. data/test/fixtures/User/92ad6537c8be5aab7cbd778d424f4944.yml +60 -0
  94. data/test/fixtures/User/9485b68940997e23e3721a413d4fbdd5.yml +49 -0
  95. data/test/fixtures/User/98348fe6fbecb7916faadd835916d94d.yml +60 -0
  96. data/test/fixtures/User/b63d7aa4703a3140b4d9884e9f302362.yml +60 -0
  97. data/test/fixtures/User/b8c3fd04d7bd0925c3ccd3a3978ab8e6.yml +49 -0
  98. data/test/fixtures/User/baa28f50439b903e423dbdf918fff20b.yml +62 -0
  99. data/test/fixtures/User/e51278f9f771be0c6c3ac0e4ee1b6459.yml +59 -0
  100. data/test/fixtures/User/eb30a195ac7829d506954f472e9e6dea.yml +60 -0
  101. data/test/support/factory.rb +45 -0
  102. data/test/support/hydra_cache.rb +59 -0
  103. data/test/test_helper.rb +36 -0
  104. metadata +330 -0
@@ -0,0 +1,141 @@
1
+ require 'test_helper'
2
+
3
+ describe Amiando::Event do
4
+ before do
5
+ Amiando.api_key = Amiando::TEST_KEY
6
+ HydraCache.prefix = 'Event'
7
+ end
8
+
9
+ after do
10
+ Amiando.api_key = nil
11
+ HydraCache.prefix = nil
12
+ end
13
+
14
+ describe 'find' do
15
+ it 'finds an already existing event' do
16
+ original = Amiando::Factory(:event, :identifier => 'wadus')
17
+ Amiando.run
18
+
19
+ event = Amiando::Event.find(original.id)
20
+ Amiando.run
21
+
22
+ event.id.must_equal original.id
23
+ event.identifier.must_equal 'wadus'
24
+ end
25
+ end
26
+
27
+ describe 'exists' do
28
+ it 'checks if an event an already exists' do
29
+ original = Amiando::Factory(:event, :identifier => 'wadus')
30
+ Amiando.run
31
+
32
+ exists = Amiando::Event.exists?('wadus')
33
+ Amiando.run
34
+
35
+ exists.result.must_equal true
36
+ end
37
+ end
38
+
39
+ describe 'create' do
40
+ it 'creates an event wit valid parameters passed' do
41
+ event = Amiando::Event.create(
42
+ :host_id => Amiando::TEST_USER.id,
43
+ :title => 'Secret title',
44
+ :country => 'es',
45
+ :selected_date => Time.at(0)
46
+ )
47
+
48
+ Amiando.run
49
+
50
+ event.id.wont_be_nil
51
+ event.success.must_equal true
52
+ end
53
+ end
54
+
55
+ describe 'update' do
56
+ it 'updates the event' do
57
+ event = Amiando::Factory.create(:event, :title => 'wadus',
58
+ :identifier => "event-identifier-update-#{HydraCache.revision}")
59
+
60
+ Amiando::Event.update(event.id, :title => 'wadus 2')
61
+ Amiando.run
62
+
63
+ event = Amiando::Event.find(event.id)
64
+ Amiando.run
65
+
66
+ event.title.must_equal 'wadus 2'
67
+ end
68
+ end
69
+
70
+ describe 'find_all_by_user_id' do
71
+ it 'fetches event ids for a user' do
72
+ event = Amiando::Factory.create(:event, :identifier => "event-identifier-find-all-#{HydraCache.revision}")
73
+
74
+ all = Amiando::Event.find_all_by_user_id(Amiando::TEST_USER.id)
75
+ Amiando.run
76
+
77
+ all.result.must_include event.id
78
+ end
79
+ end
80
+
81
+ describe 'activate' do
82
+ it "returns errors if it can't be activated" do
83
+ event = Amiando::Factory.create(:event, :identifier => "event-identifier-activate-#{HydraCache.revision}")
84
+
85
+ activated = Amiando::Event.activate(event.id)
86
+ Amiando.run
87
+
88
+ activated.result.must_equal false
89
+ activated.errors.wont_be_empty
90
+ end
91
+
92
+ ##
93
+ # To be implemented when we can do everything necessary to activate an event
94
+ # (create ticket categories, etc).
95
+ # it 'activates the event' do
96
+ # end
97
+ end
98
+
99
+ describe 'delete' do
100
+ it 'deletes the event' do
101
+ event = Amiando::Factory.create(:event, :identifier => "event-identifier-#{HydraCache.revision}")
102
+
103
+ deleted = Amiando::Event.delete(event.id)
104
+ Amiando.run
105
+
106
+ deleted.result.must_equal true
107
+
108
+ exists = Amiando::Event.exists?(event.id)
109
+ Amiando.run
110
+
111
+ exists.result.must_equal false
112
+ end
113
+ end
114
+
115
+ describe 'search' do
116
+ it 'finds events by identifier' do
117
+ event = Amiando::Factory(:event, :identifier => 'waduswadus1234')
118
+ Amiando.run
119
+
120
+ search = Amiando::Event.search(:identifier => 'waduswadus1234')
121
+ Amiando.run
122
+
123
+ search.result.must_include event.id
124
+ end
125
+
126
+ it 'finds events by title' do
127
+ event = Amiando::Factory(:event, :title => 'Long title wadus bang bang bang')
128
+ Amiando.run
129
+
130
+ search = Amiando::Event.search(:title => 'Long title wadus bang bang bang')
131
+ Amiando.run
132
+
133
+ search.result.must_include event.id
134
+ end
135
+
136
+ it 'raises an error if more than one or no search option passed' do
137
+ lambda { Amiando::Event.search :title => 'a', :identifier => 'e' }.must_raise ArgumentError
138
+ lambda { Amiando::Event.search({})}.must_raise ArgumentError
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,68 @@
1
+ require 'test_helper'
2
+
3
+ describe Amiando::Resource do
4
+ class Wadus < Amiando::Resource
5
+ map :first_name, :firstName
6
+ map :last_name , :lastName
7
+ map :creation, :creation, :type => :time
8
+
9
+ def self.create
10
+ post new, 'somewhere'
11
+ end
12
+ end
13
+
14
+ it 'raises error when amiando is down' do
15
+ stub_request(:post, /somewhere/).to_return(:status => 503)
16
+ lambda {
17
+ key = Wadus.create
18
+ Amiando.run
19
+ }.must_raise Amiando::Error::ServiceDown
20
+ end
21
+
22
+ it 'raises an error if populate method is not implemented' do
23
+ lambda {
24
+ Wadus.new.populate(nil)
25
+ }.must_raise Amiando::Error::NotImplemented
26
+ end
27
+
28
+ it "raises an error when the call doesnt supply the required api key" do
29
+ stub_request(:post, /somewhere/).to_return(
30
+ :status => 400,
31
+ :body => "{\"errors\":[\"com.amiando.api.rest.MissingParam.apikey\"],\"success\":false}"
32
+ )
33
+
34
+ lambda {
35
+ Wadus.create
36
+ Amiando.run
37
+ }.must_raise Amiando::Error::MissingApiKey
38
+ end
39
+
40
+ it 'maps attributes appropriately' do
41
+ expected = {:firstName => '1', :lastName => '2', :wadus => '3'}
42
+ Wadus.map_params(:first_name => '1', :last_name => '2', :wadus => '3').must_equal expected
43
+ end
44
+
45
+ it 'reverse maps attributes appropriately' do
46
+ expected = {:first_name => '1', :last_name => '2', :wadus => '3'}
47
+ Wadus.reverse_map_params(:firstName => '1', :lastName => '2', :wadus => '3').must_equal expected
48
+ Wadus.reverse_map_params('firstName' => '1', 'lastName' => '2', 'wadus' => '3').must_equal expected
49
+ end
50
+
51
+ it 'maps attributes with typecasting' do
52
+ time = Time.at(0)
53
+ expected = { :creation => '1970-01-01T01:00:00+01:00' }
54
+ Wadus.map_params(:creation => time).must_equal expected
55
+ end
56
+
57
+ it 'automatically typecasts if the object is a Time' do
58
+ time = Time.at(0)
59
+ expected = { :firstName => '1970-01-01T01:00:00+01:00' }
60
+ Wadus.map_params(:first_name => time).must_equal expected
61
+ end
62
+
63
+ it 'reverse maps attributes with typecasting' do
64
+ time = Time.at(0)
65
+ expected = { :creation => time }
66
+ Wadus.reverse_map_params(:creation => '1970-01-01T01:00:00+01:00').must_equal expected
67
+ end
68
+ end
@@ -0,0 +1,25 @@
1
+ require 'test_helper'
2
+
3
+ describe Amiando::Result do
4
+ it "raises error if you try to get the result before it's been calculated" do
5
+ lambda { result = Amiando::Result.new{}; result.result }.must_raise Amiando::Error::NotInitialized
6
+ end
7
+
8
+ it "uses the passed block to calculate the result" do
9
+ result = Amiando::Result.new do |something|
10
+ something * 2
11
+ end
12
+ result.populate(2)
13
+ result.result.must_equal 4
14
+ end
15
+
16
+ it "can access itself in the block" do
17
+ result = Amiando::Result.new do |something, res|
18
+ res.errors = ["hi"]
19
+ something * 2
20
+ end
21
+ result.populate(2)
22
+ result.result.must_equal 4
23
+ result.errors.must_equal ["hi"]
24
+ end
25
+ end
@@ -0,0 +1,89 @@
1
+ require "test_helper"
2
+
3
+ describe Amiando::TicketCategory do
4
+ before do
5
+ Amiando.api_key = Amiando::TEST_KEY
6
+ HydraCache.prefix = 'TicketCategory'
7
+ end
8
+
9
+ after do
10
+ Amiando.api_key = nil
11
+ HydraCache.prefix = nil
12
+ end
13
+
14
+ describe 'create' do
15
+ it 'should create a ticket category given valid required parameters' do
16
+ event = Amiando::Factory.create(:event)
17
+ ticket_category = Amiando::TicketCategory.create(event.id,
18
+ :name => "Name",
19
+ :price => "50",
20
+ :available => "1"
21
+ )
22
+
23
+ Amiando.run
24
+
25
+ ticket_category.id.wont_be_nil
26
+ ticket_category.success.must_equal true
27
+ end
28
+
29
+ it 'should return errors if invalid data given' do
30
+ ticket_category = Amiando::Factory.create(:ticket_category, :name => "")
31
+
32
+ ticket_category.success.must_equal false
33
+ ticket_category.errors.must_include "com.amiando.api.rest.MissingParam.name"
34
+ end
35
+ end
36
+
37
+ describe 'update' do
38
+ it 'should update a ticket category given valid parameters' do
39
+ ticket_category = Amiando::Factory.create(:ticket_category)
40
+
41
+ update = Amiando::TicketCategory.update(ticket_category.id, :name => "New name")
42
+ Amiando.run
43
+
44
+ update.result.must_equal true
45
+ end
46
+
47
+ it 'should return errors if invalid data given' do
48
+ ticket_category = Amiando::Factory.create(:ticket_category)
49
+
50
+ update = Amiando::TicketCategory.update(ticket_category.id, :name => "")
51
+ Amiando.run
52
+
53
+ update.result.must_equal false
54
+ update.errors.must_include "com.amiando.TicketCategory.NameMissing"
55
+ end
56
+ end
57
+
58
+ describe 'find' do
59
+ it 'finds a ticket category given the id' do
60
+ ticket_category = Amiando::Factory.create(:ticket_category)
61
+ found = Amiando::TicketCategory.find(ticket_category.id)
62
+ Amiando.run
63
+
64
+ found.must_equal ticket_category
65
+ end
66
+ end
67
+
68
+ describe 'find_all_by_event_id' do
69
+ it 'fetches ticket category ids for the event' do
70
+ event = Amiando::Factory.create(:event)
71
+ ticket_category = Amiando::Factory.create(:ticket_category, :event => event)
72
+
73
+ found = Amiando::TicketCategory.find_all_by_event_id(event.id)
74
+ Amiando.run
75
+
76
+ found.result.must_include ticket_category.id
77
+ end
78
+
79
+ it 'fetches ticket categories for the event' do
80
+ event = Amiando::Factory.create(:event)
81
+ ticket_category = Amiando::Factory.create(:ticket_category, :event => event)
82
+
83
+ found = Amiando::TicketCategory.find_all_by_event_id(event.id, :full)
84
+ Amiando.run
85
+
86
+ found.result.must_include ticket_category
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,42 @@
1
+ require 'test_helper'
2
+
3
+ describe Amiando::TicketShop do
4
+ before do
5
+ Amiando.api_key = Amiando::TEST_KEY
6
+ HydraCache.prefix = 'TicketShop'
7
+ end
8
+
9
+ after do
10
+ Amiando.api_key = nil
11
+ HydraCache.prefix = nil
12
+ end
13
+
14
+ describe 'find' do
15
+ it 'gets the ticket shop of an event' do
16
+ event = Amiando::Factory.create(:event, :identifier => "event-ticketshop-find-#{HydraCache.revision}")
17
+
18
+ ticket_shop = Amiando::TicketShop.find(event.id)
19
+ Amiando.run
20
+
21
+ ticket_shop.id.wont_be_nil
22
+ ticket_shop.ticket_base_fee.wont_be_nil
23
+ ticket_shop.fee_inclusive.wont_be_nil
24
+ end
25
+ end
26
+
27
+ describe 'update' do
28
+ it 'updates the values of the ticketshop' do
29
+ event = Amiando::Factory.create(:event, :identifier => "event-ticketshop-update-#{HydraCache.revision}")
30
+
31
+ update = Amiando::TicketShop.update(event.id, :fee_inclusive => true, :shipment_fee_inclusive => true, :currency => 'USD')
32
+ Amiando.run
33
+
34
+ ticket_shop = Amiando::TicketShop.find(event.id)
35
+ Amiando.run
36
+
37
+ ticket_shop.fee_inclusive.must_equal true
38
+ ticket_shop.shipment_fee_inclusive.must_equal true
39
+ ticket_shop.currency.must_equal 'USD'
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,130 @@
1
+ require 'test_helper'
2
+
3
+ describe Amiando::User do
4
+ before do
5
+ Amiando.api_key = Amiando::TEST_KEY
6
+ HydraCache.prefix = 'User'
7
+ end
8
+
9
+ after do
10
+ Amiando.api_key = nil
11
+ HydraCache.prefix = nil
12
+ end
13
+
14
+ describe 'create' do
15
+ it 'creates a user with valid parameters passed' do
16
+ user = Amiando::User.create(
17
+ :first_name => 'Jorge',
18
+ :last_name => 'Llop',
19
+ :username => "jorgellop-#{HydraCache.revision}@example.com",
20
+ :password => '123456',
21
+ :language => 'es'
22
+ )
23
+ Amiando.run
24
+
25
+ user.id.wont_be_nil
26
+ user.success.must_equal true
27
+ end
28
+ end
29
+
30
+ describe 'exists?' do
31
+ it "will return if the user exists" do
32
+ username = "jorgellop-exists-#{HydraCache.revision}@example.com"
33
+ user = Amiando::Factory.create(:user, :username => username)
34
+
35
+ exists = Amiando::User.exists?(username)
36
+ Amiando.run
37
+
38
+ exists.result.must_equal true
39
+ end
40
+ end
41
+
42
+ describe 'find_by_username' do
43
+ it 'should return the user id when found' do
44
+ username = "jorgellop-find_by_username-#{HydraCache.revision}@example.com"
45
+ user = Amiando::Factory.create(:user, :username => username)
46
+
47
+ result = Amiando::User.find_by_username(username)
48
+ Amiando.run
49
+
50
+ result.result.must_equal user.id
51
+ end
52
+ end
53
+
54
+ describe 'logout' do
55
+ it 'logs out a user if exists' do
56
+ username = "jorgellop-logout-test-#{HydraCache.revision}@example.com"
57
+ user = Amiando::Factory.create(:user, :username => username)
58
+
59
+ logout = Amiando::User.logout(user.id)
60
+ Amiando.run
61
+
62
+ logout.result.must_equal true
63
+ end
64
+ end
65
+
66
+ describe 'update' do
67
+ it 'updates a user given the id' do
68
+ username = "jorgellop-update-#{HydraCache.revision}@example.com"
69
+ user = Amiando::Factory.create(:user, :username => username)
70
+
71
+ update = Amiando::User.update(user.id, :telephone => "0034666666666")
72
+ Amiando.run
73
+
74
+ update.result.must_equal true
75
+ end
76
+ end
77
+
78
+ describe 'find' do
79
+ it 'finds a user given the id' do
80
+ username = "jorgellop-find-#{HydraCache.revision}@example.com"
81
+ user = Amiando::Factory.create(:user, :username => username)
82
+
83
+ found = Amiando::User.find(user.id)
84
+ Amiando.run
85
+
86
+ found.must_equal user
87
+ end
88
+ end
89
+
90
+ describe 'delete' do
91
+ it 'should delete a user' do
92
+ username = "jorgellop-delete-#{HydraCache.revision}@example.com"
93
+ user = Amiando::Factory.create(:user, :username => username)
94
+
95
+ deleted = Amiando::User.delete(user.id)
96
+ Amiando.run
97
+
98
+ deleted.result.must_equal true
99
+ end
100
+ end
101
+
102
+ describe 'request_permission' do
103
+ it 'should be successful given the right password' do
104
+ username = "jorgellop-request-permission-#{HydraCache.revision}@example.com"
105
+ user = Amiando::Factory(:user, :username => username, :password => '12345')
106
+ key = Amiando::Factory(:api_key)
107
+ Amiando.run
108
+
109
+ Amiando.api_key = key.key
110
+ permission = Amiando::User.request_permission(user.id, '12345')
111
+ Amiando.run
112
+
113
+ permission.result.must_equal true
114
+ end
115
+
116
+ it 'should not be successful given the wrong password' do
117
+ username = "jorgellop-request-permission-#{HydraCache.revision}@example.com"
118
+ user = Amiando::Factory(:user, :username => username, :password => '12345')
119
+ key = Amiando::Factory(:api_key)
120
+ Amiando.run
121
+
122
+ Amiando.api_key = key.key
123
+ permission = Amiando::User.request_permission(user.id, 'wrong password')
124
+ Amiando.run
125
+
126
+ permission.result.must_equal false
127
+ permission.errors.must_include "com.amiando.api.rest.InvalidPassword"
128
+ end
129
+ end
130
+ end