|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'swagger_helper' |
| 4 | + |
| 5 | +RSpec.describe 'products', type: :request do # rubocop:disable RSpec/EmptyExampleGroup |
| 6 | + path '/api/products' do |
| 7 | + get('list products') do |
| 8 | + response(200, 'successful') do |
| 9 | + after do |example| |
| 10 | + example.metadata[:response][:content] = { |
| 11 | + 'application/json' => { |
| 12 | + example: JSON.parse(response.body, symbolize_names: true) |
| 13 | + } |
| 14 | + } |
| 15 | + end |
| 16 | + |
| 17 | + run_test! |
| 18 | + end |
| 19 | + end |
| 20 | + end |
| 21 | + |
| 22 | + path '/api/products/{id}' do |
| 23 | + # You'll want to customize the parameter types... |
| 24 | + parameter name: 'id', in: :path, type: :string, description: 'id' |
| 25 | + |
| 26 | + get('show product') do |
| 27 | + response(200, 'successful') do |
| 28 | + let(:id) { '123' } |
| 29 | + |
| 30 | + after do |example| |
| 31 | + example.metadata[:response][:content] = { |
| 32 | + 'application/json' => { |
| 33 | + example: JSON.parse(response.body, symbolize_names: true) |
| 34 | + } |
| 35 | + } |
| 36 | + end |
| 37 | + |
| 38 | + run_test! |
| 39 | + end |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + path '/products' do |
| 44 | + get('list products') do |
| 45 | + response(200, 'successful') do |
| 46 | + after do |example| |
| 47 | + example.metadata[:response][:content] = { |
| 48 | + 'application/json' => { |
| 49 | + example: JSON.parse(response.body, symbolize_names: true) |
| 50 | + } |
| 51 | + } |
| 52 | + end |
| 53 | + |
| 54 | + run_test! |
| 55 | + end |
| 56 | + end |
| 57 | + |
| 58 | + post('create product') do |
| 59 | + response(200, 'successful') do |
| 60 | + after do |example| |
| 61 | + example.metadata[:response][:content] = { |
| 62 | + 'application/json' => { |
| 63 | + example: JSON.parse(response.body, symbolize_names: true) |
| 64 | + } |
| 65 | + } |
| 66 | + end |
| 67 | + |
| 68 | + run_test! |
| 69 | + end |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + path '/products/new' do |
| 74 | + get('new product') do |
| 75 | + response(200, 'successful') do |
| 76 | + after do |example| |
| 77 | + example.metadata[:response][:content] = { |
| 78 | + 'application/json' => { |
| 79 | + example: JSON.parse(response.body, symbolize_names: true) |
| 80 | + } |
| 81 | + } |
| 82 | + end |
| 83 | + |
| 84 | + run_test! |
| 85 | + end |
| 86 | + end |
| 87 | + end |
| 88 | + |
| 89 | + path '/products/{id}/edit' do |
| 90 | + # You'll want to customize the parameter types... |
| 91 | + parameter name: 'id', in: :path, type: :string, description: 'id' |
| 92 | + |
| 93 | + get('edit product') do |
| 94 | + response(200, 'successful') do |
| 95 | + let(:id) { '123' } |
| 96 | + |
| 97 | + after do |example| |
| 98 | + example.metadata[:response][:content] = { |
| 99 | + 'application/json' => { |
| 100 | + example: JSON.parse(response.body, symbolize_names: true) |
| 101 | + } |
| 102 | + } |
| 103 | + end |
| 104 | + |
| 105 | + run_test! |
| 106 | + end |
| 107 | + end |
| 108 | + end |
| 109 | + |
| 110 | + path '/products/{id}' do |
| 111 | + # You'll want to customize the parameter types... |
| 112 | + parameter name: 'id', in: :path, type: :string, description: 'id' |
| 113 | + |
| 114 | + get('show product') do |
| 115 | + response(200, 'successful') do |
| 116 | + let(:id) { '123' } |
| 117 | + |
| 118 | + after do |example| |
| 119 | + example.metadata[:response][:content] = { |
| 120 | + 'application/json' => { |
| 121 | + example: JSON.parse(response.body, symbolize_names: true) |
| 122 | + } |
| 123 | + } |
| 124 | + end |
| 125 | + |
| 126 | + run_test! |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + patch('update product') do |
| 131 | + response(200, 'successful') do |
| 132 | + let(:id) { '123' } |
| 133 | + |
| 134 | + after do |example| |
| 135 | + example.metadata[:response][:content] = { |
| 136 | + 'application/json' => { |
| 137 | + example: JSON.parse(response.body, symbolize_names: true) |
| 138 | + } |
| 139 | + } |
| 140 | + end |
| 141 | + |
| 142 | + run_test! |
| 143 | + end |
| 144 | + end |
| 145 | + |
| 146 | + put('update product') do |
| 147 | + response(200, 'successful') do |
| 148 | + let(:id) { '123' } |
| 149 | + |
| 150 | + after do |example| |
| 151 | + example.metadata[:response][:content] = { |
| 152 | + 'application/json' => { |
| 153 | + example: JSON.parse(response.body, symbolize_names: true) |
| 154 | + } |
| 155 | + } |
| 156 | + end |
| 157 | + |
| 158 | + run_test! |
| 159 | + end |
| 160 | + end |
| 161 | + |
| 162 | + delete('delete product') do |
| 163 | + response(200, 'successful') do |
| 164 | + let(:id) { '123' } |
| 165 | + |
| 166 | + after do |example| |
| 167 | + example.metadata[:response][:content] = { |
| 168 | + 'application/json' => { |
| 169 | + example: JSON.parse(response.body, symbolize_names: true) |
| 170 | + } |
| 171 | + } |
| 172 | + end |
| 173 | + |
| 174 | + run_test! |
| 175 | + end |
| 176 | + end |
| 177 | + end |
| 178 | +end |
0 commit comments