|
|
|
@ -1,10 +1,19 @@
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
require_relative '../../lib/cartodb/central'
|
|
|
|
|
|
|
|
|
|
def config
|
|
|
|
|
Cartodb.config[:cartodb_central_api].deep_symbolize_keys
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def config_present?
|
|
|
|
|
Cartodb.config[:cartodb_central_api].present? &&
|
|
|
|
|
Cartodb.config[:cartodb_central_api]['username'].present? &&
|
|
|
|
|
Cartodb.config[:cartodb_central_api]['password'].present?
|
|
|
|
|
config.present? &&
|
|
|
|
|
config[:username].present? &&
|
|
|
|
|
config[:password].present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def assert_headers_and_auth(request)
|
|
|
|
|
request.options[:headers]["Content-Type"].should == "application/json"
|
|
|
|
|
request.options[:userpwd].should == "#{ config[:username] }:#{ config[:password] }"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe Cartodb::Central do
|
|
|
|
@ -35,10 +44,18 @@ describe Cartodb::Central do
|
|
|
|
|
describe "Organization users" do
|
|
|
|
|
it "gets all users from an organization" do
|
|
|
|
|
request = @cartodb_central_client.build_request(@users_path, nil, :get)
|
|
|
|
|
|
|
|
|
|
request.url.should == "#{ @cartodb_central_client.host }/#{ @users_path }"
|
|
|
|
|
request.options[:method].should == :get
|
|
|
|
|
assert_headers_and_auth(request)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "gets an organization user" do
|
|
|
|
|
request = @cartodb_central_client.build_request(@user_path, nil, :get)
|
|
|
|
|
|
|
|
|
|
request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }"
|
|
|
|
|
request.options[:method].should == :get
|
|
|
|
|
assert_headers_and_auth(request)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "creates an organization user" do
|
|
|
|
@ -47,9 +64,9 @@ describe Cartodb::Central do
|
|
|
|
|
request = @cartodb_central_client.build_request(@user_path, body, :post)
|
|
|
|
|
|
|
|
|
|
request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }"
|
|
|
|
|
request.options[:headers]["Content-Type"].should == "application/json"
|
|
|
|
|
request.options[:method].should == :post
|
|
|
|
|
request.options[:body].should == { user: @user.allowed_attributes_to_central(:create) }.to_json
|
|
|
|
|
assert_headers_and_auth(request)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "updates an organization user" do
|
|
|
|
@ -58,17 +75,17 @@ describe Cartodb::Central do
|
|
|
|
|
request = @cartodb_central_client.build_request(@user_path, body, :put)
|
|
|
|
|
|
|
|
|
|
request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }"
|
|
|
|
|
request.options[:headers]["Content-Type"].should == "application/json"
|
|
|
|
|
request.options[:method].should == :put
|
|
|
|
|
request.options[:body].should == { user: @user.allowed_attributes_to_central(:update) }.to_json
|
|
|
|
|
assert_headers_and_auth(request)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "deletes an organization user" do
|
|
|
|
|
request = @cartodb_central_client.build_request(@user_path, nil, :delete)
|
|
|
|
|
|
|
|
|
|
request.url.should == "#{ @cartodb_central_client.host }/#{ @user_path }"
|
|
|
|
|
request.options[:headers]["Content-Type"].should == "application/json"
|
|
|
|
|
request.options[:method].should == :delete
|
|
|
|
|
assert_headers_and_auth(request)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|