mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Tests for adding vendors to quotes, credits and invoices
This commit is contained in:
parent
f6686c7df5
commit
dd2fba48cd
@ -78,6 +78,7 @@ class Credit extends BaseModel
|
||||
'assigned_user_id',
|
||||
'exchange_rate',
|
||||
'subscription_id',
|
||||
'vendor_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -123,6 +124,11 @@ class Credit extends BaseModel
|
||||
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
||||
}
|
||||
|
||||
public function vendor()
|
||||
{
|
||||
return $this->belongsTo(Vendor::class);
|
||||
}
|
||||
|
||||
public function history()
|
||||
{
|
||||
return $this->hasManyThrough(Backup::class, Activity::class);
|
||||
|
@ -76,6 +76,7 @@ class Quote extends BaseModel
|
||||
'exchange_rate',
|
||||
'subscription_id',
|
||||
'uses_inclusive_taxes',
|
||||
'vendor_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@ -133,6 +134,11 @@ class Quote extends BaseModel
|
||||
return $this->belongsTo(Company::class);
|
||||
}
|
||||
|
||||
public function vendor()
|
||||
{
|
||||
return $this->belongsTo(Vendor::class);
|
||||
}
|
||||
|
||||
public function history()
|
||||
{
|
||||
return $this->hasManyThrough(Backup::class, Activity::class);
|
||||
|
@ -89,6 +89,7 @@ class CreditTransformer extends EntityTransformer
|
||||
'user_id' => $this->encodePrimaryKey($credit->user_id),
|
||||
'project_id' => $this->encodePrimaryKey($credit->project_id),
|
||||
'assigned_user_id' => $this->encodePrimaryKey($credit->assigned_user_id),
|
||||
'vendor_id' => (string) $this->encodePrimaryKey($credit->vendor_id),
|
||||
'amount' => (float) $credit->amount,
|
||||
'balance' => (float) $credit->balance,
|
||||
'client_id' => (string) $this->encodePrimaryKey($credit->client_id),
|
||||
|
@ -95,6 +95,7 @@ class QuoteTransformer extends EntityTransformer
|
||||
'status_id' => (string) $quote->status_id,
|
||||
'design_id' => (string) $this->encodePrimaryKey($quote->design_id),
|
||||
'invoice_id' => (string) $this->encodePrimaryKey($quote->invoice_id),
|
||||
'vendor_id' => (string) $this->encodePrimaryKey($quote->vendor_id),
|
||||
'updated_at' => (int) $quote->updated_at,
|
||||
'archived_at' => (int) $quote->deleted_at,
|
||||
'created_at' => (int) $quote->created_at,
|
||||
|
@ -41,6 +41,111 @@ class VendorApiTest extends TestCase
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
public function testAddVendorToInvoice()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName,
|
||||
];
|
||||
|
||||
$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();
|
||||
$vendor_id =$arr['data']['id'];
|
||||
|
||||
$data = [
|
||||
'vendor_id' => $vendor_id,
|
||||
'client_id' => $this->client->hashed_id
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/invoices', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals($arr['data']['vendor_id'], $vendor_id);
|
||||
|
||||
}
|
||||
|
||||
public function testAddVendorToQuote()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName,
|
||||
];
|
||||
|
||||
$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();
|
||||
$vendor_id =$arr['data']['id'];
|
||||
|
||||
$data = [
|
||||
'vendor_id' => $vendor_id,
|
||||
'client_id' => $this->client->hashed_id
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/quotes', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals($arr['data']['vendor_id'], $vendor_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testAddVendorToCredit()
|
||||
{
|
||||
$data = [
|
||||
'name' => $this->faker->firstName,
|
||||
];
|
||||
|
||||
$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();
|
||||
$vendor_id =$arr['data']['id'];
|
||||
|
||||
$data = [
|
||||
'vendor_id' => $vendor_id,
|
||||
'client_id' => $this->client->hashed_id
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/credits', $data);
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals($arr['data']['vendor_id'], $vendor_id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testVendorPost()
|
||||
{
|
||||
$data = [
|
||||
|
Loading…
Reference in New Issue
Block a user