Skip to content

Commit

Permalink
fixed test assertions and stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
George Byers committed May 3, 2024
1 parent 45c41bb commit ac1d40a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
9 changes: 6 additions & 3 deletions spec/services/argyle_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require 'rails_helper'
require 'support/account_connected'
require 'support/account_connected_webhook_stub'
require 'support/payroll_documents_response_stub'

RSpec.describe ArgyleService, type: :service do
let(:service) { ArgyleService.new }
let(:account_id) { 'account_id' }
let(:user_id) { 'user_id' }
let(:fake_response) { instance_double(Faraday::Response, body: payroll_documents_response_stub) }

describe 'Initialization' do
it 'has a default API endpoint pointing to the sandbox' do
Expand All @@ -31,15 +33,16 @@
describe '#payroll_documents' do
context 'when ConnectedArgyleAccount exists' do
before do
# simulate that we have a ConnectedArgyleAccount record
allow(ConnectedArgyleAccount).to receive(:exists?).with(user_id: user_id, account_id: account_id).and_return(true)
fake_response = instance_double(Faraday::Response, body: account_connected_stub)
# simulate that fetching the payroll documents returns a non-empty JSON response resembling payroll data
allow_any_instance_of(Faraday::Connection).to receive(:get).with("payroll-documents", { account: account_id, user: user_id }).and_return(fake_response)
end

it 'returns payroll documents' do
response = service.payroll_documents(account_id, user_id)
expect(response).not_to be_empty
expect(response['data']['resource']['id']).to eq("018f3fb8-47b7-7a9f-b95a-530117e8522e")
expect(response['data'][0]['id']).to eq(JSON.parse(fake_response.body)['data'][0]['id'])
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def account_connected_stub
def account_connected_webhook_stub
'{
"event": "accounts.connected",
"name": "Account Connected",
Expand Down
36 changes: 36 additions & 0 deletions spec/support/payroll_documents_response_stub.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
def payroll_documents_response_stub
'{
"data": [
{
"id": "018f110a-39c1-3a5f-826f-a004eb7ed0b5",
"account": "018f3fb8-47b7-7a9f-b95a-530117e8522e",
"document_number": null,
"available_date": "2020-05-13T17:25:59Z",
"expiration_date": null,
"employer": "Whole Goods",
"document_type": "payout-statement",
"document_type_description": null,
"file_url": "api.argyle.com/v2/payroll-documents/{id}/file",
"created_at": "2023-03-13T17:27:01.501Z",
"updated_at": "2023-03-13T17:27:01.501Z",
"ocr_data": {},
"metadata": {}
},
{
"id": "018f110a-39c1-3a5f-826f-a004eb7ed0b5",
"account": "018f3fb8-47b7-7a9f-b95a-530117e8522e",
"document_number": "ced46eb3-7586-3cd7-2418-8eb9482bc3ec",
"available_date": "2019-03-14T17:46:25Z",
"expiration_date": "2027-03-12T17:46:25Z",
"employer": "GigAndGo",
"document_type": "drivers-licence",
"document_type_description": "Driver\'s license",
"file_url": "api.argyle.com/v2/payroll-documents/{id}/file",
"created_at": "2023-03-13T17:46:28.240Z",
"updated_at": "2023-03-13T17:46:28.240Z",
"ocr_data": {},
"metadata": {}
}
]
}'
end

0 comments on commit ac1d40a

Please sign in to comment.