Fixes for tests

This commit is contained in:
David Bomba 2024-03-21 09:12:45 +11:00
parent ba4cd4508b
commit f5f972ad6a
4 changed files with 7 additions and 17 deletions

View File

@ -260,8 +260,8 @@ class UserController extends BaseController
/** @var \App\Models\User $logged_in_user */
$logged_in_user = auth()->user();
$company_user = CompanyUser::whereUserId($user->id)
->whereCompanyId($logged_in_user->companyId())
$company_user = CompanyUser::where('user_id',$user->id)
->where('company_id', $logged_in_user->companyId())
->withTrashed()
->first();
@ -269,14 +269,10 @@ class UserController extends BaseController
return response()->json(['message', 'Cannot detach owner.'], 401);
}
$token = $company_user->token->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first();
if ($token) {
$token->delete();
}
$company_user->tokens()->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->forceDelete();
if ($company_user) {
$company_user->delete();
$company_user->forceDelete();
}
return response()->json(['message' => ctrans('texts.user_detached')], 200);

View File

@ -50,7 +50,7 @@ class StorePaymentRequest extends Request
'invoices.*.invoice_id' => ['bail','required','distinct', new ValidInvoicesRules($this->all()),Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
'credits.*.credit_id' => ['bail','required','distinct', new ValidCreditsRules($this->all()),Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
'credits.*.amount' => ['bail','required', new CreditsSumRule($this->all())],
'invoices' => ['bail','sometimes','array', new ValidPayableInvoicesRule()],
'invoices' => ['bail','sometimes', 'nullable', 'array', new ValidPayableInvoicesRule()],
'number' => ['bail', 'nullable', Rule::unique('payments')->where('company_id', $user->company()->id)],
'idempotency_key' => ['nullable', 'bail', 'string','max:64', Rule::unique('payments')->where('company_id', $user->company()->id)],
];

View File

@ -44,7 +44,7 @@ class UpdatePaymentRequest extends Request
$rules = [
'client_id' => ['sometimes', 'bail', Rule::in([$this->payment->client_id])],
'number' => ['sometimes', 'bail', Rule::unique('payments')->where('company_id', $user->company()->id)->ignore($this->payment->id)],
'invoices' => ['sometimes', 'bail', 'array', new PaymentAppliedValidAmount($this->all())],
'invoices' => ['sometimes', 'bail', 'nullable', 'array', new PaymentAppliedValidAmount($this->all())],
'invoices.*.invoice_id' => ['sometimes','distinct',Rule::exists('invoices','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],
'invoices.*.amount' => ['sometimes','numeric','min:0'],
'credits.*.credit_id' => ['sometimes','bail','distinct',Rule::exists('credits','id')->where('company_id', $user->company()->id)->where('client_id', $this->client_id)],

View File

@ -590,19 +590,13 @@ class PaymentTest extends TestCase
$response = false;
// try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/payments?include=invoices', $data);
// } catch (ValidationException $e) {
// $message = json_decode($e->validator->getMessageBag(), 1);
// $this->assertNotNull($message);
// }
// if ($response) {
$response->assertStatus(200);
// }
}
public function testPartialPaymentAmount()