@@ -121,6 +121,33 @@ def test_track_with_array_property_value
121121 exception . message
122122 end
123123
124+ def test_track_with_non_date_timestamp
125+ exception = assert_raises ArgumentError do
126+ @heap . track 'test_track_with_array_property_value' , 'test-identity' , { } , :timestamp => 'foobar'
127+ end
128+ assert_equal ArgumentError , exception . class
129+ assert_equal 'Unsupported timestamp format foobar. Must be iso8601 or unix epoch milliseconds.' ,
130+ exception . message
131+ end
132+
133+ def test_track_with_array_timestamp
134+ exception = assert_raises ArgumentError do
135+ @heap . track 'test_track_with_array_property_value' , 'test-identity' , { } , :timestamp => [ ]
136+ end
137+ assert_equal ArgumentError , exception . class
138+ assert_equal 'Unsupported timestamp format []. Must be iso8601 or unix epoch milliseconds.' ,
139+ exception . message
140+ end
141+
142+ def test_track_with_array_idempotency_key
143+ exception = assert_raises ArgumentError do
144+ @heap . track 'test_track_with_array_property_value' , 'test-identity' , { } , :idempotency_key => [ ]
145+ end
146+ assert_equal ArgumentError , exception . class
147+ assert_equal 'Unsupported idempotency key format for []. Must be string or integer' ,
148+ exception . message
149+ end
150+
124151 def test_track
125152 @stubs . post '/api/track' do |env |
126153 golden_body = {
@@ -174,6 +201,67 @@ def test_track_with_properties
174201 'test-identity' , 'foo' => 'bar' , :heap => :hurray )
175202 end
176203
204+ def test_track_with_timestamp
205+ @stubs . post '/api/track' do |env |
206+ golden_body = {
207+ 'app_id' => 'test-app-id' ,
208+ 'identity' => 'test-identity' ,
209+ 'event' => 'test_track_with_timestamp' ,
210+ 'properties' => { } ,
211+ 'timestamp' => '1524038400000'
212+ }
213+ assert_equal 'application/json' , env [ :request_headers ] [ 'Content-Type' ]
214+ assert_equal @heap . user_agent , env [ :request_headers ] [ 'User-Agent' ]
215+ assert_equal golden_body , JSON . parse ( env [ :body ] )
216+
217+ [ 200 , { 'Content-Type' => 'text/plain; encoding=utf8' } , '' ]
218+ end
219+
220+ assert_equal @heap , @heap . track ( 'test_track_with_timestamp' ,
221+ 'test-identity' , { } , :timestamp => Time . parse ( "2018-04-18 08:00:00 UTC" ) )
222+ end
223+
224+ def test_track_with_iso8601_timestamp
225+ timestamp = "2018-04-18T22:42:38+03:00"
226+ @stubs . post '/api/track' do |env |
227+ golden_body = {
228+ 'app_id' => 'test-app-id' ,
229+ 'identity' => 'test-identity' ,
230+ 'event' => 'test_track_with_iso8601_timestamp' ,
231+ 'properties' => { } ,
232+ 'timestamp' => timestamp
233+ }
234+ assert_equal 'application/json' , env [ :request_headers ] [ 'Content-Type' ]
235+ assert_equal @heap . user_agent , env [ :request_headers ] [ 'User-Agent' ]
236+ assert_equal golden_body , JSON . parse ( env [ :body ] )
237+
238+ [ 200 , { 'Content-Type' => 'text/plain; encoding=utf8' } , '' ]
239+ end
240+
241+ assert_equal @heap , @heap . track ( 'test_track_with_iso8601_timestamp' ,
242+ 'test-identity' , { } , :timestamp => timestamp )
243+ end
244+
245+ def test_track_with_idempotency_key
246+ @stubs . post '/api/track' do |env |
247+ golden_body = {
248+ 'app_id' => 'test-app-id' ,
249+ 'identity' => 'test-identity' ,
250+ 'event' => 'test_track_with_idempotency_key' ,
251+ 'properties' => { } ,
252+ 'idempotency_key' => 'foobar35214532512'
253+ }
254+ assert_equal 'application/json' , env [ :request_headers ] [ 'Content-Type' ]
255+ assert_equal @heap . user_agent , env [ :request_headers ] [ 'User-Agent' ]
256+ assert_equal golden_body , JSON . parse ( env [ :body ] )
257+
258+ [ 200 , { 'Content-Type' => 'text/plain; encoding=utf8' } , '' ]
259+ end
260+
261+ assert_equal @heap , @heap . track ( 'test_track_with_idempotency_key' ,
262+ 'test-identity' , { } , :idempotency_key => 'foobar35214532512' )
263+ end
264+
177265 def test_track_error
178266 @stubs . post '/api/track' do |env |
179267 [ 400 , { 'Content-Type' => 'text/plain; encoding=utf8' } , 'Bad request' ]
0 commit comments