require 'rails_helper'

describe Service do
  context "validations" do
    it "creates a Service with all fields" do
      service = build(:service)
      expect(service).to be_valid
    end

    it "does not create a Service without name" do
      service = build(:service, name: "")
      expect(service).to_not be_valid
      expect(service.errors).to include(:name)
    end

    it "does not create a Service without service_type" do
      service = build(:service, service_type: nil)
      expect(service).to_not be_valid
      expect(service.errors).to include(:service_type)
    end

    it "does not create a Service with invalid service_type" do
      expect { build(:service, service_type: :nothing) }.to raise_error(ArgumentError)
    end

    it "does not create a Service without service_price_divisor" do
      service = build(:service, service_price_divisor: nil)
      expect(service).to_not be_valid
      expect(service.errors).to include(:service_price_divisor)
    end

    it "does not create a Service with negative service_price_divisor" do
      service = build(:service, service_price_divisor: -1)
      expect(service).to_not be_valid
      expect(service.errors).to include(:service_price_divisor)
    end

    it "does not create a Service with zero service_price_divisor" do
      service = build(:service, service_price_divisor: 0)
      expect(service).to_not be_valid
      expect(service.errors).to include(:service_price_divisor)
    end

    it "does not create a Service with invalid service_price_divisor" do
      service = build(:service, service_price_divisor: 1.456)
      expect(service).to_not be_valid
      expect(service.errors).to include(:service_price_divisor)
    end

  end
end
