I have a method to process a loan request, it creates a new loan record from form inputs and uses it as a dependency for an API call.
I wrote a test for this method that includes faking an API call like this:
//
Http::fake([config('services.dummy.url').'/v3/transfers' => Http::response([
'status' => 'success',
'message' => 'test message',
'data' => [
'tx_ref' => $ref,
'meta' => [
'user_id' => $user->id,
'loan_id' => $loan->id,
'loanProvider_id' => $loanProvider->id,
'transfer_description' => 'Loan Disbursement',
],
],
], 200),
config('services.dummy.url').'/v3/transactions/'.$ref.'/verify' => Http::response([
'status' => 'success',
'message' => 'test message',
'meta' => [
//
'loan_id' => $loan->id,
//
],
],
], 200),
]);
//
The thing is that I need the loan record for the API call but it’s not created within my test but within the method.
public function processLoanApplication(Request $request, User $user) {
//
$loan = $user->loans()->create([//]);
//
// API call
$transferService->disburseLoan($loan);
}
What’s the correct way to set this test up?