mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 14:51:15 +00:00
* docs(api): sync openapi.yaml with merchants import and transfer fee fields Regenerate the OpenAPI document from the request specs already on main (bundle exec rake rswag:specs:swaggerize). Purely additive: documents the POST /api/v1/merchants CSV import endpoint, the MerchantImportResult schema, and the transfer source/destination fee fields that were intentionally left out of #2823. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(docs): describe merchants CSV multipart body as an object schema type: file is a Swagger 2 idiom that is invalid under OpenAPI 3.0.3; declare the multipart part as an object with a required binary file property (matching params[:file]) and regenerate the document. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
122 lines
3.0 KiB
Ruby
122 lines
3.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'swagger_helper'
|
|
|
|
RSpec.describe 'API V1 Merchants', type: :request do
|
|
let(:family) do
|
|
Family.create!(
|
|
name: 'API Family',
|
|
currency: 'USD',
|
|
locale: 'en',
|
|
date_format: '%m-%d-%Y'
|
|
)
|
|
end
|
|
|
|
let(:user) do
|
|
family.users.create!(
|
|
email: 'api-user@example.com',
|
|
password: 'password123',
|
|
password_confirmation: 'password123'
|
|
)
|
|
end
|
|
|
|
let(:api_key) do
|
|
key = ApiKey.generate_secure_key
|
|
ApiKey.create!(
|
|
user: user,
|
|
name: 'API Docs Key',
|
|
key: key,
|
|
scopes: %w[read_write],
|
|
source: 'web'
|
|
)
|
|
end
|
|
|
|
let(:'X-Api-Key') { api_key.plain_key }
|
|
|
|
let!(:family_merchant) { family.merchants.create!(name: 'Coffee Shop') }
|
|
|
|
path '/api/v1/merchants' do
|
|
get 'List merchants' do
|
|
tags 'Merchants'
|
|
security [ { apiKeyAuth: [] } ]
|
|
produces 'application/json'
|
|
|
|
response '200', 'merchants listed' do
|
|
schema type: :array, items: { '$ref' => '#/components/schemas/MerchantDetail' }
|
|
|
|
run_test!
|
|
end
|
|
end
|
|
|
|
post 'Import merchants from CSV' do
|
|
tags 'Merchants'
|
|
security [ { apiKeyAuth: [] } ]
|
|
consumes 'multipart/form-data'
|
|
produces 'application/json'
|
|
|
|
parameter name: :file, in: :formData, required: true,
|
|
description: 'CSV file with columns: name* (required), color, website_url',
|
|
schema: {
|
|
type: :object,
|
|
required: [ 'file' ],
|
|
properties: {
|
|
file: { type: :string, format: :binary }
|
|
}
|
|
}
|
|
|
|
response '201', 'merchants imported' do
|
|
schema '$ref' => '#/components/schemas/MerchantImportResult'
|
|
|
|
let(:file) do
|
|
Rack::Test::UploadedFile.new(
|
|
StringIO.new("name,color,website_url\nCoffee Shop,#e99537,https://coffeeshop.com"),
|
|
'text/csv',
|
|
true,
|
|
original_filename: 'merchants.csv'
|
|
)
|
|
end
|
|
|
|
run_test!
|
|
end
|
|
|
|
response '401', 'unauthorized' do
|
|
schema '$ref' => '#/components/schemas/ErrorResponse'
|
|
let(:'X-Api-Key') { nil }
|
|
run_test!
|
|
end
|
|
|
|
response '422', 'missing file or invalid CSV' do
|
|
schema '$ref' => '#/components/schemas/ErrorResponse'
|
|
let(:file) { nil }
|
|
run_test!
|
|
end
|
|
end
|
|
end
|
|
|
|
path '/api/v1/merchants/{id}' do
|
|
parameter name: :id, in: :path, type: :string, required: true, description: 'Merchant ID'
|
|
|
|
get 'Retrieve a merchant' do
|
|
tags 'Merchants'
|
|
security [ { apiKeyAuth: [] } ]
|
|
produces 'application/json'
|
|
|
|
response '200', 'merchant retrieved' do
|
|
schema '$ref' => '#/components/schemas/MerchantDetail'
|
|
|
|
let(:id) { family_merchant.id }
|
|
|
|
run_test!
|
|
end
|
|
|
|
response '404', 'merchant not found' do
|
|
schema '$ref' => '#/components/schemas/ErrorResponse'
|
|
|
|
let(:id) { SecureRandom.uuid }
|
|
|
|
run_test!
|
|
end
|
|
end
|
|
end
|
|
end
|