Skip to content

Instantly share code, notes, and snippets.

@fjbelchi
Created March 5, 2015 09:07
Show Gist options
  • Save fjbelchi/cfb35d6e46f65560f7b0 to your computer and use it in GitHub Desktop.
Save fjbelchi/cfb35d6e46f65560f7b0 to your computer and use it in GitHub Desktop.
Test uploading image
require 'airborne'
token = '9iuz9f5fc3b79156a344b904417453e1b0679f5fc3b79156a344b904417453e1b067'
header_auth = {'Wam-Token': token, Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
header = {Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
describe 'Uploading image to feed' do
describe 'should login and have permission' do
before(:all) do
# Request
headers = {Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
params = {email: 'brett.martin+52@workangel.com', password:'newpasswordforbrett9'}
post 'http://qa.api-v13.workivate.com/auth/mobile', params, header
end
it 'valid response' do
# Expectations
expect_status(200) # HTTP Status
expect_json_types({body: :object}) # Body Type
expect_json('body',{user:{user_id:'52d90a47fcdc48c613000060'}}) # UserId
# Here it should check all the properties of the response
expect(json_body[:error]).to be_nil # No Error
expect(json_body[:pagination]).to be_nil # No Pagination
end
it 'should have enable social, social_feed and social_feed_post' do
feature_list = json_body[:body][:user][:feature_list]
expect(feature_list[:social]).to eq(true)
expect(feature_list[:social_feed]).to eq(true)
expect(feature_list[:social_feed_post]).to eq(true)
end
end
describe 'should send a post with image' do
before(:all) do
headers = {'Wam-Token': token, Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
params = {message: 'rspec test', 'data_upload': true}
post 'http://qa.api-v13.workivate.com/feed/post', params, header_auth
end
it 'valid response' do
expect_status(200)
expect_json_types({body: :object}) # Body Type
# Here it should check all the properties of the post
expect(json_body[:error]).to be_nil # No Error
expect(json_body[:pagination]).to be_nil # No Pagination
end
it 'should upload image' do
post_id = json_body[:body][:post_id]
post "http://qa.api-v13.workivate.com/feed/post/#{post_id}/image", {upload:{file:File.new('./image.png'), multipart: true}}, header_auth
expect(json_body[:error]).to be_nil # No Error
expect(json_body[:pagination]).to be_nil # No Pagination
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment