Sha256: 75d6a9d248573dace8223417022419e8af7f744582bb900742c5e5b9f25a5056

Contents?: true

Size: 1.8 KB

Versions: 11

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true

require "spec_helper"

module Decidim
  module Admin
    describe CreateManagedUser do
      describe "call" do
        let(:available_authorizations) { ["Decidim::DummyAuthorizationHandler"] }
        let(:organization) { create(:organization, available_authorizations: available_authorizations) }
        let(:document_number) { "12345678X" }
        let(:form_params) do
          {
            name: "Foo",
            authorization: {
              handler_name: "Decidim::DummyAuthorizationHandler",
              document_number: document_number
            }
          }
        end
        let(:form) do
          ManagedUserForm.from_params(
            form_params
          ).with_context(
            current_organization: organization
          )
        end
        let(:command) { described_class.new(form) }

        describe "when the form is not valid" do
          before do
            expect(form).to receive(:invalid?).and_return(true)
          end

          it "broadcasts invalid" do
            expect { command.call }.to broadcast(:invalid)
          end

          it "doesn't create a user" do
            expect do
              command.call
            end.not_to change { User.count }
          end
        end

        describe "when the form is valid" do
          it "broadcasts ok" do
            expect { command.call }.to broadcast(:ok)
          end

          it "creates a managed user" do
            expect do
              command.call
            end.to change { User.count }.by(1)

            user = Decidim::User.last
            expect(user).to be_managed
          end

          it "authorizes the user" do
            expect(AuthorizeUser).to receive(:call).with(form.authorization)
            command.call
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
decidim-0.6.8 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.7 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.6 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.5 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.4 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.3 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.2 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.1 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.6.0 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.5.1 decidim-admin/spec/commands/create_managed_user_spec.rb
decidim-0.5.0 decidim-admin/spec/commands/create_managed_user_spec.rb