validic 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rspec +0 -1
  4. data/Gemfile +12 -1
  5. data/Gemfile.lock +32 -62
  6. data/README.md +442 -28
  7. data/lib/validic.rb +3 -20
  8. data/lib/validic/app.rb +11 -0
  9. data/lib/validic/biometrics.rb +9 -0
  10. data/lib/validic/client.rb +35 -77
  11. data/lib/validic/diabetes.rb +4 -60
  12. data/lib/validic/error.rb +33 -0
  13. data/lib/validic/extra.rb +10 -0
  14. data/lib/validic/fitness.rb +4 -57
  15. data/lib/validic/nutrition.rb +5 -61
  16. data/lib/validic/organization.rb +6 -13
  17. data/lib/validic/profile.rb +4 -39
  18. data/lib/validic/response.rb +15 -0
  19. data/lib/validic/rest/apps.rb +21 -0
  20. data/lib/validic/rest/biometrics.rb +39 -0
  21. data/lib/validic/rest/diabetes.rb +39 -0
  22. data/lib/validic/rest/fitness.rb +40 -0
  23. data/lib/validic/rest/nutrition.rb +40 -0
  24. data/lib/validic/rest/organizations.rb +12 -0
  25. data/lib/validic/rest/profile.rb +18 -0
  26. data/lib/validic/rest/request.rb +95 -0
  27. data/lib/validic/rest/routine.rb +40 -0
  28. data/lib/validic/rest/sleep.rb +41 -0
  29. data/lib/validic/rest/tobacco_cessation.rb +40 -0
  30. data/lib/validic/rest/users.rb +55 -0
  31. data/lib/validic/rest/utils.rb +28 -0
  32. data/lib/validic/rest/weight.rb +43 -0
  33. data/lib/validic/routine.rb +4 -55
  34. data/lib/validic/sleep.rb +4 -59
  35. data/lib/validic/summary.rb +18 -0
  36. data/lib/validic/tobacco_cessation.rb +4 -53
  37. data/lib/validic/user.rb +4 -99
  38. data/lib/validic/utils.rb +13 -0
  39. data/lib/validic/version.rb +1 -1
  40. data/lib/validic/weight.rb +4 -57
  41. data/spec/fixtures/apps.json +32 -0
  42. data/spec/fixtures/biometrics-expanded.json +56 -0
  43. data/spec/fixtures/biometrics-extras.json +35 -0
  44. data/spec/fixtures/biometrics_record.json +36 -0
  45. data/spec/fixtures/biometrics_records.json +54 -0
  46. data/spec/fixtures/bulk_biometrics_records.json +55 -0
  47. data/spec/fixtures/bulk_diabetes_records.json +37 -0
  48. data/spec/fixtures/bulk_fitnesses.json +35 -0
  49. data/spec/fixtures/bulk_nutritions.json +37 -0
  50. data/spec/fixtures/bulk_sleeps.json +35 -0
  51. data/spec/fixtures/bulk_tobacco_cessations.json +33 -0
  52. data/spec/fixtures/conflict.json +5 -0
  53. data/spec/fixtures/diabetes-expanded.json +38 -0
  54. data/spec/fixtures/diabetes-extras.json +17 -0
  55. data/spec/fixtures/diabetes_record.json +18 -0
  56. data/spec/fixtures/diabetes_records.json +36 -0
  57. data/spec/fixtures/fitness-expanded.json +1521 -0
  58. data/spec/fixtures/fitness-extras.json +15 -0
  59. data/spec/fixtures/fitness.json +16 -0
  60. data/spec/fixtures/fitnesses.json +34 -0
  61. data/spec/fixtures/forbidden.json +5 -0
  62. data/spec/fixtures/internal_server.json +4 -0
  63. data/spec/fixtures/me.json +5 -0
  64. data/spec/fixtures/not_found.json +5 -0
  65. data/spec/fixtures/nutrition-expanded.json +123 -0
  66. data/spec/fixtures/nutrition-extras.json +13 -0
  67. data/spec/fixtures/nutrition.json +18 -0
  68. data/spec/fixtures/nutritions-expanded.json +123 -0
  69. data/spec/fixtures/nutritions.json +36 -0
  70. data/spec/fixtures/organizations.json +27 -0
  71. data/spec/fixtures/profile.json +13 -0
  72. data/spec/fixtures/refresh_token.json +7 -0
  73. data/spec/fixtures/routine-expanded.json +749 -0
  74. data/spec/fixtures/routine-extras.json +14 -0
  75. data/spec/fixtures/routine.json +17 -0
  76. data/spec/fixtures/routines.json +47 -0
  77. data/spec/fixtures/sleep-expanded.json +51 -0
  78. data/spec/fixtures/sleep-extras.json +15 -0
  79. data/spec/fixtures/sleep.json +16 -0
  80. data/spec/fixtures/sleeps.json +48 -0
  81. data/spec/fixtures/synced_apps.json +43 -0
  82. data/spec/fixtures/tobacco_cessation-expanded.json +33 -0
  83. data/spec/fixtures/tobacco_cessation-extras.json +12 -0
  84. data/spec/fixtures/tobacco_cessation.json +14 -0
  85. data/spec/fixtures/tobacco_cessations.json +32 -0
  86. data/spec/fixtures/unauthorized.json +4 -0
  87. data/spec/fixtures/unprocessable_entity.json +5 -0
  88. data/spec/fixtures/updated_user.json +9 -0
  89. data/spec/fixtures/user.json +8 -0
  90. data/spec/fixtures/user_with_profile.json +14 -0
  91. data/spec/fixtures/users.json +23 -0
  92. data/spec/fixtures/weight-expanded.json +66 -0
  93. data/spec/fixtures/weight-extras.json +15 -0
  94. data/spec/fixtures/weight.json +18 -0
  95. data/spec/fixtures/weights.json +48 -0
  96. data/spec/spec_helper.rb +47 -33
  97. data/spec/validic/client_spec.rb +5 -38
  98. data/spec/validic/error_spec.rb +73 -0
  99. data/spec/validic/expanded_spec.rb +87 -0
  100. data/spec/validic/rest/apps_spec.rb +41 -0
  101. data/spec/validic/rest/biometrics_spec.rb +131 -0
  102. data/spec/validic/rest/diabetes_spec.rb +131 -0
  103. data/spec/validic/rest/fitness_spec.rb +131 -0
  104. data/spec/validic/rest/nutrition_spec.rb +144 -0
  105. data/spec/validic/rest/organizations_spec.rb +24 -0
  106. data/spec/validic/rest/profile_spec.rb +44 -0
  107. data/spec/validic/rest/routine_spec.rb +129 -0
  108. data/spec/validic/rest/sleep_spec.rb +148 -0
  109. data/spec/validic/rest/tobacco_cessation_spec.rb +131 -0
  110. data/spec/validic/rest/users_spec.rb +170 -0
  111. data/spec/validic/rest/weight_spec.rb +150 -0
  112. data/spec/validic/summary_spec.rb +3 -0
  113. data/spec/validic_spec.rb +19 -31
  114. data/validic.gemspec +0 -13
  115. metadata +174 -194
  116. data/lib/validic/biometric.rb +0 -97
  117. data/lib/validic/request.rb +0 -46
  118. data/lib/validic/third_party_app.rb +0 -32
  119. data/spec/validic/biometrics_spec.rb +0 -43
  120. data/spec/validic/diabetes_spec.rb +0 -89
  121. data/spec/validic/fitness_spec.rb +0 -85
  122. data/spec/validic/nutrition_spec.rb +0 -91
  123. data/spec/validic/organization_spec.rb +0 -26
  124. data/spec/validic/profile_spec.rb +0 -19
  125. data/spec/validic/routine_spec.rb +0 -82
  126. data/spec/validic/sleep_spec.rb +0 -86
  127. data/spec/validic/third_party_app_spec.rb +0 -32
  128. data/spec/validic/tobacco_cessation_spec.rb +0 -81
  129. data/spec/validic/user_spec.rb +0 -81
  130. data/spec/validic/weight_spec.rb +0 -88
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validic::REST::Routine do
4
+ let(:client) { Validic::Client.new }
5
+
6
+ describe "#get_routine" do
7
+ context 'no user_id given' do
8
+ before do
9
+ stub_get('/organizations/1/routine.json')
10
+ .with(query: { access_token: '1' })
11
+ .to_return(body: fixture('routines.json'),
12
+ headers: { content_type: 'application/json; charset=utf-8' })
13
+ end
14
+ it 'returns a validic response object' do
15
+ routine = client.get_routine
16
+ expect(routine).to be_a Validic::Response
17
+ end
18
+ it 'makes a routine request to the correct url' do
19
+ client.get_routine
20
+ expect(a_get('/organizations/1/routine.json').with(query: { access_token: '1' })).to have_been_made
21
+ end
22
+ end
23
+ context 'with user_id' do
24
+ before do
25
+ stub_get('/organizations/1/users/1/routine.json')
26
+ .with(query: { access_token: '1' })
27
+ .to_return(body: fixture('routines.json'), headers: { content_type: 'application/json; charset=utf-8' })
28
+ end
29
+ it 'returns a Response' do
30
+ routine = client.get_routine(user_id: '1')
31
+ expect(routine).to be_a Validic::Response
32
+ end
33
+ it 'makes a routine request to the correct url' do
34
+ client.get_routine(user_id: '1')
35
+ expect(a_get('/organizations/1/users/1/routine.json').with(query: { access_token: '1' })).to have_been_made
36
+ end
37
+ end
38
+ end
39
+
40
+ describe '#create_routine' do
41
+ before do
42
+ stub_post("/organizations/1/users/1/routine.json")
43
+ .with(body: { routine: { timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345' },
44
+ access_token: '1' }.to_json)
45
+ .to_return(body: fixture('routine.json'),
46
+ headers: { content_type: 'application/json; charset=utf-8'} )
47
+ end
48
+ it 'requests the correct resource' do
49
+ client.create_routine(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
50
+ expect(a_post('/organizations/1/users/1/routine.json')
51
+ .with(body: { routine: { timestamp: '2013-03-10T07:12:16+00:00',
52
+ activity_id: '12345' },
53
+ access_token: '1' }.to_json)).to have_been_made
54
+ end
55
+ it 'returns a routine' do
56
+ routine = client.create_routine(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
57
+ expect(routine).to be_a Validic::Routine
58
+ expect(routine.timestamp).to eq '2013-03-10T07:12:16+00:00'
59
+ end
60
+ end
61
+
62
+ describe "#update_routine" do
63
+ before do
64
+ stub_put("/organizations/1/users/1/routine/51552cddfded0807c4000096.json")
65
+ .with(body: { routine: { timestamp: '2013-03-10T07:12:16+00:00' },
66
+ access_token: '1' }.to_json)
67
+ .to_return(body: fixture('routine.json'),
68
+ headers: {content_type: 'application/json; charset=utf-8'})
69
+ end
70
+ it 'makes a routine request to the correct url' do
71
+ client.update_routine(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
72
+ expect(a_put('/organizations/1/users/1/routine/51552cddfded0807c4000096.json')
73
+ .with(body: { routine: { timestamp: '2013-03-10T07:12:16+00:00' },
74
+ access_token: '1' }.to_json)).to have_been_made
75
+ end
76
+ it 'returns a routine' do
77
+ routine = client.update_routine(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
78
+ expect(routine).to be_a Validic::Routine
79
+ end
80
+ end
81
+
82
+ describe '#delete_routine' do
83
+ context 'when resource is found' do
84
+ before do
85
+ stub_delete("/organizations/1/users/1/routine/51552cddfded0807c4000096.json")
86
+ .to_return(status: 200)
87
+ end
88
+ it 'returns true' do
89
+ routine = client.delete_routine(user_id: '1', _id: '51552cddfded0807c4000096')
90
+ expect(routine).to be true
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#latest_routine' do
96
+ context 'with user_id' do
97
+ before do
98
+ stub_get("/organizations/1/users/2/routine/latest.json").
99
+ with(query: { access_token: '1' }).
100
+ to_return(body: fixture('routines.json'),
101
+ headers: { content_type: 'application/json; charset=utf-8' })
102
+ end
103
+ it 'makes a latest for routine' do
104
+ latest = client.latest_routine(user_id: '2')
105
+ expect(latest).to be_a Validic::Response
106
+ end
107
+ it 'builds a latest url' do
108
+ client.latest_routine(user_id: '2')
109
+ expect(a_get('/organizations/1/users/2/routine/latest.json').with(query: { access_token: '1' })).to have_been_made
110
+ end
111
+ end
112
+ context 'without user_id' do
113
+ before do
114
+ stub_get("/organizations/1/routine/latest.json").
115
+ with(query: { access_token: '1' }).
116
+ to_return(body: fixture('routines.json'),
117
+ headers: { content_type: 'application/json; charset=utf-8' })
118
+ end
119
+ it 'makes a latest for routine' do
120
+ latest = client.latest_routine
121
+ expect(latest).to be_a Validic::Response
122
+ end
123
+ it 'builds a latest url' do
124
+ client.latest_routine
125
+ expect(a_get('/organizations/1/routine/latest.json').with(query: { access_token: '1' })).to have_been_made
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validic::REST::Sleep do
4
+ let(:client) { Validic::Client.new }
5
+
6
+ describe "#get_sleeps" do
7
+ context 'no user_id given' do
8
+ before do
9
+ stub_get("/organizations/1/sleep.json")
10
+ .with(query: { access_token: '1' })
11
+ .to_return(body: fixture('sleeps.json'),
12
+ headers: { content_type: 'application/json; charset=utf-8' })
13
+ end
14
+ it 'returns a validic response object' do
15
+ sleep = client.get_sleep
16
+ expect(sleep).to be_a Validic::Response
17
+ end
18
+ it 'makes a sleep request to the correct url' do
19
+ client.get_sleep
20
+ expect(a_get('/organizations/1/sleep.json').with(query: { access_token: '1' })).to have_been_made
21
+ end
22
+ end
23
+ context 'with user_id' do
24
+ before do
25
+ stub_get("/organizations/1/users/1/sleep.json")
26
+ .with(query: { access_token: '1' })
27
+ .to_return(body: fixture('bulk_sleeps.json'),
28
+ headers: { content_type: 'application/json; charset=utf-8' })
29
+ end
30
+ it 'returns a Response' do
31
+ sleep = client.get_sleep(user_id: '1')
32
+ expect(sleep).to be_a Validic::Response
33
+ end
34
+ it 'makes a sleep request to the correct url' do
35
+ client.get_sleep(user_id: '1')
36
+ expect(a_get('/organizations/1/users/1/sleep.json').with(query: { access_token: '1' })).to have_been_made
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#create_sleep' do
42
+ before do
43
+ stub_post("/organizations/1/users/1/sleep.json").
44
+ with(body: { sleep: { timestamp: '2013-03-10T07:12:16+00:00',
45
+ utc_offset: '+00:00', total_sleep: 477,
46
+ awake: 34, deep: 234, light: 94, rem: 115,
47
+ times_woken: 4, activity_id: '12345' },
48
+ access_token: '1' }.to_json).
49
+ to_return(body: fixture('sleep.json'),
50
+ headers: { content_type: 'application/json; charset=utf-8'} )
51
+ end
52
+ it 'returns a Sleep' do
53
+ @sleep = client.create_sleep(user_id: '1', timestamp: "2013-03-10T07:12:16+00:00",
54
+ utc_offset: "+00:00",
55
+ total_sleep: 477,
56
+ awake: 34,
57
+ deep: 234,
58
+ light: 94,
59
+ rem: 115,
60
+ times_woken: 4,
61
+ activity_id: '12345')
62
+
63
+ expect(@sleep).to be_a Validic::Sleep
64
+ expect(@sleep.total_sleep).to eq 477
65
+ end
66
+ end
67
+
68
+ describe "#update_sleep" do
69
+ before do
70
+ stub_put("/organizations/1/users/1/sleep/51552cddfded0807c4000096.json").
71
+ with(body: { sleep: { timestamp: '2013-03-10T07:12:16+00:00',
72
+ utc_offset: '+00:00', total_sleep: 477,
73
+ awake: 224, deep: 234, light: 94, rem: 115,
74
+ times_woken: 4 },
75
+ access_token: '1' }.to_json).
76
+ to_return(body: fixture('sleep.json'),
77
+ headers: {content_type: 'application/json; charset=utf-8'})
78
+
79
+ @sleep = client.update_sleep(user_id: '1',
80
+ _id: "51552cddfded0807c4000096",
81
+ timestamp: "2013-03-10T07:12:16+00:00",
82
+ utc_offset: "+00:00",
83
+ total_sleep: 477,
84
+ awake: 224,
85
+ deep: 234,
86
+ light: 94,
87
+ rem: 115,
88
+ times_woken: 4)
89
+ end
90
+
91
+ it 'returns a sleep object' do
92
+ expect(@sleep).to be_a Validic::Sleep
93
+ end
94
+
95
+ it 'makes a sleep request to the correct url' do
96
+ url = "#{Validic::BASE_URL}/organizations/1/users/1/sleep/51552cddfded0807c4000096.json"
97
+ expect(a_request(:put, url)).to have_been_made
98
+ end
99
+ end
100
+
101
+ describe '#delete_sleep' do
102
+ context 'when resource is found' do
103
+ before do
104
+ stub_delete("/organizations/1/users/1/sleep/51552cddfded0807c4000096.json")
105
+ .to_return(status: 200)
106
+ end
107
+ it 'returns true' do
108
+ sleep = client.delete_sleep(user_id: '1',
109
+ _id: '51552cddfded0807c4000096')
110
+ expect(sleep).to be true
111
+ end
112
+ end
113
+ end
114
+
115
+ describe '#latest_sleep' do
116
+ context 'with user_id' do
117
+ before do
118
+ stub_get("/organizations/1/users/2/sleep/latest.json").
119
+ with(query: { access_token: '1' }).
120
+ to_return(body: fixture('sleeps.json'),
121
+ headers: { content_type: 'application/json; charset=utf-8' })
122
+ @latest = client.latest_sleep(user_id: '2')
123
+ end
124
+ it 'makes a latest for sleep' do
125
+ expect(@latest).to be_a Validic::Response
126
+ end
127
+ it 'builds a latest url' do
128
+ expect(a_get('/organizations/1/users/2/sleep/latest.json').with(query: { access_token: '1' })).to have_been_made
129
+ end
130
+ end
131
+ context 'without user_id' do
132
+ before do
133
+ stub_get("/organizations/1/sleep/latest.json").
134
+ with(query: { access_token: '1' }).
135
+ to_return(body: fixture('sleeps.json'),
136
+ headers: { content_type: 'application/json; charset=utf-8' })
137
+ @latest = client.latest_sleep
138
+ end
139
+ it 'makes a latest for sleep' do
140
+ expect(@latest).to be_a Validic::Response
141
+ end
142
+ it 'builds a latest url' do
143
+ expect(a_get('/organizations/1/sleep/latest.json').with(query: { access_token: '1' })).to have_been_made
144
+ end
145
+ end
146
+ end
147
+
148
+ end
@@ -0,0 +1,131 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::REST::TobaccoCessation do
5
+ let(:client) { Validic::Client.new }
6
+
7
+ describe "#get_tobacco_cessation" do
8
+ context 'no user_id given' do
9
+ before do
10
+ stub_get("/organizations/1/tobacco_cessation.json")
11
+ .with(query: { access_token: '1' })
12
+ .to_return(body: fixture('tobacco_cessations.json'),
13
+ headers: { content_type: 'application/json; charset=utf-8' })
14
+ end
15
+ it 'returns a validic response object' do
16
+ tobacco_cessation = client.get_tobacco_cessation
17
+ expect(tobacco_cessation).to be_a Validic::Response
18
+ end
19
+ it 'makes a tobacco_cessation request to the correct url' do
20
+ client.get_tobacco_cessation
21
+ expect(a_get('/organizations/1/tobacco_cessation.json').with(query: { access_token: '1' })).to have_been_made
22
+ end
23
+ end
24
+ context 'with user_id' do
25
+ before do
26
+ stub_get("/organizations/1/users/1/tobacco_cessation.json")
27
+ .with(query: { access_token: '1' })
28
+ .to_return(body: fixture('bulk_tobacco_cessations.json'),
29
+ headers: { content_type: 'application/json; charset=utf-8' })
30
+ end
31
+ it 'returns a Response' do
32
+ tobacco_cessation = client.get_tobacco_cessation(user_id: '1')
33
+ expect(tobacco_cessation).to be_a Validic::Response
34
+ end
35
+ it 'makes a tobacco_cessation request to the correct url' do
36
+ client.get_tobacco_cessation(user_id: '1')
37
+ expect(a_get('/organizations/1/users/1/tobacco_cessation.json').with(query: { access_token: '1' })).to have_been_made
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#create_tobacco_cessation' do
43
+ before do
44
+ stub_post("/organizations/1/users/1/tobacco_cessation.json")
45
+ .with(body: { tobacco_cessation: { timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345' },
46
+ access_token: '1' }.to_json)
47
+ .to_return(body: fixture('tobacco_cessation.json'),
48
+ headers: { content_type: 'application/json; charset=utf-8'} )
49
+ end
50
+ it 'requests the correct resource' do
51
+ client.create_tobacco_cessation(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
52
+ expect(a_post('/organizations/1/users/1/tobacco_cessation.json')
53
+ .with(body: { tobacco_cessation: { timestamp: '2013-03-10T07:12:16+00:00',
54
+ activity_id: '12345' },
55
+ access_token: '1' }.to_json)).to have_been_made
56
+ end
57
+ it 'returns a TobaccoCessation' do
58
+ tobacco_cessation = client.create_tobacco_cessation(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
59
+ expect(tobacco_cessation).to be_a Validic::TobaccoCessation
60
+ expect(tobacco_cessation.timestamp).to eq '2013-03-10T07:12:16+00:00'
61
+ end
62
+ end
63
+
64
+ describe "#update_tobacco_cessation" do
65
+ before do
66
+ stub_put("/organizations/1/users/1/tobacco_cessation/51552cddfded0807c4000096.json")
67
+ .with(body: { tobacco_cessation: { timestamp: '2013-03-10T07:12:16+00:00' },
68
+ access_token: '1' }.to_json)
69
+ .to_return(body: fixture('tobacco_cessation.json'),
70
+ headers: {content_type: 'application/json; charset=utf-8'})
71
+ end
72
+ it 'makes a tobacco_cessation request to the correct url' do
73
+ client.update_tobacco_cessation(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
74
+ expect(a_put('/organizations/1/users/1/tobacco_cessation/51552cddfded0807c4000096.json')
75
+ .with(body: { tobacco_cessation: { timestamp: '2013-03-10T07:12:16+00:00' },
76
+ access_token: '1' }.to_json)).to have_been_made
77
+ end
78
+ it 'returns a TobaccoCessation' do
79
+ tobacco_cessation = client.update_tobacco_cessation(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
80
+ expect(tobacco_cessation).to be_a Validic::TobaccoCessation
81
+ end
82
+ end
83
+
84
+ describe '#delete_tobacco_cessation' do
85
+ context 'when resource is found' do
86
+ before do
87
+ stub_delete("/organizations/1/users/1/tobacco_cessation/51552cddfded0807c4000096.json")
88
+ .to_return(status: 200)
89
+ end
90
+ it 'returns true' do
91
+ tobacco_cessation = client.delete_tobacco_cessation(user_id: '1', _id: '51552cddfded0807c4000096')
92
+ expect(tobacco_cessation).to be true
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '#latests_tobacco_cessation' do
98
+ context 'with user_id' do
99
+ before do
100
+ stub_get("/organizations/1/users/2/tobacco_cessation/latest.json").
101
+ with(query: { access_token: '1' }).
102
+ to_return(body: fixture('tobacco_cessations.json'),
103
+ headers: { content_type: 'application/json; charset=utf-8' })
104
+ end
105
+ it 'makes a latest for tobacco_cessation' do
106
+ latest = client.latest_tobacco_cessation(user_id: '2')
107
+ expect(latest).to be_a Validic::Response
108
+ end
109
+ it 'builds a latest url' do
110
+ client.latest_tobacco_cessation(user_id: '2')
111
+ expect(a_get('/organizations/1/users/2/tobacco_cessation/latest.json').with(query: { access_token: '1' })).to have_been_made
112
+ end
113
+ end
114
+ context 'without user_id' do
115
+ before do
116
+ stub_get("/organizations/1/tobacco_cessation/latest.json").
117
+ with(query: { access_token: '1' }).
118
+ to_return(body: fixture('tobacco_cessations.json'),
119
+ headers: { content_type: 'application/json; charset=utf-8' })
120
+ end
121
+ it 'makes a latest for tobacco_cessation' do
122
+ latest = client.latest_tobacco_cessation
123
+ expect(latest).to be_a Validic::Response
124
+ end
125
+ it 'builds a latest url' do
126
+ client.latest_tobacco_cessation
127
+ expect(a_get('/organizations/1/tobacco_cessation/latest.json').with(query: { access_token: '1' })).to have_been_made
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,170 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validic::REST::Users do
4
+ let(:client) { Validic::Client.new }
5
+
6
+ describe '#get_users' do
7
+ before do
8
+ stub_get("/organizations/1/users.json")
9
+ .with(query: { access_token: '1' })
10
+ .to_return(body: fixture('users.json'),
11
+ headers: { content_type: 'application/json; charset=utf-8' })
12
+ end
13
+ it 'returns a validic response object' do
14
+ users = client.get_users
15
+ expect(users).to be_a Validic::Response
16
+ end
17
+ it 'makes a users request to the correct url' do
18
+ client.get_users
19
+ expect(a_get('/organizations/1/users.json').with(query: { access_token: '1' })).to have_been_made
20
+ end
21
+ end
22
+
23
+ describe '#provision_user' do
24
+ before do
25
+ stub_post('/organizations/1/users.json')
26
+ .with(body: { user: { uid: '123467890' }, access_token: '1' }.to_json)
27
+ .to_return(body: fixture('user.json'), headers: { content_type: 'application/json; charset=utf-8' })
28
+ end
29
+ it 'requests the correct resource' do
30
+ client.provision_user(uid: '123467890')
31
+ expect(a_post('/organizations/1/users.json')
32
+ .with(body: { user: { uid: '123467890' }, access_token: '1' }.to_json))
33
+ .to have_been_made
34
+ end
35
+ it 'returns a User' do
36
+ user = client.provision_user(uid: '123467890')
37
+ expect(user).to be_a Validic::User
38
+ expect(user.uid).to eq '123467890'
39
+ end
40
+ context 'with optional profile' do
41
+ before do
42
+ stub_post('/organizations/1/users.json')
43
+ .with(body: { user: { uid: '123467890', profile: { gender: 'M' } }, access_token: '1' }.to_json)
44
+ .to_return(body: fixture('user_with_profile.json'), headers: { content_type: 'application/json; charset=utf-8' })
45
+ end
46
+ it 'returns a User with profile' do
47
+ user = client.provision_user(uid: '123467890', profile: { gender: 'M' })
48
+ expect(user).to be_a Validic::User
49
+ expect(user.uid).to eq '123467890'
50
+ expect(user.profile).to be_a Validic::Profile
51
+ expect(user.profile.gender).to eq 'M'
52
+ end
53
+ end
54
+ end
55
+
56
+ describe '#update_user' do
57
+ before do
58
+ stub_put('/organizations/1/users/1.json')
59
+ .with(body: { user: { uid: 'abcde' }, access_token: '1' }.to_json)
60
+ .to_return(body: fixture('updated_user.json'), headers: { content_type: 'application/json; charset=utf-8' })
61
+ end
62
+ it 'requests the correct resource' do
63
+ client.update_user(user_id: '1', uid: 'abcde')
64
+ expect(a_put('/organizations/1/users/1.json')
65
+ .with(body: { user: { uid: 'abcde' }, access_token: '1' }.to_json))
66
+ .to have_been_made
67
+ end
68
+ it 'returns a User' do
69
+ user = client.update_user(user_id: '1', uid: 'abcde')
70
+ expect(user).to be_a Validic::User
71
+ expect(user.uid).to eq 'abcde'
72
+ end
73
+ context 'with optional profile' do
74
+ before do
75
+ stub_put('/organizations/1/users/1.json')
76
+ .with(body: { user: { uid: '123467890', profile: { gender: 'M' } }, access_token: '1' }.to_json)
77
+ .to_return(body: fixture('user_with_profile.json'), headers: { content_type: 'application/json; charset=utf-8' })
78
+ end
79
+ it 'returns a User with profile' do
80
+ user = client.update_user(user_id: '1', uid: '123467890', profile: { gender: 'M' })
81
+ expect(user).to be_a Validic::User
82
+ expect(user.uid).to eq '123467890'
83
+ expect(user.profile).to be_a Validic::Profile
84
+ expect(user.profile.gender).to eq 'M'
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#delete_user' do
90
+ before do
91
+ stub_delete('/organizations/1/users/1.json').to_return(status: 200)
92
+ end
93
+ it 'returns true' do
94
+ response = client.delete_user(user_id: '1')
95
+ expect(response).to be true
96
+ end
97
+ end
98
+
99
+ describe '#me' do
100
+ before do
101
+ stub_get('/me.json').with(query: { access_token: '1', authentication_token: 'auth_token' })
102
+ .to_return(body: fixture('me.json'),
103
+ headers: { content_type: 'application/json; charset=utf-8' })
104
+ end
105
+ it 'makes a request to the correct resource' do
106
+ client.me(authentication_token: 'auth_token')
107
+ expect(a_get('/me.json').with(query: { access_token: '1', authentication_token: 'auth_token' }))
108
+ .to have_been_made
109
+ end
110
+ it 'returns a String' do
111
+ me = client.me(authentication_token: 'auth_token')
112
+ expect(me).to eq '1'
113
+ end
114
+ end
115
+
116
+ describe '#suspend_user' do
117
+ before do
118
+ stub_put('/organizations/1/users/1.json')
119
+ .with(body: { suspend: '1', access_token: '1' }.to_json)
120
+ .to_return(status: 200)
121
+ end
122
+ it 'makes a request to the correct resource' do
123
+ client.suspend_user(user_id: '1')
124
+ expect(a_put('/organizations/1/users/1.json')
125
+ .with(body: { suspend: '1', access_token: '1' }.to_json))
126
+ .to have_been_made
127
+ end
128
+ it 'returns true' do
129
+ response = client.suspend_user(user_id: '1')
130
+ expect(response).to be true
131
+ end
132
+ end
133
+
134
+ describe '#unsuspend_user' do
135
+ before do
136
+ stub_put('/organizations/1/users/1.json')
137
+ .with(body: { suspend: '0', access_token: '1' }.to_json)
138
+ .to_return(status: 200)
139
+ end
140
+ it 'makes a request to the correct resource' do
141
+ client.unsuspend_user(user_id: '1')
142
+ expect(a_put('/organizations/1/users/1.json')
143
+ .with(body: { suspend: '0', access_token: '1' }.to_json))
144
+ .to have_been_made
145
+ end
146
+ it 'returns true' do
147
+ response = client.unsuspend_user(user_id: '1')
148
+ expect(response).to be true
149
+ end
150
+ end
151
+
152
+ describe '#refresh_token' do
153
+ before do
154
+ stub_get('/organizations/1/users/1/refresh_token.json')
155
+ .with(query: { access_token: '1' })
156
+ .to_return(body: fixture('refresh_token.json'),
157
+ headers: { content_type: 'application/json; charset=utf-8' })
158
+ end
159
+ it 'makes a request to the correct resource' do
160
+ client.refresh_token(user_id: '1')
161
+ expect(a_get('/organizations/1/users/1/refresh_token.json')
162
+ .with(query: { access_token: '1' }))
163
+ .to have_been_made
164
+ end
165
+ it 'returns a User' do
166
+ user = client.refresh_token(user_id: '1')
167
+ expect(user).to be_a Validic::User
168
+ end
169
+ end
170
+ end