mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 17:51:39 -05:00
* Move points creation logic from background jobs to service objects * Remove unused point creation jobs * Update changelog
47 lines
1.3 KiB
Ruby
47 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'Api::V1::Owntracks::Points', type: :request do
|
|
describe 'POST /api/v1/owntracks/points' do
|
|
let(:file_path) { 'spec/fixtures/files/owntracks/2024-03.rec' }
|
|
let(:json) { OwnTracks::RecParser.new(File.read(file_path)).call }
|
|
let(:point_params) { json.first }
|
|
|
|
context 'with invalid api key' do
|
|
it 'returns http unauthorized' do
|
|
post '/api/v1/owntracks/points', params: point_params
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
|
|
context 'with valid api key' do
|
|
let(:user) { create(:user) }
|
|
|
|
it 'returns ok' do
|
|
post "/api/v1/owntracks/points?api_key=#{user.api_key}", params: point_params
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
|
|
it 'creates a point immediately' do
|
|
expect do
|
|
post "/api/v1/owntracks/points?api_key=#{user.api_key}", params: point_params
|
|
end.to change(Point, :count).by(1)
|
|
end
|
|
|
|
context 'when user is inactive' do
|
|
before do
|
|
user.update(status: :inactive, active_until: 1.day.ago)
|
|
end
|
|
|
|
it 'returns http unauthorized' do
|
|
post "/api/v1/owntracks/points?api_key=#{user.api_key}", params: point_params
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|