Merge pull request 'Document expenses endpoint and add some specs' (#132) from document-expenses-controller into main
Some checks failed
Check usage of free licenses / check-licenses (push) Successful in 2m28s
Run unit tests / unit_tests (push) Successful in 6m46s
Build Nginx-based docker image / build-static-assets (push) Failing after 19m30s

Reviewed-on: #132
This commit is contained in:
bustikiller 2024-11-16 09:32:36 +00:00
commit 17c796c375
4 changed files with 63 additions and 9 deletions

View File

@ -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

View File

@ -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

View 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

View File

@ -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