Files
sure/test/models/provider/akahu_test.rb
Brad 1b8b21760b feat(provider): Akahu integration (#1921)
* First pass of Akahu

* fix up sync all

* conflicts

* fix db migration issue? - fix auto selection of akahu account type

* Address Akahu PR feedback

* Complete provider metadata

* Fix PR 1921 CI tests

* PR feedback

* PR feedback

* post merge

---------

Co-authored-by: failing <failing@users.noreply.github.com>
Co-authored-by: Juan José Mata <jjmata@jjmata.com>
Co-authored-by: sure-admin <sure-admin@splashblot.com>
2026-06-02 21:44:57 +02:00

55 lines
1.9 KiB
Ruby

require "test_helper"
class Provider::AkahuTest < ActiveSupport::TestCase
FakeResponse = Struct.new(:code, :body, :message, keyword_init: true)
test "fetches paginated account transactions with Akahu auth headers" do
responses = [
FakeResponse.new(
code: 200,
message: "OK",
body: { items: [ { _id: "tx_1" } ], cursor: { next: "next-cursor" } }.to_json
),
FakeResponse.new(
code: 200,
message: "OK",
body: { items: [ { _id: "tx_2" } ] }.to_json
)
]
requests = []
Provider::Akahu.stub(:get, ->(url, headers:, query: nil) {
requests << { url: url, headers: headers, query: query }
responses.shift
}) do
client = Provider::Akahu.new(app_token: "akahu-app-credential", user_token: "akahu-user-credential")
transactions = client.get_account_transactions(
account_id: "acc_123",
start_date: Date.new(2026, 1, 1)
)
assert_equal [ "tx_1", "tx_2" ], transactions.map { |tx| tx[:_id] }
end
assert_equal 2, requests.size
assert_match "/accounts/acc_123/transactions", requests.first[:url]
assert_equal "Bearer akahu-user-credential", requests.first[:headers]["Authorization"]
assert_equal "akahu-app-credential", requests.first[:headers]["X-Akahu-Id"]
assert_match "2026-01-01", requests.first[:query][:start]
assert_equal "next-cursor", requests.second[:query][:cursor]
end
test "raises typed errors for unauthorized responses" do
response = FakeResponse.new(code: 401, message: "Unauthorized", body: "{}")
Provider::Akahu.stub(:get, ->(_url, headers:, query: nil) { response }) do
error = assert_raises Provider::Akahu::AkahuError do
Provider::Akahu.new(app_token: "akahu-app-credential", user_token: "invalid-credential").get_accounts
end
assert_equal :unauthorized, error.error_type
end
end
end