From be4f4d6c138f4c6c6f73d3b0a5a7f273f319485c Mon Sep 17 00:00:00 2001 From: Philipp Rothmann Date: Thu, 1 Dec 2022 18:45:18 +0100 Subject: [PATCH] add orders spec --- spec/requests/api/orders_spec.rb | 55 ++++++++++++++++++++++++++++++++ spec/swagger_helper.rb | 40 +++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 spec/requests/api/orders_spec.rb diff --git a/spec/requests/api/orders_spec.rb b/spec/requests/api/orders_spec.rb new file mode 100644 index 00000000..f6ecb0e1 --- /dev/null +++ b/spec/requests/api/orders_spec.rb @@ -0,0 +1,55 @@ +require 'swagger_helper' + +describe 'Orders', type: :request do + include ApiHelper + let(:api_scopes) { ['orders:read'] } + + path '/orders' do + get 'orders' do + tags 'Order' + produces 'application/json' + parameter name: 'page[number]', in: :query, type: :integer, required: false + parameter name: 'page[size]', in: :query, type: :integer, required: false + + let(:order) { create(:order) } + + response '200', 'success' do + schema type: :object, properties: { + meta: { + '$ref' => '#/components/schemas/Meta' + }, + ordes: { + type: :array, + items: { + '$ref': '#/components/schemas/Order' + } + } + } + + run_test! + end + + it_handles_invalid_token_and_scope + end + end + + path '/orders/{id}' do + get 'Order' do + tags 'Order' + produces 'application/json' + parameter name: 'id', in: :path, type: :integer, minimum: 1, required: true + let(:order) { create(:order) } + let(:id) { order.id } + + response '200', 'success' do + schema type: :object, properties: { + '$ref': '#/components/schemas/Order' + } + + run_test! do |response| + expect(JSON.parse(response.body)['order']['id']).to eq order.id + end + end + end + end +end diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index 2d255a91..0eeb05ac 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -34,6 +34,46 @@ RSpec.configure do |config| }, required: %w(recordCount pageCount currentPage pageSize) }, + Order: { + type: :object, + properties: { + id: { + type: :integer + }, + name: { + type: :string, + description: "name of the order's supplier (or stock)" + }, + starts: { + type: :string, + format: 'date-time', + description: 'when the order was opened' + }, + ends: { + type: ['string', 'null'], + format: 'date-time', + description: 'when the order will close or was closed' + }, + boxfill: { + type: ['string', 'null'], + format: 'date-time', + description: 'when the order will enter or entered the boxfill phase' + }, + pickup: { + type: ['string', 'null'], + format: :date, + description: 'pickup date' + }, + is_open: { + type: :boolean, + description: 'if the order is currently open or not' + }, + is_boxfill: { + type: :boolean, + description: 'if the order is currently in the boxfill phase or not' + } + } + }, Article: { type: :object, properties: {