Sha256: 7b858d3a5947d12c10df5eb77b25350a481f0ed89593977cb0b89c223569aa9f

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

RSpec.describe CmQuiz::Review::DeleteIdea do
  describe '#perform' do
    let!(:project_api) do
      api = double
      allow(api).to receive(:request) do |verb, path, opts|
        if path == '/ideas'
          double(success?: true, body: [].to_json, code: 200)
        else
          double(success?: true, body: "", code: 200)
        end
      end
      api
    end
    let(:idea_id) { 1 }
    let(:mock_idea_payload) do
      {
        'id' => idea_id
      }
    end
    let(:service) do
      CmQuiz::Review::DeleteIdea.new({
        project_api: project_api
      })
    end
    before :each do
      user_factory = double(create: ['jwt', 'refresh_token'])
      allow(CmQuiz::Factory::User).to receive(:new).and_return(user_factory)
      idea_factory = double(create: mock_idea_payload)
      allow(CmQuiz::Factory::Idea).to receive(:new).and_return(idea_factory)
    end

    it "should pass test" do
      test_result = service.perform

      expect(test_result).to eq(["delete /ideas/:idea_id", true, nil])
      options = {
        headers: {
          'x-access-token' => 'jwt'
        }
      }
      args = [:delete, "/ideas/#{idea_id}", options]
      expect(project_api).to have_received(:request).with(*args)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cm_quiz-0.0.2 spec/lib/cm_quiz/review/delete_idea_spec.rb
cm_quiz-0.0.1 spec/lib/cm_quiz/review/delete_idea_spec.rb