Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .codegenignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test/**
.gitignore
.github/**
Rakefile
Gemfile
69 changes: 69 additions & 0 deletions .github/workflows/test-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Run Tests

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch:

permissions:
contents: read

jobs:
test-runner:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Add Minitest Dependencies
run: |
gem install minitest -v 5.24 && bundle add minitest
gem install minitest-proveit -v 1.0 && bundle add minitest-proveit
- name: Add DotEnv Dependency
run: |
gem install dotenv -v 2.8 && bundle add dotenv
- name: Add Web Driver Dependency
run: |
gem install selenium-webdriver -v 4.23 && bundle add selenium-webdriver
- name: Add UI Testing Framework Dependency
run: |
gem install capybara -v 3.40 && bundle add capybara
- name: Create Environment
run: |
touch .env
echo AKOYA_API_VERSION=${{ secrets.AKOYA_API_VERSION }} >> .env
echo AKOYA_PROVIDER_ID=${{ secrets.AKOYA_PROVIDER_ID }} >> .env
echo OAUTH_CLIENT_ID=${{ secrets.OAUTH_CLIENT_ID }} >> .env
echo OAUTH_CLIENT_SECRET=${{ secrets.OAUTH_CLIENT_SECRET }} >> .env
echo OAUTH_REDIRECT_URI=${{ secrets.OAUTH_REDIRECT_URI }} >> .env
echo CONNECTOR=${{ secrets.CONNECTOR }} >> .env
echo STATE=${{ secrets.STATE }} >> .env
echo TEST_USERNAME=${{ secrets.TEST_USERNAME }} >> .env
echo TEST_PASSWORD=${{ secrets.TEST_PASSWORD }} >> .env
echo TAX_USERNAME=${{ secrets.TAX_USERNAME }} >> .env
echo TAX_PASSWORD=${{ secrets.TAX_PASSWORD }} >> .env
echo RETURN_URL=${{ secrets.RETURN_URL }} >> .env
echo STATEMENT_ACCOUNT_ID=${{ secrets.STATEMENT_ACCOUNT_ID }} >> .env
echo STATEMENT_ID=${{ secrets.STATEMENT_ID }} >> .env
echo TAXLOT_ACCOUNT_ID=${{ secrets.TAXLOT_ACCOUNT_ID }} >> .env
echo HOLDING_ID=${{ secrets.HOLDING_ID }} >> .env
cat .env
- name: Run Tests
run: bundle exec rake test
# - name: Run Endpoint Tests Only
# run: bundle exec rake test_endpoints
# - name: Run Auth Tests Only
# run: bundle exec rake test_auth
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
Gemfile.lock
.env
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore uploaded files in development.
/public/uploads

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore application configuration.
/config/application.yml

# Ignore test artifacts
consent_flow_failure.png
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
source 'https://rubygems.org'

gemspec
group :test do
gem 'rake'
end

gemspec
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,80 @@ A new controller class named `HelloController` will be created in a file named `

![Initialize the library](https://apidocs.io/illustration/ruby?workspaceFolder=Akoya&gemName=akoya&step=addCode3)

## Testing

The Akoya Ruby SDK includes a comprehensive test suite that follows Ruby best practices and testing patterns. The test suite covers all major API endpoints and authentication scenarios.

### Test Structure

The test suite is organized into the following components:

- **Base Test Class**: `test/controller_test_base.rb` - Handles authentication and environment setup
- **Endpoint Tests**: Tests for all major API endpoints (account info, balances, customers, investments, payments, statements, tax, transactions)
- **Authentication Tests**: Tests for various error scenarios and authentication flows
- **Test Runner**: `test/test_runner.rb` - Main test runner that executes all tests

### Running Tests

#### Prerequisites
1. Install Ruby 3.0 or later
2. Install dependencies: `bundle install`
3. Install Playwright: `npx playwright install chromium`
4. Set up environment variables (see `env.example` file)

#### Running All Tests
```bash
bundle exec rake test
```

#### Running Specific Test Categories
```bash
# Run only endpoint tests
bundle exec rake test_endpoints

# Run only authentication tests
bundle exec rake test_auth
```

#### Running Individual Test Files
```bash
# Run a specific test file
ruby test/test_account_info_controller.rb

# Run the test runner
ruby test/test_runner.rb
```

### Environment Setup

Copy `env.example` to `.env` and configure the following environment variables:

**Required Variables:**
- `AKOYA_API_VERSION` - API version to use
- `AKOYA_PROVIDER_ID` - Provider ID for testing
- `OAUTH_CLIENT_ID` - OAuth client ID
- `OAUTH_CLIENT_SECRET` - OAuth client secret
- `OAUTH_REDIRECT_URI` - OAuth redirect URI
- `CONNECTOR` - Connector identifier
- `STATE` - OAuth state parameter
- `TEST_USERNAME` - Username for test authentication
- `TEST_PASSWORD` - Password for test authentication
- `TAX_USERNAME` - Username for tax-related tests
- `TAX_PASSWORD` - Password for tax-related tests
- `RETURN_URL` - Return URL for OAuth flow

**Optional Variables:**
- `STATEMENT_ACCOUNT_ID` - Account ID for statement tests
- `STATEMENT_ID` - Statement ID for specific statement tests
- `TAXLOT_ACCOUNT_ID` - Account ID for tax lot tests
- `HOLDING_ID` - Holding ID for investment tests

### CI/CD Integration

The test suite is integrated with GitHub Actions via `.github/workflows/test-runner.yml`. The workflow automatically runs tests on push to main/master branches and pull requests.

For more detailed information about the test suite, see the [test README](test/README.md).

## Initialize the API Client

**_Note:_** Documentation for the client can be found [here.](https://www.github.com/akoya-llc/akoya-ruby-sdk/tree/0.2.0/doc/client.md)
Expand Down
24 changes: 24 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,27 @@ lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/test_*.rb"]
t.verbose = true
end

Rake::TestTask.new(:test_endpoints) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/test_*_controller.rb"]
t.verbose = true
end

Rake::TestTask.new(:test_auth) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/test_error_scenarios.rb"]
t.verbose = true
end

task default: :test
151 changes: 151 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
# Akoya Ruby SDK Test Suite

This directory contains the comprehensive test suite for the Akoya Ruby SDK, following Ruby best practices and testing patterns.

## Test Structure

The test suite is organized into the following components:

### Base Test Class
- `controller_test_base.rb` - Base class for all endpoint tests, handles authentication and environment setup

### Endpoint Tests
- `test_account_info_controller.rb` - Tests for account information endpoints
- `test_balances_controller.rb` - Tests for balances endpoints
- `test_customers_controller.rb` - Tests for customer information endpoints
- `test_investments_controller.rb` - Tests for investment endpoints
- `test_payments_controller.rb` - Tests for payment network endpoints
- `test_statements_controller.rb` - Tests for statement endpoints
- `test_tax_controller.rb` - Tests for tax form endpoints
- `test_transactions_controller.rb` - Tests for transaction endpoints

### Authentication Tests
- `test_error_scenarios.rb` - Tests for various error scenarios and authentication flows

### Test Runner
- `test_runner.rb` - Main test runner that executes all tests

## Environment Setup

The tests require the following environment variables to be set:

### Required Variables
- `AKOYA_API_VERSION` - API version to use
- `AKOYA_PROVIDER_ID` - Provider ID for testing
- `OAUTH_CLIENT_ID` - OAuth client ID
- `OAUTH_CLIENT_SECRET` - OAuth client secret
- `OAUTH_REDIRECT_URI` - OAuth redirect URI
- `CONNECTOR` - Connector identifier
- `STATE` - OAuth state parameter
- `TEST_USERNAME` - Username for test authentication
- `TEST_PASSWORD` - Password for test authentication
- `TAX_USERNAME` - Username for tax-related tests
- `TAX_PASSWORD` - Password for tax-related tests
- `RETURN_URL` - Return URL for OAuth flow

### Optional Variables
- `STATEMENT_ACCOUNT_ID` - Account ID for statement tests
- `STATEMENT_ID` - Statement ID for specific statement tests
- `TAXLOT_ACCOUNT_ID` - Account ID for tax lot tests
- `HOLDING_ID` - Holding ID for investment tests

## Running Tests

### Prerequisites
1. Install Ruby 3.0 or later
2. Install dependencies: `bundle install`
3. Install Playwright: `npx playwright install chromium`
4. Set up environment variables (see above)

### Running All Tests
```bash
bundle exec rake test
```

### Running Specific Test Categories
```bash
# Run only endpoint tests
bundle exec rake test_endpoints

# Run only authentication tests
bundle exec rake test_auth
```

### Running Individual Test Files
```bash
# Run a specific test file
ruby test/test_account_info_controller.rb

# Run the test runner
ruby test/test_runner.rb
```

## Test Features

### Authentication Flow
- Uses Playwright for browser automation
- Handles OAuth consent flow automatically
- Supports different user credentials for different test scenarios

### Error Testing
- Tests various error scenarios (500, 501, 601, 602, 701, 702, 703, 704)
- Validates proper exception handling
- Ensures error codes match expected values

### Endpoint Testing
- Tests all major API endpoints
- Validates response structure and content
- Ensures proper status codes
- Verifies data integrity

## CI/CD Integration

The test suite is integrated with GitHub Actions via `.github/workflows/test-runner.yml`. The workflow:

1. Sets up Ruby environment
2. Installs dependencies
3. Configures environment variables from GitHub secrets
4. Installs Playwright
5. Runs all test categories

## Best Practices

### Ruby Testing Standards
- Uses Minitest framework (Ruby's standard testing library)
- Follows Ruby naming conventions
- Implements proper setup and teardown methods
- Uses descriptive test method names

### Test Organization
- Clear separation between endpoint and auth tests
- Consistent test structure across all controllers
- Proper error handling and validation
- Comprehensive documentation

### Environment Management
- Uses dotenv for environment variable management
- Validates required environment variables
- Supports both local and CI environments

## Troubleshooting

### Common Issues
1. **Playwright not found**: Ensure Playwright is installed with `npx playwright install chromium`
2. **Environment variables missing**: Check that all required variables are set in `.env` file
3. **Authentication failures**: Verify test credentials are correct
4. **Network issues**: Ensure stable internet connection for API calls

### Debug Mode
To run tests with additional logging:
```bash
LOG_LEVEL=DEBUG bundle exec rake test
```

## Contributing

When adding new tests:
1. Follow the existing naming conventions
2. Extend the appropriate base class
3. Include proper documentation
4. Add corresponding Rake tasks if needed
5. Update this README if necessary
Loading
Loading