cartodb-4.42/services/datasources/spec/unit/gdrive_spec.rb
2024-04-06 05:25:13 +00:00

54 lines
1.6 KiB
Ruby

require_relative '../../../../spec/rspec_configuration'
require_relative '../../lib/datasources'
require_relative '../doubles/user'
include CartoDB::Datasources
describe Url::GDrive do
def get_config
{
'application_name' => '',
'client_id' => '',
'client_secret' => '',
'callback_url' => 'http://localhost/callback'
}
end #get_config
describe '#filters' do
it 'test that filter options work correctly' do
# Stubs Google Drive client for connectionless testing
Google::Apis::DriveV2::DriveService.any_instance.stubs(:get_file)
Google::Apis::DriveV2::DriveService.any_instance.stubs(:export_file)
Google::Apis::DriveV2::DriveService.any_instance.stubs(:list_files)
user_mock = CartoDB::Datasources::Doubles::User.new
gdrive_provider = Url::GDrive.get_new(get_config, user_mock)
# No filter = all formats allowed
filter = []
Url::GDrive::FORMATS_TO_MIME_TYPES.each do |id, mime_types|
mime_types.each do |mime_type|
filter = filter.push(mime_type)
end
end
gdrive_provider.filter.should eq filter
# Filter to 'documents'
filter = []
format_ids = [ Url::GDrive::FORMAT_CSV, Url::GDrive::FORMAT_EXCEL ]
Url::GDrive::FORMATS_TO_MIME_TYPES.each do |id, mime_types|
if format_ids.include?(id)
mime_types.each do |mime_type|
filter = filter.push(mime_type)
end
end
end
gdrive_provider.filter = format_ids
gdrive_provider.filter.should eq filter
end
end #run
end