From 102e0e7ed67e668ff1a72715bb981473de388348 Mon Sep 17 00:00:00 2001 From: viehlieb Date: Fri, 25 Nov 2022 13:55:21 +0100 Subject: [PATCH] wip swagger spec article_categories --- spec/requests/api/article_categories_spec.rb | 69 ++++++++++++++++---- spec/swagger_helper.rb | 20 +++--- 2 files changed, 66 insertions(+), 23 deletions(-) diff --git a/spec/requests/api/article_categories_spec.rb b/spec/requests/api/article_categories_spec.rb index cc22134c..c16a0a99 100644 --- a/spec/requests/api/article_categories_spec.rb +++ b/spec/requests/api/article_categories_spec.rb @@ -7,34 +7,79 @@ describe 'Article Categories', type: :request do get 'article categories' do tags 'Category' produces 'application/json' - parameter name: :page, in: :query, schema: { '$ref' => '#/components/schemas/page' } - parameter name: :per_page, in: :query, schema: { '$ref' => '#/components/schemas/per_page' } + parameter name: "page[number]", in: :query, type: :integer, required: false + parameter name: "page[size]", in: :query, type: :integer, required: false - let(:api_scopes) { ['orders:read'] } let!(:order_article) { create(:order, article_count: 1).order_articles.first } let!(:stock_article) { create(:stock_article) } let!(:stock_order_article) { create(:stock_order, article_ids: [stock_article.id]).order_articles.first } - response '200', 'success' do + schema type: :object, properties: { + meta: { + '$ref' => '#/components/schemas/pagination' + }, + article_categories: { + type: :array, + items: { + '$ref': '#/components/schemas/ArticleCategory' + } + } + } + + let(:page) { { number: 1, size: 20 } } + run_test! + end + + it_handles_invalid_token + end + end + + path '/article_categories/{id}' do + get 'Retrieves an article category' do + tags 'Category' + produces 'application/json' + parameter name: :id, in: :path, type: :string + + response '200', 'article category found' do schema type: :object, properties: { article_categories: { type: :array, items: { '$ref': '#/components/schemas/ArticleCategory' } - }, - meta: { - '$ref': '#/components/schemas/Meta' } } - - let(:page) { 0 } - let(:per_page) { 20 } + let(:id) { ArticleCategory.create(name: 'dairy').id } run_test! end - it_handles_invalid_token_and_scope + response '401', 'not logged in' do + schema type: :object, properties: { + article_categories: { + type: :array, + items: { + '$ref': '#/components/schemas/ArticleCategory' + } + } + } + let(:Authorization) { 'abc' } + let(:id) { ArticleCategory.create(name: 'dairy').id } + run_test! + end + + response '404', 'article category not found' do + schema type: :object, properties: { + article_categories: { + type: :array, + items: { + '$ref': '#/components/schemas/ArticleCategory' + } + } + } + let(:id) { 'invalid' } + run_test! + end end end -end +end \ No newline at end of file diff --git a/spec/swagger_helper.rb b/spec/swagger_helper.rb index b5555136..dcabf6c3 100644 --- a/spec/swagger_helper.rb +++ b/spec/swagger_helper.rb @@ -24,17 +24,15 @@ RSpec.configure do |config| paths: {}, components: { schemas: { - page: { - type: :integer, - description: 'page number', - minimum: 0, - default: 0 - }, - per_page: { - type: :integer, - description: 'items per page', - minimum: 0, - default: 20 + pagination: { + type: :object, + properties: { + recordCount: { type: :integer }, + pageCount: { type: :integer }, + currentPage: { type: :integer }, + pageSize: { type: :integer } + }, + required: %w(recordCount pageCount currentPage pageSize) }, ArticleCategory: { type: :object,