The personal finance app for everyone (by everyone)
Ruby
Fix the rswag request specs and run them in CI (#5430)
David Gilf5865a9702db
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 51abaa0464..90d4308bd9 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -221,6 +221,58 @@ jobs:echo "Unit test shards: ${RESULT}"[ "$RESULT" = "success" ]+ # The rswag specs generate docs/api/openapi.yaml. Running them checks that+ # every documented request still gets the documented response.+ test_api_docs:+ runs-on: ubuntu-24.04+ timeout-minutes: 10++ env:+ PLAID_CLIENT_ID: foo+ PLAID_SECRET: bar+ DATABASE_URL: postgres://postgres:postgres@localhost:5432 # pipelock:ignore+ REDIS_URL: redis://localhost:6379+ RAILS_ENV: test++ services:+ postgres:+ image: postgres+ env:+ POSTGRES_USER: postgres+ POSTGRES_PASSWORD: postgres+ ports:+ - 5432:5432+ options: --health-cmd="pg_isready" --health-interval=10s --health-timeout=5s --health-retries=3++ redis:+ image: redis+ ports:+ - 6379:6379+ options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3++ steps:+ - name: Install packages+ run: sudo apt-get update && sudo apt-get install --no-install-recommends -y curl libvips postgresql-client libpq-dev++ - name: Checkout code+ uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1+ with:+ persist-credentials: false++ - name: Set up Ruby+ uses: ruby/setup-ruby@f9c4492e86def3e644ab32a0ef185eda5b0c20d0 # v1.342.0+ with:+ ruby-version: .ruby-version+ bundler-cache: true++ - name: DB setup+ run: |+ bin/rails db:create+ bin/rails db:schema:load++ - name: API documentation specs+ run: bundle exec rspec+# System tests run serially (they flake when parallel workers compete for# the runner's CPUs), so they are split by file across several runners.test_system_shard:diff --git a/app/controllers/api/v1/family_exports_controller.rb b/app/controllers/api/v1/family_exports_controller.rbindex 1647570e01..8b64e30746 100644--- a/app/controllers/api/v1/family_exports_controller.rb+++ b/app/controllers/api/v1/family_exports_controller.rb@@ -4,6 +4,8 @@ class Api::V1::FamilyExportsController < Api::V1::BaseControllerinclude Pagy::Backendinclude ActiveStorage::Streaming+ wrap_parameters false+before_action :ensure_read_scope, only: [ :index, :show, :download ]before_action :ensure_write_scope, only: [ :create ]before_action :ensure_admindiff --git a/docs/api/openapi.yaml b/docs/api/openapi.yamlindex 0db682519a..3008ed19c1 100644--- a/docs/api/openapi.yaml+++ b/docs/api/openapi.yaml@@ -5290,7 +5290,16 @@ paths:content:application/json:schema:- "$ref": "#/components/schemas/ErrorResponse"+ oneOf:+ - type: object+ required:+ - errors+ properties:+ errors:+ type: array+ items:+ type: string+ - "$ref": "#/components/schemas/ErrorResponse"'403':description: 'registration refused: the instance is closed to new registrations,or an invite code is required or invalid'diff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex 96000b7bca..a34151a49f 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -35,10 +35,12 @@ rescue ActiveRecord::PendingMigrationError => eabort e.to_s.stripendRSpec.configure do |config|- # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures+ # Same fixtures as the Minitest suite; some docs specs use them.config.fixture_paths = [- Rails.root.join('spec/fixtures')+ Rails.root.join('test/fixtures')]+ config.file_fixture_path = Rails.root.join('test/fixtures/files')+ config.global_fixtures = :all# If you're not using ActiveRecord, or you'd prefer not to run each of your# examples within a transaction, remove the following line or assign falsediff --git a/spec/requests/api/v1/accounts_spec.rb b/spec/requests/api/v1/accounts_spec.rbindex 91686840bd..24dea20ac4 100644--- a/spec/requests/api/v1/accounts_spec.rb+++ b/spec/requests/api/v1/accounts_spec.rb@@ -39,6 +39,7 @@ RSpec.describe 'API V1 Accounts', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: %w[write],source: 'web').tap { |api_key| api_key.save!(validate: false) }@@ -49,6 +50,7 @@ RSpec.describe 'API V1 Accounts', type: :request dolet!(:checking_account) doAccount.create!(family: family,+ owner: user,name: 'Checking Account',balance: 1500.50,currency: 'USD',@@ -59,6 +61,7 @@ RSpec.describe 'API V1 Accounts', type: :request dolet!(:savings_account) doAccount.create!(family: family,+ owner: user,name: 'Savings Account',balance: 10000.00,currency: 'USD',@@ -69,6 +72,7 @@ RSpec.describe 'API V1 Accounts', type: :request dolet!(:credit_card) doAccount.create!(family: family,+ owner: user,name: 'Credit Card',balance: -500.00,currency: 'USD',diff --git a/spec/requests/api/v1/auth_spec.rb b/spec/requests/api/v1/auth_spec.rbindex ddb696bbb4..14a2d00ecb 100644--- a/spec/requests/api/v1/auth_spec.rb+++ b/spec/requests/api/v1/auth_spec.rb@@ -3,6 +3,59 @@require 'swagger_helper'RSpec.describe 'API V1 Auth', type: :request do+ let(:password) { 'Docs-Pass1!' }+ let(:device) do+ {+ device_id: 'rswag-docs-device',+ device_name: 'Docs iPhone',+ device_type: 'ios',+ os_version: '17.0',+ app_version: '1.0.0'+ }+ end+ let(:family) { Family.create!(name: 'Auth Docs Family', currency: 'USD', locale: 'en', date_format: '%m-%d-%Y') }+ let(:user) do+ family.users.create!(+ email: '[email protected]',+ password: password,+ password_confirmation: password,+ first_name: 'Auth',+ last_name: 'Docs',+ role: 'admin'+ )+ end+ let(:linking_code) { 'rswag-linking-code' }++ # Linking and exchange codes live in Rails.cache, which is a null store in tests.+ around do |example|+ original_cache = Rails.cache+ Rails.cache = ActiveSupport::Cache::MemoryStore.new+ example.run+ ensure+ Rails.cache = original_cache+ end++ # The memoized mobile OAuth application would point at a row rolled back by an earlier example.+ before { MobileDevice.instance_variable_set(:@shared_oauth_application, nil) }++ def write_linking_code(**attributes)+ Rails.cache.write("mobile_sso_link:#{linking_code}", {+ provider: 'google_oauth2',+ uid: 'rswag-google-uid',+ email: '[email protected]',+ first_name: 'Sso',+ last_name: 'Docs',+ name: 'Sso Docs',+ device_info: device.stringify_keys,+ allow_account_creation: true+ }.merge(attributes))+ end++ def api_key_with_scope(scope)+ key = ApiKey.generate_secure_key+ ApiKey.create!(user: user, name: "API Docs Key (#{scope})", key: key, scopes: [ scope ], source: 'web')+ end+path '/api/v1/auth/signup' dopost 'Sign up a new user' dotags 'Auth'@@ -59,16 +112,34 @@ RSpec.describe 'API V1 Auth', type: :request do}}}++ let(:body) { { user: { email: '[email protected]', password: password, first_name: 'Docs', last_name: 'User' }, device: device } }+run_test!endresponse '422', 'validation error' do- schema '$ref' => '#/components/schemas/ErrorResponse'+ schema oneOf: [+ {+ type: :object,+ required: %w[errors],+ properties: { errors: { type: :array, items: { type: :string } } }+ },+ { '$ref' => '#/components/schemas/ErrorResponse' }+ ]++ let(:body) { { user: { email: '[email protected]', password: 'short' }, device: device } }+run_test!endresponse '403', 'registration refused: the instance is closed to new registrations, or an invite code is required or invalid' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:body) { { user: { email: '[email protected]', password: password }, device: device } }++ before { allow(Setting).to receive(:onboarding_state).and_return('closed') }+run_test!end@@ -125,6 +196,9 @@ RSpec.describe 'API V1 Auth', type: :request do}}}++ let(:body) { { email: user.email, password: password, device: device } }+run_test!end@@ -135,6 +209,14 @@ RSpec.describe 'API V1 Auth', type: :request doresponse '403', 'local login is disabled: the instance is SSO-only, and this account is not a super admin using the emergency override' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:body) { { email: user.email, password: password, device: device } }++ before do+ allow(AuthConfig).to receive(:local_login_enabled?).and_return(false)+ allow(AuthConfig).to receive(:local_admin_override_enabled?).and_return(false)+ end+run_test!endend@@ -202,11 +284,33 @@ RSpec.describe 'API V1 Auth', type: :request do}}}++ let(:body) { { code: 'rswag-sso-code' } }++ before do+ Rails.cache.write('mobile_sso:rswag-sso-code', {+ access_token: 'rswag-access-token',+ refresh_token: 'rswag-refresh-token',+ token_type: 'Bearer',+ expires_in: 30.days.to_i,+ created_at: Time.current.to_i,+ user_id: user.id,+ user_email: user.email,+ user_first_name: user.first_name,+ user_last_name: user.last_name,+ user_ui_layout: user.ui_layout,+ user_ai_enabled: user.ai_enabled?+ })+ end+run_test!endresponse '401', 'invalid or expired code' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:body) { { code: 'rswag-expired-code' } }+run_test!endend@@ -241,11 +345,20 @@ RSpec.describe 'API V1 Auth', type: :request doexpires_in: { type: :integer },created_at: { type: :integer }}++ let(:body) do+ tokens = MobileDevice.upsert_device!(user, device).issue_token!+ { refresh_token: tokens[:refresh_token], device: { device_id: device[:device_id] } }+ end+run_test!endresponse '401', 'invalid or revoked refresh token, or account deactivated' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:body) { { refresh_token: 'rswag-revoked-token', device: { device_id: device[:device_id] } } }+run_test!end@@ -292,6 +405,11 @@ RSpec.describe 'API V1 Auth', type: :request do}}}++ let(:body) { { linking_code: linking_code, email: user.email, password: password } }++ before { write_linking_code }+run_test!end@@ -305,6 +423,9 @@ RSpec.describe 'API V1 Auth', type: :request do{ '$ref' => '#/components/schemas/ErrorResponse' },{ '$ref' => '#/components/schemas/MfaRequiredResponse' }]++ let(:body) { { linking_code: 'rswag-expired-link', email: user.email, password: password } }+run_test!end@@ -321,14 +442,6 @@ RSpec.describe 'API V1 Auth', type: :request do}end- around do |example|- original_cache = Rails.cache- Rails.cache = ActiveSupport::Cache::MemoryStore.new- example.run- ensure- Rails.cache = original_cache- end-before doRails.cache.write("mobile_sso_link:#{linking_code}", {provider: 'openid_connect',@@ -385,6 +498,11 @@ RSpec.describe 'API V1 Auth', type: :request do}}}++ let(:body) { { linking_code: linking_code, first_name: 'Sso', last_name: 'Docs' } }++ before { write_linking_code }+run_test!end@@ -395,11 +513,19 @@ RSpec.describe 'API V1 Auth', type: :request doresponse '401', 'invalid or expired linking code' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:body) { { linking_code: 'rswag-expired-link' } }+run_test!endresponse '403', 'SSO identity removed or account creation disabled' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:body) { { linking_code: linking_code } }++ before { write_linking_code(allow_account_creation: false) }+run_test!end@@ -411,6 +537,11 @@ RSpec.describe 'API V1 Auth', type: :request doitems: { type: :string }}}++ let(:body) { { linking_code: linking_code } }++ before { write_linking_code(email: user.email) }+run_test!endend@@ -438,16 +569,25 @@ RSpec.describe 'API V1 Auth', type: :request do}}}++ let(:'X-Api-Key') { api_key_with_scope('read_write').plain_key }+run_test!endresponse '401', 'unauthorized' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:'X-Api-Key') { nil }+run_test!endresponse '403', 'insufficient scope' doschema '$ref' => '#/components/schemas/ErrorResponse'++ let(:'X-Api-Key') { api_key_with_scope('read').plain_key }+run_test!endenddiff --git a/spec/requests/api/v1/balances_spec.rb b/spec/requests/api/v1/balances_spec.rbindex 641b76a5b2..38499711e3 100644--- a/spec/requests/api/v1/balances_spec.rb+++ b/spec/requests/api/v1/balances_spec.rb@@ -37,6 +37,7 @@ RSpec.describe 'API V1 Balances', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: %w[write],source: 'web').tap { |api_key| api_key.save!(validate: false) }@@ -47,6 +48,7 @@ RSpec.describe 'API V1 Balances', type: :request dolet!(:account) doAccount.create!(family: family,+ owner: user,name: 'Checking Account',balance: 1500.50,currency: 'USD',diff --git a/spec/requests/api/v1/cash_flow_spec.rb b/spec/requests/api/v1/cash_flow_spec.rbindex e76213bf43..85667790de 100644--- a/spec/requests/api/v1/cash_flow_spec.rb+++ b/spec/requests/api/v1/cash_flow_spec.rb@@ -38,7 +38,8 @@ RSpec.describe 'API V1 Cash Flow', type: :request dotags 'Cash Flow'description 'Server-calculated income, spending, savings, and daily cumulative comparison in family currency. Uses the authenticated user’s finance accounts and Sure reporting rules. Browser sessions do not authenticate this public API.'parameter name: :month, in: :query, required: false, schema: { type: :string, format: :date }, description: 'Non-future first day YYYY-MM-01; defaults to the current month in the family time zone.'- parameter name: :include, in: :query, required: false, schema: { type: :string, enum: [ 'sankey' ] }, description: 'Append server-calculated graph to the monthly summary; cannot combine with view.'+ # Read through include_param: `include` is RSpec's include matcher.+ parameter name: :include, getter: :include_param, in: :query, required: false, schema: { type: :string, enum: [ 'sankey' ] }, description: 'Append server-calculated graph to the monthly summary; cannot combine with view.'parameter name: :view, in: :query, required: false, schema: { type: :string, enum: [ 'sankey' ] }, description: 'Graph-only envelope; omits daily comparison. Accepts month or an explicit date range; cannot combine with include.'parameter name: :group_by, in: :query, required: false, schema: { type: :string, enum: %w[category account], default: 'category' }, description: 'Requires view=sankey. category: flows through one Cash Flow node; account: income categories flow through each account to expense categories (basis net_by_account).'parameter name: :start_date, in: :query, required: false, schema: { type: :string, format: :date }, description: 'Inclusive ISO date. Requires end_date and view=sankey; cannot combine with month.'diff --git a/spec/requests/api/v1/family_exports_spec.rb b/spec/requests/api/v1/family_exports_spec.rbindex f9101f002e..a2e6e18727 100644--- a/spec/requests/api/v1/family_exports_spec.rb+++ b/spec/requests/api/v1/family_exports_spec.rb@@ -55,8 +55,6 @@ RSpec.describe "Api::V1::FamilyExports", type: :request dodescription: "Family export creation does not accept request parameters."}- let(:body) { {} }-response "202", "family export queued" doschema "$ref" => "#/components/schemas/FamilyExportResponse"run_test!diff --git a/spec/requests/api/v1/financekit_spec.rb b/spec/requests/api/v1/financekit_spec.rbindex 5cc810bce8..63fe163b2c 100644--- a/spec/requests/api/v1/financekit_spec.rb+++ b/spec/requests/api/v1/financekit_spec.rb@@ -37,7 +37,6 @@ RSpec.describe "Api::V1::Financekit", type: :request dolet(:per_page) { nil }before do- allow(Financekit).to receive(:enabled?).and_return(true)allow(ApiRateLimiter).to receive(:limit).and_return(nil)enddiff --git a/spec/requests/api/v1/holdings_spec.rb b/spec/requests/api/v1/holdings_spec.rbindex 27d7ac4f36..f1c1bc8c74 100644--- a/spec/requests/api/v1/holdings_spec.rb+++ b/spec/requests/api/v1/holdings_spec.rb@@ -36,6 +36,7 @@ RSpec.describe 'API V1 Holdings', type: :request dolet(:account) doAccount.create!(family: family,+ owner: user,name: 'Investment Account',balance: 50_000,currency: 'USD',diff --git a/spec/requests/api/v1/import_sessions_spec.rb b/spec/requests/api/v1/import_sessions_spec.rbindex 96ff3e95a0..2191a813d8 100644--- a/spec/requests/api/v1/import_sessions_spec.rb+++ b/spec/requests/api/v1/import_sessions_spec.rb@@ -6,9 +6,25 @@ RSpec.describe 'API V1 Import Sessions', type: :request dolet(:user) { users(:empty) }let(:family) { user.family }- let(:api_key) { api_keys(:active_key) }- let(:api_key_without_write_scope) { api_keys(:one) }- let(:api_key_without_read_scope) { api_keys(:expired_key) }+ 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(:api_key_without_write_scope) do+ key = ApiKey.generate_secure_key+ ApiKey.create!(user: user, name: 'Read Only Docs Key', key: key, scopes: %w[read], source: 'web')+ end+ let(:api_key_without_read_scope) do+ key = ApiKey.generate_secure_key+ ApiKey.new(+ user: user,+ name: 'No Read Docs Key',+ key: key,+ display_key: key,+ scopes: %w[write],+ source: 'web'+ ).tap { |api_key| api_key.save!(validate: false) }+ endlet(:'X-Api-Key') { api_key.plain_key }@@ -372,7 +388,8 @@ RSpec.describe 'API V1 Import Sessions', type: :request dofilename: 'entities.ndjson',content_type: 'application/x-ndjson')- import_session.imports.update_all(rows_count: SureImport.max_row_count + 1)+ # Publish recounts rows from the uploaded chunks, so lower the limit instead.+ allow(SureImport).to receive(:max_row_count).and_return(0)endrun_test!diff --git a/spec/requests/api/v1/imports_spec.rb b/spec/requests/api/v1/imports_spec.rbindex d9a331df41..1d3982b749 100644--- a/spec/requests/api/v1/imports_spec.rb+++ b/spec/requests/api/v1/imports_spec.rb@@ -37,6 +37,7 @@ RSpec.describe 'API V1 Imports', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: %w[write],source: 'web').tap { |api_key| api_key.save!(validate: false) }diff --git a/spec/requests/api/v1/merchants_spec.rb b/spec/requests/api/v1/merchants_spec.rbindex f9ca005133..30f383ca8a 100644--- a/spec/requests/api/v1/merchants_spec.rb+++ b/spec/requests/api/v1/merchants_spec.rb@@ -64,18 +64,18 @@ RSpec.describe 'API V1 Merchants', type: :request do}}+ 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+response '201', 'merchants imported' doschema '$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@@ -96,9 +96,6 @@ RSpec.describe 'API V1 Merchants', type: :request dorole: 'guest')end- let(:file) do- Rack::Test::UploadedFile.new(StringIO.new("name\nCoffee Shop"), 'text/csv', true, original_filename: 'merchants.csv')- endrun_test!enddiff --git a/spec/requests/api/v1/provider_connections_spec.rb b/spec/requests/api/v1/provider_connections_spec.rbindex ec52f96199..7da7164d39 100644--- a/spec/requests/api/v1/provider_connections_spec.rb+++ b/spec/requests/api/v1/provider_connections_spec.rb@@ -20,6 +20,7 @@ RSpec.describe "Api::V1::ProviderConnections", type: :request douser: user,name: "API Docs Write Key",key: key,+ display_key: key,scopes: %w[write],source: "web").tap { |api_key| api_key.save!(validate: false) }diff --git a/spec/requests/api/v1/rejected_transfers_spec.rb b/spec/requests/api/v1/rejected_transfers_spec.rbindex 91580a42b5..34018cca0d 100644--- a/spec/requests/api/v1/rejected_transfers_spec.rb+++ b/spec/requests/api/v1/rejected_transfers_spec.rb@@ -37,14 +37,15 @@ RSpec.describe 'API V1 Rejected Transfers', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: [],source: 'mobile').tap { |api_key| api_key.save!(validate: false) }endlet(:'X-Api-Key') { api_key.plain_key }- let(:checking) { family.accounts.create!(name: 'Checking', balance: 1000, currency: 'USD', accountable: Depository.create!) }- let(:savings) { family.accounts.create!(name: 'Savings', balance: 2500, currency: 'USD', accountable: Depository.create!) }+ let(:checking) { family.accounts.create!(owner: user, name: 'Checking', balance: 1000, currency: 'USD', accountable: Depository.create!) }+ let(:savings) { family.accounts.create!(owner: user, name: 'Savings', balance: 2500, currency: 'USD', accountable: Depository.create!) }let!(:outflow_entry) dochecking.entries.create!(date: Date.current,diff --git a/spec/requests/api/v1/rule_runs_spec.rb b/spec/requests/api/v1/rule_runs_spec.rbindex 84044e7027..9b43391ec5 100644--- a/spec/requests/api/v1/rule_runs_spec.rb+++ b/spec/requests/api/v1/rule_runs_spec.rb@@ -39,6 +39,7 @@ RSpec.describe 'API V1 Rule Runs', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: [],display_key: key,source: 'mobile'diff --git a/spec/requests/api/v1/rules_spec.rb b/spec/requests/api/v1/rules_spec.rbindex 0bf8e5bced..8833b6f2fb 100644--- a/spec/requests/api/v1/rules_spec.rb+++ b/spec/requests/api/v1/rules_spec.rb@@ -39,6 +39,7 @@ RSpec.describe 'API V1 Rules', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: [],display_key: key,source: 'mobile'diff --git a/spec/requests/api/v1/securities_spec.rb b/spec/requests/api/v1/securities_spec.rbindex b250ece3c5..c8d7a57300 100644--- a/spec/requests/api/v1/securities_spec.rb+++ b/spec/requests/api/v1/securities_spec.rb@@ -50,6 +50,7 @@ RSpec.describe 'API V1 Securities', type: :request dolet(:account) doAccount.create!(family: family,+ owner: user,name: 'Investment Account',balance: 50_000,currency: 'USD',diff --git a/spec/requests/api/v1/splits_spec.rb b/spec/requests/api/v1/splits_spec.rbindex 3921657644..e97d47e644 100644--- a/spec/requests/api/v1/splits_spec.rb+++ b/spec/requests/api/v1/splits_spec.rb@@ -39,6 +39,7 @@ RSpec.describe 'API V1 Transaction Split', type: :request dolet(:account) doAccount.create!(family: family,+ owner: user,name: 'Checking Account',balance: 1000,currency: 'USD',diff --git a/spec/requests/api/v1/transactions_spec.rb b/spec/requests/api/v1/transactions_spec.rbindex 48a8bbb99c..89aa310de1 100644--- a/spec/requests/api/v1/transactions_spec.rb+++ b/spec/requests/api/v1/transactions_spec.rb@@ -56,6 +56,7 @@ RSpec.describe 'API V1 Transactions', type: :request dolet(:account) doAccount.create!(family: family,+ owner: user,name: 'Checking Account',balance: 1000,currency: 'USD',diff --git a/spec/requests/api/v1/transfers_spec.rb b/spec/requests/api/v1/transfers_spec.rbindex 0afcfe70e1..b9ec636b5b 100644--- a/spec/requests/api/v1/transfers_spec.rb+++ b/spec/requests/api/v1/transfers_spec.rb@@ -37,14 +37,15 @@ RSpec.describe 'API V1 Transfers', type: :request douser: user,name: 'No Read Docs Key',key: key,+ display_key: key,scopes: [],source: 'mobile').tap { |api_key| api_key.save!(validate: false) }endlet(:'X-Api-Key') { api_key.plain_key }- let(:checking) { family.accounts.create!(name: 'Checking', balance: 1000, currency: 'USD', accountable: Depository.create!) }- let(:savings) { family.accounts.create!(name: 'Savings', balance: 2500, currency: 'USD', accountable: Depository.create!) }+ let(:checking) { family.accounts.create!(owner: user, name: 'Checking', balance: 1000, currency: 'USD', accountable: Depository.create!) }+ let(:savings) { family.accounts.create!(owner: user, name: 'Savings', balance: 2500, currency: 'USD', accountable: Depository.create!) }let!(:outflow_entry) dochecking.entries.create!(date: Date.current,diff --git a/test/controllers/api/v1/family_exports_controller_test.rb b/test/controllers/api/v1/family_exports_controller_test.rbindex e269a71096..4a0bc41a08 100644--- a/test/controllers/api/v1/family_exports_controller_test.rb+++ b/test/controllers/api/v1/family_exports_controller_test.rb@@ -92,6 +92,16 @@ class Api::V1::FamilyExportsControllerTest < ActionDispatch::IntegrationTestassert_equal @family.id, export.family_idend+ test "creates a family export from an empty JSON request" do+ [ "", "{}" ].each do |body|+ assert_difference("@family.family_exports.count") do+ post api_v1_family_exports_url, params: body, headers: api_headers(@api_key).merge("Content-Type" => "application/json")+ end++ assert_response :accepted+ end+ end+test "read-only key cannot create a family export" doassert_no_difference("@family.family_exports.count") dopost api_v1_family_exports_url, headers: api_headers(@read_only_api_key)@@ -112,6 +122,17 @@ class Api::V1::FamilyExportsControllerTest < ActionDispatch::IntegrationTestassert_equal "invalid_params", JSON.parse(response.body)["error"]end+ test "create rejects unsupported params in a JSON body" do+ [ { status: "completed" }, { family_export: { status: "completed" } }, { unknown: "value" } ].each do |payload|+ assert_no_difference("@family.family_exports.count") do+ post api_v1_family_exports_url, params: payload, headers: api_headers(@api_key), as: :json+ end++ assert_response :unprocessable_entity+ assert_equal "invalid_params", JSON.parse(response.body)["error"]+ end+ end+test "non-admin cannot access family exports" doget api_v1_family_exports_url, headers: api_headers(@member_api_key)assert_response :forbidden