Merge pull request 'Document expenses endpoint and add some specs' (#132) from document-expenses-controller into main
Reviewed-on: #132
This commit is contained in:
commit
17c796c375
@ -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
|
||||
|
@ -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
|
||||
|
49
spec/requests/expenses_spec.rb
Normal file
49
spec/requests/expenses_spec.rb
Normal file
@ -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
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user