mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-11 09:17:20 -04:00
* Add crops search API endpoint - Added GET /api/v1/crops/search endpoint. - Updated CropSearchService to support additional search options. - Manually updated Swagger documentation in swagger/v1/swagger.json. - Added request specs to verify the new endpoint. Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com> * Add crops search API endpoint - Added GET /api/v1/crops/search endpoint. - Updated CropSearchService to support additional search options. - Manually updated Swagger documentation in swagger/v1/swagger.json. - Added request specs to verify the new endpoint. Co-authored-by: CloCkWeRX <365751+CloCkWeRX@users.noreply.github.com> --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
RSpec.describe 'Crops Search' do
|
|
subject { JSON.parse response.body }
|
|
|
|
let(:headers) { { 'Accept' => 'application/vnd.api+json' } }
|
|
let!(:cabbage) { create(:crop, name: 'Cabbage', approval_status: 'approved') }
|
|
let!(:apple) { create(:crop, name: 'Apple', approval_status: 'approved') }
|
|
|
|
describe 'GET /api/v1/crops/search' do
|
|
before do
|
|
Crop.reindex
|
|
end
|
|
|
|
it 'returns crops matching the search term' do
|
|
get '/api/v1/crops/search', params: { term: 'Cabbage' }, headers: headers
|
|
expect(response).to have_http_status(:ok)
|
|
expect(subject['data'].size).to eq(1)
|
|
expect(subject['data'].first['attributes']['name']).to eq('Cabbage')
|
|
end
|
|
|
|
it 'returns empty data if no crops match' do
|
|
get '/api/v1/crops/search', params: { term: 'NonExistent' }, headers: headers
|
|
expect(response).to have_http_status(:ok)
|
|
expect(subject['data']).to be_empty
|
|
end
|
|
|
|
it 'includes meta information' do
|
|
get '/api/v1/crops/search', params: { term: 'Cabbage' }, headers: headers
|
|
expect(subject['meta']).to include('record_count' => 1, 'page_count' => 1)
|
|
end
|
|
end
|
|
end
|