forked from whazzmaster/fitgem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fitgem_activities_spec.rb
171 lines (146 loc) · 5.39 KB
/
fitgem_activities_spec.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
require 'spec_helper'
describe Fitgem::Client do
before do
@client = Fitgem::Client.new({
:consumer_key => '12345',
:consumer_secret => '67890'
})
end
describe '#create_or_update_daily_goal' do
before(:each) do
@opts = {type: :steps, value: '10000'}
end
it 'raises an exception if the :type value is missing' do
@opts.delete :type
expect {
@client.create_or_update_daily_goal @opts
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the :type value is not valid' do
@opts[:type] = :milesWalked
expect {
@client.create_or_update_daily_goal @opts
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the :value value is missing' do
@opts.delete :value
expect {
@client.create_or_update_daily_goal @opts
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'posts to the correct URI if the :type and :value are valid' do
expect(@client).to receive(:post).with('/user/-/activities/goals/daily.json', @opts)
@client.create_or_update_daily_goal @opts
end
end
describe '#create_or_update_weekly_goal' do
before(:each) do
@opts = { type: :steps, value: '10000' }
end
it 'raises an exception if the :type value is missing' do
@opts.delete :type
expect {
@client.create_or_update_weekly_goal @opts
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the :type value is not valid' do
@opts[:type] = :milesWalked
expect {
@client.create_or_update_weekly_goal @opts
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the :value value is missing' do
@opts.delete :value
expect {
@client.create_or_update_weekly_goal @opts
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'posts to the correct URI if the :type and :value are valid' do
expect(@client).to receive(:post).with('/user/-/activities/goals/weekly.json', @opts)
@client.create_or_update_weekly_goal @opts
end
end
describe '#intraday_time_series' do
before(:each) do
@date_opts = {
resource: :calories,
date: '2013-05-13',
detailLevel: '1min'
}
@time_opts = {
resource: :calories,
date: '2013-05-13',
detailLevel: '15min',
startTime: '10:00',
endTime: '13:00'
}
end
it 'raises an exception if the resource is missing' do
expect {
@client.intraday_time_series(@date_opts.merge!(resource: nil))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the resource is not valid' do
expect {
@client.intraday_time_series(@date_opts.merge!(resource: :some_wrong_thing))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'valid resources should not raise an error' do
allow(@client).to receive(:raw_get)
[:calories, :steps, :distance, :floors, :elevation].each do |resource|
opts = { resource: resource, date: '2013-05-13', detailLevel: '15min' }
expect{
@client.intraday_time_series(opts)
}.not_to raise_error
end
end
it 'raises an exception if the date is missing' do
expect {
@client.intraday_time_series(@date_opts.merge!(date: nil))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the date is invalid' do
expect {
@client.intraday_time_series(@date_opts.merge!(date: 'zach-is-cool'))
}.to raise_error(Fitgem::InvalidDateArgument)
end
it 'raises an exception if the detail level is missing' do
expect {
@client.intraday_time_series(@date_opts.merge!(detailLevel: nil))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the detail level is invalid' do
expect {
@client.intraday_time_series(@date_opts.merge!(detailLevel: '5years'))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if only the start time is supplied' do
expect {
@client.intraday_time_series(@time_opts.merge!(endTime: nil))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if only the end time is supplied' do
expect {
@client.intraday_time_series(@time_opts.merge!(startTime: nil))
}.to raise_error(Fitgem::InvalidArgumentError)
end
it 'raises an exception if the start time is invalid' do
expect {
@client.intraday_time_series(@time_opts.merge!(startTime: 'what-is-this-nonsense'))
}.to raise_error(Fitgem::InvalidTimeArgument)
end
it 'raises an exception if the end time is invalid' do
expect {
@client.intraday_time_series(@time_opts.merge!(endTime: 'what-is-this-nonsense'))
}.to raise_error(Fitgem::InvalidTimeArgument)
end
it 'constructs the correct time-based url' do
expect(@client).to receive(:get).with('/user/-/activities/calories/date/2013-05-13/1d/15min/time/10:00/13:00.json', {})
@client.intraday_time_series(@time_opts)
end
it 'constructs the correct date-based url' do
expect(@client).to receive(:get).with('/user/-/activities/calories/date/2013-05-13/1d/1min.json', {})
@client.intraday_time_series(@date_opts)
end
end
end