feat: search issue API

This commit is contained in:
Muhsin Keloth
2024-05-09 22:28:47 +05:30
parent df29b43540
commit 5e1dbfb64d
8 changed files with 153 additions and 0 deletions
@@ -187,4 +187,36 @@ RSpec.describe 'Linear Integration API', type: :request do
end
end
end
describe 'GET /api/v1/accounts/:account_id/integrations/linear/search_issue' do
let(:term) { 'issue' }
context 'when it is an authenticated user' do
context 'when search is successful' do
let(:search_results) { [{ 'id' => 'issue1', 'title' => 'Sample Issue' }] }
it 'returns search results' do
allow(processor_service).to receive(:search_issue).with(term).and_return(search_results)
get "/api/v1/accounts/#{account.id}/integrations/linear/search_issue",
params: { q: term },
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:ok)
expect(response.body).to include('Sample Issue')
end
end
context 'when search fails' do
it 'returns error message' do
allow(processor_service).to receive(:search_issue).with(term).and_return(error: 'error message')
get "/api/v1/accounts/#{account.id}/integrations/linear/search_issue",
params: { q: term },
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:unprocessable_entity)
expect(response.body).to include('error message')
end
end
end
end
end
@@ -128,4 +128,54 @@ describe Integrations::Linear::ProcessorService do
end
end
end
describe '#unlink_issue' do
let(:link_id) { 'attachment1' }
let(:unlink_response) { { link_id: link_id } }
context 'when Linear client returns valid data' do
it 'returns parsed unlink data' do
allow(linear_client).to receive(:unlink_issue).with(link_id).and_return(unlink_response)
result = service.unlink_issue(link_id)
expect(result).to eq(unlink_response)
end
end
context 'when Linear client returns an error' do
let(:error_response) { { error: 'Some error message' } }
it 'returns the error' do
allow(linear_client).to receive(:unlink_issue).with(link_id).and_return(error_response)
result = service.unlink_issue(link_id)
expect(result).to eq(error_response)
end
end
end
describe '#search_issue' do
let(:term) { 'search term' }
let(:search_response) do
{
'searchIssues' => { 'nodes' => [{ 'id' => 'issue1', 'title' => 'Issue title', 'description' => 'Issue description' }] }
}
end
context 'when Linear client returns valid data' do
it 'returns parsed search data' do
allow(linear_client).to receive(:search_issue).with(term).and_return(search_response)
result = service.search_issue(term)
expect(result).to contain_exactly({ 'id' => 'issue1', 'title' => 'Issue title', 'description' => 'Issue description' })
end
end
context 'when Linear client returns an error' do
let(:error_response) { { error: 'Some error message' } }
it 'returns the error' do
allow(linear_client).to receive(:search_issue).with(term).and_return(error_response)
result = service.search_issue(term)
expect(result).to eq(error_response)
end
end
end
end
+30
View File
@@ -249,4 +249,34 @@ describe Linear do
end
end
end
context 'when querying issues' do
let(:term) { 'term' }
context 'when the API response is success' do
before do
linear_client.instance_variable_set(:@client, client)
stub_request(:post, url)
.to_return(status: 200, body: { data: { searchIssues: { nodes: [{ id: 'issue1', title: 'Title' }] } } }.to_json)
end
it 'returns issues' do
response = linear_client.search_issue(term)
expect(response).to eq({ 'searchIssues' => { 'nodes' => [{ 'id' => 'issue1', 'title' => 'Title' }] } })
end
end
context 'when the API response is an error' do
before do
linear_client.instance_variable_set(:@client, client)
stub_request(:post, url)
.to_return(status: 422, body: { errors: [{ message: 'Error retrieving data' }] }.to_json)
end
it 'raises an exception' do
response = linear_client.search_issue(term)
expect(response).to eq({ :error => 'Error: the server responded with status 422' })
end
end
end
end