From 0bf4fc9e2112e3e1fbb75482e070f9af1ef7f504 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Mon, 6 May 2024 15:58:53 +0530 Subject: [PATCH] chore: add ProcessorService spec --- .../linear/processor_service_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/lib/integrations/linear/processor_service_spec.rb diff --git a/spec/lib/integrations/linear/processor_service_spec.rb b/spec/lib/integrations/linear/processor_service_spec.rb new file mode 100644 index 000000000..0249e7806 --- /dev/null +++ b/spec/lib/integrations/linear/processor_service_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +describe Integrations::Linear::ProcessorService do + let(:account) { create(:account) } + let(:conversation) { create(:conversation, account: account) } + let(:processor) { described_class.new(account: account, conversation: conversation) } + let(:api_key) { 'valid_api_key' } + let(:url) { 'https://api.linear.app/graphql' } + let(:headers) { { 'Content-Type' => 'application/json', 'Authorization' => api_key } } + + let(:schema) { JSON.parse(File.read('spec/fixtures/linear-schema.json')) } + let(:linear_client) { Graphlient::Client.new(url, schema: Graphlient::Schema.new({ 'data' => schema }, nil), headers: headers) } + let(:linear_instance) { Linear.new(api_key) } + + before do + create(:integrations_hook, :linear, account: account) + end + + describe '#teams' do + context 'when the API response is success' do + before do + linear_instance.instance_variable_set(:@client, linear_client) + processor.instance_variable_set(:@linear_client, linear_instance) + stub_request(:post, url) + .to_return(status: 200, body: { data: { teams: { nodes: [{ id: 'team1', name: 'Team One' }] } } }.to_json) + end + + it 'returns the list of teams' do + result = processor.teams + expect(result).to eq([{ 'id' => 'team1', 'name' => 'Team One' }]) + end + end + end +end