Skip to content

armgit / sure

Public Imported from GitHub
0

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.yml
index 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.rb
index 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::BaseController
include Pagy::Backend
include ActiveStorage::Streaming
+ wrap_parameters false
+
before_action :ensure_read_scope, only: [ :index, :show, :download ]
before_action :ensure_write_scope, only: [ :create ]
before_action :ensure_admin
diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml
index 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.rb
index 96000b7bca..a34151a49f 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -35,10 +35,12 @@ rescue ActiveRecord::PendingMigrationError => e
abort e.to_s.strip
end
RSpec.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 false
diff --git a/spec/requests/api/v1/accounts_spec.rb b/spec/requests/api/v1/accounts_spec.rb
index 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 do
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) }
@@ -49,6 +50,7 @@ RSpec.describe 'API V1 Accounts', type: :request do
let!(:checking_account) do
Account.create!(
family: family,
+ owner: user,
name: 'Checking Account',
balance: 1500.50,
currency: 'USD',
@@ -59,6 +61,7 @@ RSpec.describe 'API V1 Accounts', type: :request do
let!(:savings_account) do
Account.create!(
family: family,
+ owner: user,
name: 'Savings Account',
balance: 10000.00,
currency: 'USD',
@@ -69,6 +72,7 @@ RSpec.describe 'API V1 Accounts', type: :request do
let!(:credit_card) do
Account.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.rb
index 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' do
post 'Sign up a new user' do
tags '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!
end
response '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!
end
response '403', 'registration refused: the instance is closed to new registrations, or an invite code is required or invalid' do
schema '$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 do
response '403', 'local login is disabled: the instance is SSO-only, and this account is not a super admin using the emergency override' do
schema '$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!
end
end
@@ -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!
end
response '401', 'invalid or expired code' do
schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ let(:body) { { code: 'rswag-expired-code' } }
+
run_test!
end
end
@@ -241,11 +345,20 @@ RSpec.describe 'API V1 Auth', type: :request do
expires_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!
end
response '401', 'invalid or revoked refresh token, or account deactivated' do
schema '$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 do
Rails.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 do
response '401', 'invalid or expired linking code' do
schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ let(:body) { { linking_code: 'rswag-expired-link' } }
+
run_test!
end
response '403', 'SSO identity removed or account creation disabled' do
schema '$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 do
items: { type: :string }
}
}
+
+ let(:body) { { linking_code: linking_code } }
+
+ before { write_linking_code(email: user.email) }
+
run_test!
end
end
@@ -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!
end
response '401', 'unauthorized' do
schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ let(:'X-Api-Key') { nil }
+
run_test!
end
response '403', 'insufficient scope' do
schema '$ref' => '#/components/schemas/ErrorResponse'
+
+ let(:'X-Api-Key') { api_key_with_scope('read').plain_key }
+
run_test!
end
end
diff --git a/spec/requests/api/v1/balances_spec.rb b/spec/requests/api/v1/balances_spec.rb
index 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 do
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) }
@@ -47,6 +48,7 @@ RSpec.describe 'API V1 Balances', type: :request do
let!(:account) do
Account.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.rb
index 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 do
tags '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.rb
index 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 do
description: "Family export creation does not accept request parameters."
}
- let(:body) { {} }
-
response "202", "family export queued" do
schema "$ref" => "#/components/schemas/FamilyExportResponse"
run_test!
diff --git a/spec/requests/api/v1/financekit_spec.rb b/spec/requests/api/v1/financekit_spec.rb
index 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 do
let(:per_page) { nil }
before do
- allow(Financekit).to receive(:enabled?).and_return(true)
allow(ApiRateLimiter).to receive(:limit).and_return(nil)
end
diff --git a/spec/requests/api/v1/holdings_spec.rb b/spec/requests/api/v1/holdings_spec.rb
index 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 do
let(:account) do
Account.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.rb
index 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 do
let(: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) }
+ end
let(:'X-Api-Key') { api_key.plain_key }
@@ -372,7 +388,8 @@ RSpec.describe 'API V1 Import Sessions', type: :request do
filename: '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)
end
run_test!
diff --git a/spec/requests/api/v1/imports_spec.rb b/spec/requests/api/v1/imports_spec.rb
index 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 do
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) }
diff --git a/spec/requests/api/v1/merchants_spec.rb b/spec/requests/api/v1/merchants_spec.rb
index 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' 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
@@ -96,9 +96,6 @@ RSpec.describe 'API V1 Merchants', type: :request do
role: 'guest'
)
end
- let(:file) do
- Rack::Test::UploadedFile.new(StringIO.new("name\nCoffee Shop"), 'text/csv', true, original_filename: 'merchants.csv')
- end
run_test!
end
diff --git a/spec/requests/api/v1/provider_connections_spec.rb b/spec/requests/api/v1/provider_connections_spec.rb
index 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 do
user: 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.rb
index 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 do
user: user,
name: 'No Read Docs Key',
key: key,
+ display_key: key,
scopes: [],
source: 'mobile'
).tap { |api_key| api_key.save!(validate: false) }
end
let(:'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) do
checking.entries.create!(
date: Date.current,
diff --git a/spec/requests/api/v1/rule_runs_spec.rb b/spec/requests/api/v1/rule_runs_spec.rb
index 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 do
user: 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.rb
index 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 do
user: 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.rb
index 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 do
let(:account) do
Account.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.rb
index 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 do
let(:account) do
Account.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.rb
index 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 do
let(:account) do
Account.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.rb
index 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 do
user: user,
name: 'No Read Docs Key',
key: key,
+ display_key: key,
scopes: [],
source: 'mobile'
).tap { |api_key| api_key.save!(validate: false) }
end
let(:'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) do
checking.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.rb
index 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::IntegrationTest
assert_equal @family.id, export.family_id
end
+ 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" do
assert_no_difference("@family.family_exports.count") do
post api_v1_family_exports_url, headers: api_headers(@read_only_api_key)
@@ -112,6 +122,17 @@ class Api::V1::FamilyExportsControllerTest < ActionDispatch::IntegrationTest
assert_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" do
get api_v1_family_exports_url, headers: api_headers(@member_api_key)
assert_response :forbidden