Skip to content

Instantly share code, notes, and snippets.

@fjbelchi
Last active August 29, 2015 14:16
Show Gist options
  • Save fjbelchi/8f95937e95f5dfe64cf3 to your computer and use it in GitHub Desktop.
Save fjbelchi/8f95937e95f5dfe64cf3 to your computer and use it in GitHub Desktop.
Shop Online API test
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 'Fetching Shop Online Landing' 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 benefit and benefit_online_shop' do
feature_list = json_body[:body][:user][:feature_list]
expect(feature_list[:benefit]).to eq(true)
expect(feature_list[:benefit_online_shop]).to eq(true)
end
end
describe 'should get 3 featured offers' do
before(:all) do
headers = {'Wam-Token': token, Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
get 'http://qa.api-v13.workivate.com/benefit/online-shop/special-offer?limit=3&offset=0&order=selected_by_wa_only&selected_by_wa_only=1', header_auth
end
it 'valid response' do
expect_status(200)
expect_json_types({body: :array}) # Body Type
expect(json_body[:error]).to be_nil # No Error
expect(json_body[:pagination]).to be_nil # No Pagination
array = json_body[:body]
expect(array.count).to eq 3
end
end
describe 'should get 3 popular offers' do
before(:all) do
headers = {'Wam-Token': token, Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
get 'http://qa.api-v13.workivate.com/benefit/online-shop/special-offer?limit=3&offset=0&order=most_popular_special_offers', header_auth
end
it 'valid response' do
expect_status(200)
expect_json_types({body: :array}) # Body Type
expect(json_body[:error]).to be_nil # No Error
expect(json_body[:pagination]).to be_nil # No Pagination
array = json_body[:body]
expect(array.count).to eq 3
end
end
describe 'should get 3 recommended offers' do
before(:all) do
headers = {'Wam-Token': token, Accept: 'application/json,application/vnd.wam-api-v1.3+json', 'Content-Type': 'application/json'}
get 'http://qa.api-v13.workivate.com/benefit/online-shop/special-offer?limit=3&offset=0&order=highest_cashback&recommended_only=1', header_auth
end
it 'valid response' do
expect_status(200)
expect_json_types({body: :array}) # Body Type
expect(json_body[:error]).to be_nil # No Error
expect(json_body[:pagination]).to be_nil # No Pagination
array = json_body[:body]
expect(array.count).to eq 3
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment