Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. require_relative 'Craigdroid.rb'
  2. require 'test/unit'
  3. require 'rack/test'
  4.  
  5. ENV['RACK_ENV'] = 'test'
  6.  
  7. class PostTest < Test::Unit::TestCase
  8. include Rack::Test::Methods
  9.  
  10. def app
  11. Sinatra::Application
  12. end
  13.  
  14. def test_post
  15. testHash = {:bar => 'baz'}
  16. post '/testpost', testHash.to_json, "CONTENT_TYPE" => "application/json"
  17.  
  18. # validate response here
  19. assert last_response.ok?
  20.  
  21. expectHash = {:bar => 'baz'}.to_json
  22. assert_equal expectHash, last_response.body
  23.  
  24. end
  25.  
  26. def test_addcat
  27. testHash = {:foo => 'baz'}
  28. post '/addcat', testHash.to_json, "CONTENT_TYPE" => "application/json"
  29.  
  30. # validate response here
  31. assert last_response.ok?
  32.  
  33. expectHash = {:foo => 'baz'}.to_json
  34. assert_equal expectHash, last_response.body
  35.  
  36. end
  37.  
  38. def test_addpost
  39. testHash = {:dateCreated => 1309508060474,:dateModified => 1309508065331,:description => 'second hand book for sale',:id => 0,:location => 'makati',:price => 0,:subcategory => [{:category => [{:id => 1,:name => 'Community',:postDisclaimer => nil,:priceAware => false,:searchDisclaimer => nil }],:id => 1,:name => 'subcategory Community - 1' }], :title => 'lord of the rings', :user => [{ :emailAddress => nil, :msisdn => '639194447777', :password => 'password' }]}
  40.  
  41. post '/addpost',testHash.to_json, "CONTENT_TYPE" => "application/json"
  42.  
  43. # validate response here
  44. assert last_response.ok?
  45.  
  46. expectHash = {:dateCreated => 1309508060474,:dateModified => 1309508065331,:description => 'second hand book for sale',:id => 0,:location => 'makati',:price => 0,:subcategory => [{:category => [{:id => 1,:name => 'Community',:postDisclaimer => nil,:priceAware => false,:searchDisclaimer => nil }],:id => 1,:name => 'subcategory Community - 1' }], :title => 'lord of the rings', :user => [{ :emailAddress => nil, :msisdn => '639194447777', :password => 'password' }]}.to_json
  47.  
  48. assert_equal expectHash, last_response.body
  49. end
  50.  
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement