2025-02-11 15:04:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe 'Api::V1::Maps::TileUsage', type: :request do
|
|
|
|
|
describe 'POST /api/v1/maps/tile_usage' do
|
|
|
|
|
let(:tile_count) { 5 }
|
|
|
|
|
let(:track_service) { instance_double(Maps::TileUsage::Track) }
|
2025-02-13 15:04:29 -05:00
|
|
|
let(:user) { create(:user) }
|
2025-02-11 15:04:12 -05:00
|
|
|
|
|
|
|
|
before do
|
2025-02-13 15:04:29 -05:00
|
|
|
allow(Maps::TileUsage::Track).to receive(:new).with(user.id, tile_count).and_return(track_service)
|
2025-02-11 15:04:12 -05:00
|
|
|
allow(track_service).to receive(:call)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is authenticated' do
|
|
|
|
|
it 'tracks tile usage' do
|
|
|
|
|
post '/api/v1/maps/tile_usage',
|
|
|
|
|
params: { tile_usage: { count: tile_count } },
|
|
|
|
|
headers: { 'Authorization' => "Bearer #{user.api_key}" }
|
|
|
|
|
|
2025-02-13 15:04:29 -05:00
|
|
|
expect(Maps::TileUsage::Track).to have_received(:new).with(user.id, tile_count)
|
2025-02-11 15:04:12 -05:00
|
|
|
expect(track_service).to have_received(:call)
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user is not authenticated' do
|
|
|
|
|
it 'returns unauthorized' do
|
|
|
|
|
post '/api/v1/maps/tile_usage', params: { tile_usage: { count: tile_count } }
|
|
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|