diff --git a/app/models/expense.rb b/app/models/expense.rb index 32f486f..6da98af 100644 --- a/app/models/expense.rb +++ b/app/models/expense.rb @@ -12,4 +12,11 @@ # updated_at :datetime not null # class Expense < ApplicationRecord + enum :pricing_type, + fixed: 'fixed', + per_person: 'per_person' + + validates :name, presence: true + validates :amount, presence: true, numericality: { greater_than: 0 } + validates :pricing_type, presence: true end diff --git a/spec/models/expense_spec.rb b/spec/models/expense_spec.rb index a6592fe..973ccf2 100644 --- a/spec/models/expense_spec.rb +++ b/spec/models/expense_spec.rb @@ -3,5 +3,10 @@ require 'rails_helper' RSpec.describe Expense, type: :model do - pending "add some examples to (or delete) #{__FILE__}" + describe 'validations' do + it { should validate_presence_of(:name) } + it { should validate_presence_of(:amount) } + it { should validate_numericality_of(:amount).is_greater_than(0) } + it { should validate_presence_of(:pricing_type) } + end end diff --git a/spec/requests/expenses_spec.rb b/spec/requests/expenses_spec.rb new file mode 100644 index 0000000..c96b5cf --- /dev/null +++ b/spec/requests/expenses_spec.rb @@ -0,0 +1,49 @@ +# Copyright (C) 2024 Manuel Bustillo + +require 'swagger_helper' + +RSpec.describe 'expenses', type: :request do + path '/expenses' do + get('list expenses') do + tags 'Expenses' + produces 'application/json' + response(200, 'successful') do + schema type: :array, + items: { + type: :object, + required: %i[id name amount pricing_type], + properties: { + id: { type: :string, format: :uuid }, + name: { type: :string }, + amount: { type: :number }, + pricing_type: { type: :string, enum: Expense.pricing_types.keys } + } + } + + xit + end + end + end + + path '/expenses/{id}' do + + patch('update expense') do + tags 'Expenses' + consumes 'application/json' + produces 'application/json' + parameter name: 'id', in: :path, type: :string, format: :uuid, description: 'id' + parameter name: :body, in: :body, schema: { + type: :object, + properties: { + name: { type: :string }, + amount: { type: :number, minimum: 0 }, + pricing_type: { type: :string, enum: Expense.pricing_types.keys } + } + } + + response_empty_200 + response_422 + response_404 + end + end +end diff --git a/spec/requests/guests_spec.rb b/spec/requests/guests_spec.rb index fedbce1..9a92de9 100644 --- a/spec/requests/guests_spec.rb +++ b/spec/requests/guests_spec.rb @@ -22,14 +22,7 @@ RSpec.describe 'guests', type: :request do } } } - let(:body) do - { - guest_ids: [SecureRandom.uuid, SecureRandom.uuid], - properties: { - status: 'confirmed' - } - } - end + response_empty_200 response_422 end