mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Tests for adding language ID for vendors
This commit is contained in:
parent
79c4d49896
commit
92336b7f05
111
app/Helpers/Bank/Yodlee/DTO/AccountSummary.php
Normal file
111
app/Helpers/Bank/Yodlee/DTO/AccountSummary.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Helpers\Bank\Yodlee\DTO;
|
||||
|
||||
use Spatie\LaravelData\Data;
|
||||
use Spatie\LaravelData\Attributes\MapInputName;
|
||||
use Spatie\LaravelData\Attributes\MapOutputName;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* {#2983
|
||||
"account": [
|
||||
{#2979
|
||||
"CONTAINER": "bank",
|
||||
"providerAccountId": 10058190,
|
||||
"accountName": "Business Trans Acct",
|
||||
"accountStatus": "ACTIVE",
|
||||
"accountNumber": "1011 4402",
|
||||
"aggregationSource": "USER",
|
||||
"isAsset": true,
|
||||
"balance": {#2978
|
||||
"currency": "AUD",
|
||||
"amount": 308544.98,
|
||||
},
|
||||
"id": 10139315,
|
||||
"includeInNetWorth": true,
|
||||
"providerId": "3857",
|
||||
"providerName": "Commonwealth Bank",
|
||||
"isManual": false,
|
||||
"availableBalance": {#2966
|
||||
"currency": "AUD",
|
||||
"amount": 309044.98,
|
||||
},
|
||||
"currentBalance": {#2982
|
||||
"currency": "AUD",
|
||||
"amount": 308544.98,
|
||||
},
|
||||
"accountType": "CHECKING",
|
||||
"displayedName": "after David",
|
||||
"createdDate": "2023-01-10T08:29:07Z",
|
||||
"classification": "SMALL_BUSINESS",
|
||||
"lastUpdated": "2023-08-01T23:50:13Z",
|
||||
"nickname": "Business Trans Acct",
|
||||
"bankTransferCode": [
|
||||
{#2976
|
||||
"id": "062020",
|
||||
"type": "BSB",
|
||||
},
|
||||
],
|
||||
"dataset": [
|
||||
{#2971
|
||||
"name": "BASIC_AGG_DATA",
|
||||
"additionalStatus": "AVAILABLE_DATA_RETRIEVED",
|
||||
"updateEligibility": "ALLOW_UPDATE",
|
||||
"lastUpdated": "2023-08-01T23:49:53Z",
|
||||
"lastUpdateAttempt": "2023-08-01T23:49:53Z",
|
||||
"nextUpdateScheduled": "2023-08-03T14:45:14Z",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
*/
|
||||
class AccountSummary extends Data
|
||||
{
|
||||
public ?int $id;
|
||||
|
||||
#[MapInputName('CONTAINER')]
|
||||
public ?string $account_type;
|
||||
|
||||
#[MapInputName('accountName')]
|
||||
public ?string $account_name;
|
||||
|
||||
#[MapInputName('accountStatus')]
|
||||
public ?string $account_status;
|
||||
|
||||
#[MapInputName('accountNumber')]
|
||||
public ?string $account_number;
|
||||
|
||||
#[MapInputName('providerAccountId')]
|
||||
public int $provider_account_id;
|
||||
|
||||
#[MapInputName('providerId')]
|
||||
public ?string $provider_id;
|
||||
|
||||
#[MapInputName('providerName')]
|
||||
public ?string $provider_name;
|
||||
|
||||
public ?string $nickname;
|
||||
|
||||
public ?float $current_balance;
|
||||
public ?string $account_currency;
|
||||
|
||||
public static function prepareForPipeline(Collection $properties) : Collection
|
||||
{
|
||||
|
||||
$properties->put('current_balance', (array)$properties['currentBalance']['amount'] ?? '');
|
||||
$properties->put('account_currency', (array)$properties['currentBalance']['currency'] ?? '');
|
||||
|
||||
return $properties;
|
||||
}
|
||||
}
|
17
app/Http/Requests/Vendor/StoreVendorRequest.php
vendored
17
app/Http/Requests/Vendor/StoreVendorRequest.php
vendored
@ -26,17 +26,23 @@ class StoreVendorRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('create', Vendor::class);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('create', Vendor::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$rules = [];
|
||||
|
||||
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
|
||||
|
||||
if (isset($this->number)) {
|
||||
$rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id);
|
||||
$rules['number'] = Rule::unique('vendors')->where('company_id', $user->company()->id);
|
||||
}
|
||||
|
||||
$rules['currency_id'] = 'bail|required|exists:currencies,id';
|
||||
@ -53,15 +59,20 @@ class StoreVendorRequest extends Request
|
||||
$rules['file'] = $this->file_validation;
|
||||
}
|
||||
|
||||
$rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$input = $this->all();
|
||||
|
||||
if (!array_key_exists('currency_id', $input) || empty($input['currency_id'])) {
|
||||
$input['currency_id'] = auth()->user()->company()->settings->currency_id;
|
||||
$input['currency_id'] = $user->company()->settings->currency_id;
|
||||
}
|
||||
|
||||
$input = $this->decodePrimaryKeys($input);
|
||||
|
12
app/Http/Requests/Vendor/UpdateVendorRequest.php
vendored
12
app/Http/Requests/Vendor/UpdateVendorRequest.php
vendored
@ -28,17 +28,21 @@ class UpdateVendorRequest extends Request
|
||||
*/
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->vendor);
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $user->can('edit', $this->vendor);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
/* Ensure we have a client name, and that all emails are unique*/
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
$rules['country_id'] = 'integer';
|
||||
|
||||
if ($this->number) {
|
||||
$rules['number'] = Rule::unique('vendors')->where('company_id', auth()->user()->company()->id)->ignore($this->vendor->id);
|
||||
$rules['number'] = Rule::unique('vendors')->where('company_id', $user->company()->id)->ignore($this->vendor->id);
|
||||
}
|
||||
|
||||
$rules['contacts.*.email'] = 'nullable|distinct';
|
||||
@ -56,6 +60,8 @@ class UpdateVendorRequest extends Request
|
||||
$rules['file'] = $this->file_validation;
|
||||
}
|
||||
|
||||
$rules['language_id'] = 'bail|nullable|sometimes|exists:languages,id';
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,8 @@ use Laracasts\Presenter\PresentableTrait;
|
||||
* @property string|null $vendor_hash
|
||||
* @property string|null $public_notes
|
||||
* @property string|null $id_number
|
||||
* @property string|null $language_id
|
||||
* @property int|null $last_login
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
|
||||
* @property-read int|null $activities_count
|
||||
* @property-read \App\Models\User|null $assigned_user
|
||||
@ -140,6 +142,7 @@ class Vendor extends BaseModel
|
||||
'custom_value3',
|
||||
'custom_value4',
|
||||
'number',
|
||||
'language_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
|
@ -103,6 +103,7 @@ class VendorTransformer extends EntityTransformer
|
||||
'archived_at' => (int) $vendor->deleted_at,
|
||||
'created_at' => (int) $vendor->created_at,
|
||||
'number' => (string) $vendor->number ?: '',
|
||||
'language_id' => (string) $vendor->language_id ?: '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -5147,6 +5147,15 @@ $LANG = array(
|
||||
'intracommunity_tax_info' => 'Tax-free intra-community delivery',
|
||||
'reverse_tax_info' => 'Please note that this supply is subject to reverse charge',
|
||||
'currency_nicaraguan_cordoba' => 'Nicaraguan Córdoba',
|
||||
'public' => 'Public',
|
||||
'private' => 'Private',
|
||||
'image' => 'Image',
|
||||
'other' => 'Other',
|
||||
'linked_to' => 'Linked To',
|
||||
'file_saved_in_path' => 'The file has been saved in :path',
|
||||
'unlinked_transactions' => 'Successfully unlinked :count transactions',
|
||||
'unlinked_transaction' => 'Successfully unlinked transaction',
|
||||
'view_dashboard_permission' => 'Allow user to access the dashboard, data is limited to available permissions',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -2189,7 +2189,7 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'credit_total' => 'Total du crédit',
|
||||
'mark_billable' => 'Marquer comme facturable',
|
||||
'billed' => 'Facturé',
|
||||
'company_variables' => 'Variables de la compagnie',
|
||||
'company_variables' => 'Variables de l\'entreprise',
|
||||
'client_variables' => 'Variables du client',
|
||||
'invoice_variables' => 'Variables de facture',
|
||||
'navigation_variables' => 'Variables de navigation',
|
||||
@ -2396,6 +2396,9 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
|
||||
'currency_cuban_peso' => 'Cuban Peso',
|
||||
'currency_bz_dollar' => 'Dollar bélizien',
|
||||
'currency_libyan_dinar' => 'Dinar libyen',
|
||||
'currency_silver_troy_ounce' => 'Once troy d\'argent',
|
||||
'currency_gold_troy_ounce' => 'Once troy d\'or',
|
||||
|
||||
'review_app_help' => 'Nous espérons que votre utilisation de cette application vous est agréable.<br/>Un commentaire de votre part serait grandement apprécié!',
|
||||
'writing_a_review' => 'rédiger un commentaire',
|
||||
@ -3264,8 +3267,8 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'contact_custom_value4' => 'Valeur personnalisée du contact 4',
|
||||
'assigned_to_id' => 'Assigné à ID',
|
||||
'created_by_id' => 'Créé par ID',
|
||||
'add_column' => 'Ajouter colonne',
|
||||
'edit_columns' => 'Éditer colonne',
|
||||
'add_column' => 'Ajouter une colonne',
|
||||
'edit_columns' => 'Éditer les colonnes',
|
||||
'to_learn_about_gogle_fonts' => 'en savoir plus sur Google Fonts',
|
||||
'refund_date' => 'Date de remboursement',
|
||||
'multiselect' => 'Sélection multiple',
|
||||
@ -3320,7 +3323,7 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'item_tax_rates' => 'Taux de taxe par article',
|
||||
'configure_rates' => 'Configuration des taux',
|
||||
'tax_settings_rates' => 'Taux de taxe',
|
||||
'accent_color' => 'Couleur de mise en évidence',
|
||||
'accent_color' => 'Couleur d\'accent',
|
||||
'comma_sparated_list' => 'Liste séparée par virgule',
|
||||
'single_line_text' => 'Ligne de texte simple',
|
||||
'multi_line_text' => 'Zone de texte multilignes',
|
||||
@ -3415,7 +3418,7 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'quote_details' => 'Informations de la soumission',
|
||||
'credit_details' => 'Informations de crédit',
|
||||
'product_columns' => 'Colonnes produit',
|
||||
'task_columns' => 'Colonnes tâches',
|
||||
'task_columns' => 'Colonnes tâche',
|
||||
'add_field' => 'Ajouter un champ',
|
||||
'all_events' => 'Ajouter un événement',
|
||||
'owned' => 'Propriétaire',
|
||||
@ -4209,7 +4212,7 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'copyright' => 'Droits d\'auteur',
|
||||
'user_created_user' => ':user a créé :created_user à :time',
|
||||
'company_deleted' => 'Entreprise supprimée',
|
||||
'company_deleted_body' => 'La compagnie [:company] a été supprimé par :user',
|
||||
'company_deleted_body' => 'L\'entreprise [:company] a été supprimé par :user',
|
||||
'back_to' => 'Retour à :url',
|
||||
'stripe_connect_migration_title' => 'Connectez votre compte Stripe',
|
||||
'stripe_connect_migration_desc' => 'Invoice Ninja v5 utilise Stripe Connect pour lier votre compte Stripe à Invoice Ninja. Cela fournit une couche de sécurité supplémentaire pour votre compte. Maintenant que vos données ont migré, vous devez autoriser Stripe à accepter les paiements dans la v5.<br><br>Pour ce faire, accédez à Paramètres > Paiements en ligne > Configurer les passerelles. Cliquez sur Stripe Connect, puis sous Paramètres, cliquez sur Configurer la passerelle. Cela vous amènera à Stripe pour autoriser Invoice Ninja et à votre retour, votre compte sera lié !',
|
||||
@ -4478,7 +4481,7 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'id' => 'Id',
|
||||
'convert_to' => 'Convertir en',
|
||||
'client_currency' => 'Devise du client',
|
||||
'company_currency' => 'Devise de la compagnie',
|
||||
'company_currency' => 'Devise de l\'entreprise',
|
||||
'custom_emails_disabled_help' => 'Il est nécessaire de souscrire à un compte payant pour personnaliser les paramètres anti-pourriels',
|
||||
'upgrade_to_add_company' => 'Augmenter votre plan pour ajouter des entreprises',
|
||||
'file_saved_in_downloads_folder' => 'Le fichier a été sauvegardé dans le dossier Téléchargements',
|
||||
@ -4944,7 +4947,7 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'sync_from' => 'Sync de',
|
||||
'gateway_payment_text' => 'Factures: :invoices pour :amount pour :client',
|
||||
'gateway_payment_text_no_invoice' => 'Paiement sans facture d\'un montant de :amount pour le client :client',
|
||||
'click_to_variables' => 'Cliquez ici pour voir toutes les variables',
|
||||
'click_to_variables' => 'Cliquez ici pour voir toutes les variables.',
|
||||
'ship_to' => 'Livrer à',
|
||||
'stripe_direct_debit_details' => 'Veuillez transférer dans le compte bancaire indiqué ci-dessus.',
|
||||
'branch_name' => 'Nom de succursale',
|
||||
@ -5127,9 +5130,13 @@ Lorsque les montant apparaîtront sur votre relevé, veuillez revenir sur cette
|
||||
'activity_10_online' => ':contact a saisi un paiement :payment pour la facture :invoice pour :client',
|
||||
'activity_10_manual' => ':user a saisi un paiement :payment pour la facture :invoice pour :client',
|
||||
'default_payment_type' => 'Type de paiement par défaut',
|
||||
'number_precision' => 'Précision du nombre',
|
||||
'number_precision_help' => 'Contrôle le nombre de décimales supportées dans l\'interface',
|
||||
'is_tax_exempt' => 'Exonéré de taxe',
|
||||
'drop_files_here' => 'Déposez les fichiers ici',
|
||||
'upload_files' => 'Téléverser les fichiers',
|
||||
);
|
||||
|
||||
|
||||
return $LANG;
|
||||
|
||||
?>
|
@ -157,7 +157,7 @@ Route::group(['middleware' => ['throttle:api', 'api_db', 'token_auth', 'locale']
|
||||
Route::resource('clients', ClientController::class); // name = (clients. index / create / show / update / destroy / edit
|
||||
Route::put('clients/{client}/upload', [ClientController::class, 'upload'])->name('clients.upload');
|
||||
Route::post('clients/{client}/purge', [ClientController::class, 'purge'])->name('clients.purge')->middleware('password_protected');
|
||||
Route::post('clients/{client}/updateTaxData', [ClientController::class, 'updateTaxData'])->name('clients.purge')->middleware('throttle:3,1');
|
||||
Route::post('clients/{client}/updateTaxData', [ClientController::class, 'updateTaxData'])->name('clients.update_tax_data')->middleware('throttle:3,1');
|
||||
Route::post('clients/{client}/{mergeable_client}/merge', [ClientController::class, 'merge'])->name('clients.merge')->middleware('password_protected');
|
||||
Route::post('clients/bulk', [ClientController::class, 'bulk'])->name('clients.bulk');
|
||||
|
||||
|
@ -29,6 +29,8 @@ class VendorApiTest extends TestCase
|
||||
use DatabaseTransactions;
|
||||
use MockAccountData;
|
||||
|
||||
public $faker;
|
||||
|
||||
protected function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
@ -40,6 +42,9 @@ class VendorApiTest extends TestCase
|
||||
$this->faker = \Faker\Factory::create();
|
||||
|
||||
Model::reguard();
|
||||
|
||||
// $this->withoutExceptionHandling();
|
||||
|
||||
}
|
||||
|
||||
public function testVendorGetFilter()
|
||||
@ -52,10 +57,79 @@ class VendorApiTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
public function testAddVendorLanguage200()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName(),
|
||||
'language_id' => 2,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/vendors', $data)->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals('2', $arr['data']['language_id']);
|
||||
|
||||
$id = $arr['data']['id'];
|
||||
|
||||
$data = [
|
||||
'language_id' => 3,
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->putJson("/api/v1/vendors/{$id}", $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
$this->assertEquals('3', $arr['data']['language_id']);
|
||||
|
||||
}
|
||||
|
||||
public function testAddVendorLanguage422()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName(),
|
||||
'language_id' => '4431',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->postJson('/api/v1/vendors', $data)->assertStatus(422);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testAddVendorLanguage()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName(),
|
||||
'language_id' => '1',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/vendors', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals('1', $arr['data']['language_id']);
|
||||
}
|
||||
|
||||
|
||||
public function testAddVendorToInvoice()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName(),
|
||||
'language_id' => '',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
|
Loading…
Reference in New Issue
Block a user