mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 06:14:35 -04:00
Fixes for tests (#3701)
* Update Exchange rate Data once a day * Tests for currency conversions * Fixes for tests * Fix for adding blank product keys * Class for logging emails sent * Fixes for tests * Fixes for testS * Include credits in first_load=true * Fixes for tests * fixes for tests * Fixes for tests: * Fixes for tests * Fixes for tests
This commit is contained in:
parent
5d54d4313a
commit
a0eecdd755
2
.env.ci
2
.env.ci
@ -16,6 +16,6 @@ DB_DATABASE=ninja
|
|||||||
DB_USERNAME=root
|
DB_USERNAME=root
|
||||||
DB_PASSWORD=ninja
|
DB_PASSWORD=ninja
|
||||||
DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
NINJA_ENVIRONMENT=development
|
NINJA_ENVIRONMENT=hosted
|
||||||
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
|
COMPOSER_AUTH='{"github-oauth": {"github.com": "${{ secrets.GITHUB_TOKEN }}"}}'
|
||||||
TRAVIS=true
|
TRAVIS=true
|
||||||
|
2
.github/workflows/phpunit.yml
vendored
2
.github/workflows/phpunit.yml
vendored
@ -20,7 +20,7 @@ jobs:
|
|||||||
CACHE_DRIVER: file
|
CACHE_DRIVER: file
|
||||||
QUEUE_CONNECTION: sync
|
QUEUE_CONNECTION: sync
|
||||||
SESSION_DRIVER: file
|
SESSION_DRIVER: file
|
||||||
NINJA_ENVIRONMENT: development
|
NINJA_ENVIRONMENT: hosted
|
||||||
MULTI_DB_ENABLED: false
|
MULTI_DB_ENABLED: false
|
||||||
NINJA_LICENSE: 123456
|
NINJA_LICENSE: 123456
|
||||||
TRAVIS: true
|
TRAVIS: true
|
||||||
|
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -21,7 +21,7 @@ jobs:
|
|||||||
- name: Install composer dependencies
|
- name: Install composer dependencies
|
||||||
run: |
|
run: |
|
||||||
composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
|
composer config -g github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
|
||||||
composer install
|
composer install --no-dev
|
||||||
|
|
||||||
- name: Prepare Laravel Application
|
- name: Prepare Laravel Application
|
||||||
run: |
|
run: |
|
||||||
|
@ -264,8 +264,9 @@ class BaseController extends Controller
|
|||||||
'company.payments.paymentables',
|
'company.payments.paymentables',
|
||||||
'company.quotes.invitations.contact',
|
'company.quotes.invitations.contact',
|
||||||
'company.quotes.invitations.company',
|
'company.quotes.invitations.company',
|
||||||
'company.credits.invitations.contact',
|
'company.credits',
|
||||||
'company.credits.invitations.company',
|
//'company.credits.invitations.contact',
|
||||||
|
//'company.credits.invitations.company',
|
||||||
'company.vendors.contacts',
|
'company.vendors.contacts',
|
||||||
'company.expenses',
|
'company.expenses',
|
||||||
'company.tasks',
|
'company.tasks',
|
||||||
|
@ -43,20 +43,26 @@ class InvoiceEmailedNotification implements ShouldQueue
|
|||||||
$invitation = $event->invitation;
|
$invitation = $event->invitation;
|
||||||
|
|
||||||
foreach ($invitation->company->company_users as $company_user) {
|
foreach ($invitation->company->company_users as $company_user) {
|
||||||
|
|
||||||
$user = $company_user->user;
|
$user = $company_user->user;
|
||||||
|
|
||||||
$notification = new EntitySentNotification($invitation, 'invoice');
|
$notification = new EntitySentNotification($invitation, 'invoice');
|
||||||
|
|
||||||
$notification->method = $this->findUserNotificationTypes($invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']);
|
$methods = $this->findUserNotificationTypes($invitation, $company_user, 'invoice', ['all_notifications', 'invoice_sent']);
|
||||||
|
|
||||||
|
if (($key = array_search('mail', $methods)) !== false) {
|
||||||
|
unset($methods[$key]);
|
||||||
|
|
||||||
|
//Fire mail notification here!!!
|
||||||
|
//This allows us better control of how we
|
||||||
|
//handle the mailer
|
||||||
|
}
|
||||||
|
|
||||||
|
$notification->method = $methods;
|
||||||
|
|
||||||
$user->notify($notification);
|
$user->notify($notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(isset($invitation->company->slack_webhook_url)){
|
|
||||||
|
|
||||||
// Notification::route('slack', $invitation->company->slack_webhook_url)
|
|
||||||
// ->notify(new EntitySentNotification($invitation, $invitation->company, true));
|
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ use App\Models\Company;
|
|||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
use App\Models\CompanyLedger;
|
use App\Models\CompanyLedger;
|
||||||
use App\Models\CompanyUser;
|
use App\Models\CompanyUser;
|
||||||
|
use App\Models\Credit;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Expense;
|
use App\Models\Expense;
|
||||||
use App\Models\GroupSetting;
|
use App\Models\GroupSetting;
|
||||||
@ -29,6 +30,7 @@ use App\Models\Task;
|
|||||||
use App\Models\TaxRate;
|
use App\Models\TaxRate;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Transformers\CompanyLedgerTransformer;
|
use App\Transformers\CompanyLedgerTransformer;
|
||||||
|
use App\Transformers\CreditTransformer;
|
||||||
use App\Transformers\TaskTransformer;
|
use App\Transformers\TaskTransformer;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
|
||||||
@ -68,6 +70,7 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
'company_gateways',
|
'company_gateways',
|
||||||
'activities',
|
'activities',
|
||||||
'quotes',
|
'quotes',
|
||||||
|
'credits',
|
||||||
'projects',
|
'projects',
|
||||||
'tasks',
|
'tasks',
|
||||||
'ledger',
|
'ledger',
|
||||||
@ -202,6 +205,13 @@ class CompanyTransformer extends EntityTransformer
|
|||||||
return $this->includeCollection($company->quotes, $transformer, Quote::class);
|
return $this->includeCollection($company->quotes, $transformer, Quote::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function includeCredits(Company $company)
|
||||||
|
{
|
||||||
|
$transformer = new CreditTransformer($this->serializer);
|
||||||
|
|
||||||
|
return $this->includeCollection($company->credits, $transformer, Credit::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function includeAccount(Company $company)
|
public function includeAccount(Company $company)
|
||||||
{
|
{
|
||||||
$transformer = new AccountTransformer($this->serializer);
|
$transformer = new AccountTransformer($this->serializer);
|
||||||
|
@ -58,9 +58,6 @@ trait UserNotifies
|
|||||||
array_push($notifiable_methods, 'mail');
|
array_push($notifiable_methods, 'mail');
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(count(array_intersect($required_permissions, $notifications->slack)) >=1)
|
|
||||||
// array_push($notifiable_methods, 'slack');
|
|
||||||
|
|
||||||
return $notifiable_methods;
|
return $notifiable_methods;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,12 @@ class AccountTest extends TestCase
|
|||||||
|
|
||||||
public function testApiAccountCreation()
|
public function testApiAccountCreation()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Account::all()->each(function($account) {
|
||||||
|
$account->delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'first_name' => $this->faker->firstName,
|
'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
'last_name' => $this->faker->lastName,
|
||||||
|
@ -20,8 +20,9 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Routing\Middleware\ThrottleRequests;
|
use Illuminate\Routing\Middleware\ThrottleRequests;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Validation\ValidationException;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Tests\MockAccountData;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,6 +33,7 @@ class ClientTest extends TestCase
|
|||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
use DatabaseTransactions;
|
use DatabaseTransactions;
|
||||||
|
use MockAccountData;
|
||||||
|
|
||||||
public function setUp() :void
|
public function setUp() :void
|
||||||
{
|
{
|
||||||
@ -51,38 +53,41 @@ class ClientTest extends TestCase
|
|||||||
$this->withoutMiddleware(
|
$this->withoutMiddleware(
|
||||||
ThrottleRequests::class
|
ThrottleRequests::class
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClientList()
|
public function testClientList()
|
||||||
{
|
{
|
||||||
$data = [
|
// $data = [
|
||||||
'first_name' => $this->faker->firstName,
|
// 'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
// 'last_name' => $this->faker->lastName,
|
||||||
'name' => $this->faker->company,
|
// 'name' => $this->faker->company,
|
||||||
'email' => $this->faker->unique()->safeEmail,
|
// 'email' => $this->faker->unique()->safeEmail,
|
||||||
'password' => 'ALongAndBrilliantPassword123',
|
// 'password' => 'ALongAndBrilliantPassword123',
|
||||||
'_token' => csrf_token(),
|
// '_token' => csrf_token(),
|
||||||
'privacy_policy' => 1,
|
// 'privacy_policy' => 1,
|
||||||
'terms_of_service' => 1
|
// 'terms_of_service' => 1
|
||||||
];
|
// ];
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
// $response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
// 'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
])->post('/api/v1/signup?include=account', $data);
|
// ])->post('/api/v1/signup?include=account', $data);
|
||||||
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
// $response->assertStatus(200);
|
||||||
|
|
||||||
$acc = $response->json();
|
// $acc = $response->json();
|
||||||
|
|
||||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
// $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
||||||
|
|
||||||
$token = $account->default_company->tokens->first()->token;
|
// $this->token = $account->default_company->tokens->first()->token;
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->get('/api/v1/clients');
|
])->get('/api/v1/clients');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -93,72 +98,34 @@ class ClientTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testClientRestEndPoints()
|
public function testClientRestEndPoints()
|
||||||
{
|
{
|
||||||
$data = [
|
|
||||||
'first_name' => $this->faker->firstName,
|
|
||||||
'last_name' => $this->faker->lastName,
|
|
||||||
'name' => $this->faker->company,
|
|
||||||
'email' => $this->faker->unique()->safeEmail,
|
|
||||||
'password' => 'ALongAndBrilliantPassword123',
|
|
||||||
'_token' => csrf_token(),
|
|
||||||
'privacy_policy' => 1,
|
|
||||||
'terms_of_service' => 1
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
factory(\App\Models\Client::class, 3)->create(['user_id' => $this->user->id, 'company_id' => $this->company->id])->each(function ($c){
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
|
||||||
])->post('/api/v1/signup?include=account', $data);
|
|
||||||
|
|
||||||
$acc = $response->json();
|
|
||||||
|
|
||||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
|
||||||
|
|
||||||
$company_token = $account->default_company->tokens()->first();
|
|
||||||
|
|
||||||
$token = $company_token->token;
|
|
||||||
$company = $company_token->company;
|
|
||||||
|
|
||||||
$user = $company_token->user;
|
|
||||||
|
|
||||||
//$company_user = $company->company_users()->first();
|
|
||||||
|
|
||||||
//$user = User::find($company_user->user_id);
|
|
||||||
$this->assertNotNull($company_token);
|
|
||||||
$this->assertNotNull($token);
|
|
||||||
$this->assertNotNull($user);
|
|
||||||
$this->assertNotNull($company);
|
|
||||||
//$this->assertNotNull($user->token->company);
|
|
||||||
|
|
||||||
factory(\App\Models\Client::class, 3)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company) {
|
|
||||||
factory(\App\Models\ClientContact::class, 1)->create([
|
factory(\App\Models\ClientContact::class, 1)->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $this->user->id,
|
||||||
'client_id' => $c->id,
|
'client_id' => $c->id,
|
||||||
'company_id' => $company->id,
|
'company_id' => $this->company->id,
|
||||||
'is_primary' => 1
|
'is_primary' => 1
|
||||||
]);
|
]);
|
||||||
|
|
||||||
factory(\App\Models\ClientContact::class, 2)->create([
|
factory(\App\Models\ClientContact::class, 2)->create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $this->user->id,
|
||||||
'client_id' => $c->id,
|
'client_id' => $c->id,
|
||||||
'company_id' => $company->id
|
'company_id' => $this->company->id
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$client = $account->default_company->clients()->first();
|
|
||||||
$client->load('contacts');
|
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id));
|
])->get('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id));
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id).'/edit');
|
])->get('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id).'/edit');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
@ -168,29 +135,29 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->put('/api/v1/clients/'.$this->encodePrimaryKey($client->id), $client_update)
|
])->put('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id), $client_update)
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->delete('/api/v1/clients/'.$this->encodePrimaryKey($client->id));
|
])->delete('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id));
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', ['name' => 'New Client'])
|
])->post('/api/v1/clients/', ['name' => 'New Client'])
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
|
|
||||||
$client->is_deleted = true;
|
$this->client->is_deleted = true;
|
||||||
$client->save();
|
$this->client->save();
|
||||||
|
|
||||||
|
|
||||||
$client_update = [
|
$client_update = [
|
||||||
@ -199,8 +166,8 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->put('/api/v1/clients/'.$this->encodePrimaryKey($client->id), $client_update)
|
])->put('/api/v1/clients/'.$this->encodePrimaryKey($this->client->id), $client_update)
|
||||||
->assertStatus(400);
|
->assertStatus(400);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +183,8 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$user = factory(\App\Models\User::class)->create([
|
$user = factory(\App\Models\User::class)->create([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'confirmation_code' => $this->createDbHash(config('database.default'))
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
||||||
|
'email' => 'whiz@gmail.com'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
@ -256,18 +224,18 @@ class ClientTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
$this->client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first();
|
||||||
|
|
||||||
$this->assertNotNull($client);
|
$this->assertNotNull($this->client);
|
||||||
|
|
||||||
/* Make sure we have a valid settings object*/
|
/* Make sure we have a valid settings object*/
|
||||||
$this->assertEquals($client->getSetting('timezone_id'), 1);
|
$this->assertEquals($this->client->getSetting('timezone_id'), 1);
|
||||||
|
|
||||||
/* Make sure we are harvesting valid data */
|
/* Make sure we are harvesting valid data */
|
||||||
$this->assertEquals($client->timezone()->name, 'Pacific/Midway');
|
$this->assertEquals($this->client->timezone()->name, 'Pacific/Midway');
|
||||||
|
|
||||||
/* Make sure NULL settings return the correct count (0) instead of throwing an exception*/
|
/* Make sure NULL settings return the correct count (0) instead of throwing an exception*/
|
||||||
$this->assertEquals($client->contacts->count(), 3);
|
$this->assertEquals($this->client->contacts->count(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -283,7 +251,9 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$user = factory(\App\Models\User::class)->create([
|
$user = factory(\App\Models\User::class)->create([
|
||||||
'account_id' => $account->id,
|
'account_id' => $account->id,
|
||||||
'confirmation_code' => $this->createDbHash(config('database.default'))
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
||||||
|
'email' => 'whiz@gmail.com'
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$user->companies()->attach($company->id, [
|
$user->companies()->attach($company->id, [
|
||||||
@ -305,7 +275,7 @@ class ClientTest extends TestCase
|
|||||||
$company_token->save();
|
$company_token->save();
|
||||||
|
|
||||||
|
|
||||||
$token = $company_token->token;
|
$this->token = $company_token->token;
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => 'A loyal Client',
|
'name' => 'A loyal Client',
|
||||||
@ -317,7 +287,7 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data)
|
])->post('/api/v1/clients/', $data)
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
@ -336,7 +306,7 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data)
|
])->post('/api/v1/clients/', $data)
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
@ -356,7 +326,7 @@ class ClientTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data);
|
])->post('/api/v1/clients/', $data);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||||
@ -378,7 +348,7 @@ class ClientTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data);
|
])->post('/api/v1/clients/', $data);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||||
@ -405,7 +375,7 @@ class ClientTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data);
|
])->post('/api/v1/clients/', $data);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||||
@ -417,12 +387,12 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
|
|
||||||
$client_id = $arr['data']['id'];
|
$this->client_id = $arr['data']['id'];
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->put('/api/v1/clients/' . $client_id, $data)->assertStatus(200);
|
])->put('/api/v1/clients/' . $this->client_id, $data)->assertStatus(200);
|
||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
|
|
||||||
@ -443,7 +413,7 @@ class ClientTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data);
|
])->post('/api/v1/clients/', $data);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||||
@ -454,9 +424,9 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
|
|
||||||
$client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
||||||
|
|
||||||
$contact = $client->contacts()->whereEmail($safe_email)->first();
|
$contact = $this->client->contacts()->whereEmail($safe_email)->first();
|
||||||
|
|
||||||
$this->assertEquals(0, strlen($contact->password));
|
$this->assertEquals(0, strlen($contact->password));
|
||||||
|
|
||||||
@ -477,7 +447,7 @@ class ClientTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post('/api/v1/clients/', $data);
|
])->post('/api/v1/clients/', $data);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||||
@ -488,9 +458,9 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
|
|
||||||
$client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
||||||
|
|
||||||
$contact = $client->contacts()->whereEmail($safe_email)->first();
|
$contact = $this->client->contacts()->whereEmail($safe_email)->first();
|
||||||
|
|
||||||
$this->assertGreaterThan(1, strlen($contact->password));
|
$this->assertGreaterThan(1, strlen($contact->password));
|
||||||
|
|
||||||
@ -512,8 +482,8 @@ class ClientTest extends TestCase
|
|||||||
try {
|
try {
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->put('/api/v1/clients/' . $client->hashed_id, $data);
|
])->put('/api/v1/clients/' . $this->client->hashed_id, $data);
|
||||||
} catch (ValidationException $e) {
|
} catch (ValidationException $e) {
|
||||||
$message = json_decode($e->validator->getMessageBag(), 1);
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
||||||
$this->assertNotNull($message);
|
$this->assertNotNull($message);
|
||||||
@ -523,58 +493,13 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$arr = $response->json();
|
$arr = $response->json();
|
||||||
|
|
||||||
$client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
$this->client = Client::find($this->decodePrimaryKey($arr['data']['id']));
|
||||||
$client->fresh();
|
$this->client->fresh();
|
||||||
|
|
||||||
$contact = $client->contacts()->whereEmail($safe_email)->first();
|
$contact = $this->client->contacts()->whereEmail($safe_email)->first();
|
||||||
|
|
||||||
$this->assertEquals($password, $contact->password);
|
$this->assertEquals($password, $contact->password);
|
||||||
}
|
}
|
||||||
/** @test */
|
|
||||||
// public function testMassivelyCreatingClients()
|
|
||||||
// {
|
|
||||||
// $data = [
|
|
||||||
// 'first_name' => $this->faker->firstName,
|
|
||||||
// 'last_name' => $this->faker->lastName,
|
|
||||||
// 'name' => $this->faker->company,
|
|
||||||
// 'email' => $this->faker->unique()->safeEmail,
|
|
||||||
// 'password' => 'ALongAndBrilliantPassword123',
|
|
||||||
// '_token' => csrf_token(),
|
|
||||||
// 'privacy_policy' => 1,
|
|
||||||
// 'terms_of_service' => 1
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $response = $this->withHeaders([
|
|
||||||
// 'X-API-SECRET' => config('ninja.api_secret'),
|
|
||||||
// ])->post('/api/v1/signup?include=account', $data);
|
|
||||||
|
|
||||||
// $response->assertStatus(200);
|
|
||||||
|
|
||||||
// $acc = $response->json();
|
|
||||||
|
|
||||||
// $account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
|
||||||
|
|
||||||
// $token = $account->default_company->tokens->first()->token;
|
|
||||||
|
|
||||||
// $body = [
|
|
||||||
// 'action' => 'create',
|
|
||||||
// 'clients' => [
|
|
||||||
// ['name' => $this->faker->firstName, 'website' => 'my-awesome-website-1.com'],
|
|
||||||
// ['name' => $this->faker->firstName, 'website' => 'my-awesome-website-2.com'],
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
|
|
||||||
// $response = $this->withHeaders([
|
|
||||||
// 'X-API-SECRET' => config('ninja.api_secret'),
|
|
||||||
// 'X-API-TOKEN' => $token,
|
|
||||||
// ])->post(route('clients.bulk'), $body);
|
|
||||||
|
|
||||||
// $response->assertStatus(200);
|
|
||||||
|
|
||||||
// $first_record = Client::where('website', 'my-awesome-website-1.com')->first();
|
|
||||||
// $second_record = Client::where('website', 'my-awesome-website-2.com')->first();
|
|
||||||
|
|
||||||
// $this->assertNotNull($first_record);
|
|
||||||
// $this->assertNotNull($second_record);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ use Illuminate\Http\UploadedFile;
|
|||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Tests\MockAccountData;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +29,7 @@ use Tests\TestCase;
|
|||||||
class CompanyTest extends TestCase
|
class CompanyTest extends TestCase
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
use MockAccountData;
|
||||||
|
|
||||||
use DatabaseTransactions;
|
use DatabaseTransactions;
|
||||||
|
|
||||||
@ -40,38 +42,17 @@ class CompanyTest extends TestCase
|
|||||||
$this->faker = \Faker\Factory::create();
|
$this->faker = \Faker\Factory::create();
|
||||||
|
|
||||||
Model::reguard();
|
Model::reguard();
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCompanyList()
|
public function testCompanyList()
|
||||||
{
|
{
|
||||||
$data = [
|
|
||||||
'first_name' => $this->faker->firstName,
|
|
||||||
'last_name' => $this->faker->lastName,
|
|
||||||
'name' => $this->faker->company,
|
|
||||||
'email' => $this->faker->unique()->safeEmail,
|
|
||||||
'password' => 'ALongAndBrilliantPassword123',
|
|
||||||
'_token' => csrf_token(),
|
|
||||||
'privacy_policy' => 1,
|
|
||||||
'terms_of_service' => 1
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
])->post('/api/v1/signup?include=account', $data);
|
'X-API-TOKEN' => $this->token,
|
||||||
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
|
|
||||||
$acc = $response->json();
|
|
||||||
|
|
||||||
$account = Account::find($this->decodePrimaryKey($acc['data'][0]['account']['id']));
|
|
||||||
|
|
||||||
$token = $account->default_company->tokens->first()->token;
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
|
||||||
'X-API-TOKEN' => $token,
|
|
||||||
])->get('/api/v1/companies');
|
])->get('/api/v1/companies');
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
@ -79,7 +60,7 @@ class CompanyTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post(
|
])->post(
|
||||||
'/api/v1/companies?include=company',
|
'/api/v1/companies?include=company',
|
||||||
[
|
[
|
||||||
@ -93,7 +74,7 @@ class CompanyTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->post(
|
])->post(
|
||||||
'/api/v1/companies/',
|
'/api/v1/companies/',
|
||||||
[
|
[
|
||||||
@ -105,7 +86,7 @@ class CompanyTest extends TestCase
|
|||||||
|
|
||||||
// Log::error($company);
|
// Log::error($company);
|
||||||
|
|
||||||
$token = CompanyToken::whereCompanyId($company->id)->first()->token;
|
$this->token = CompanyToken::whereCompanyId($company->id)->first()->token;
|
||||||
|
|
||||||
$company_update = [
|
$company_update = [
|
||||||
'name' => 'CHANGE NAME',
|
'name' => 'CHANGE NAME',
|
||||||
@ -114,7 +95,7 @@ class CompanyTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company_update)
|
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company_update)
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
@ -128,19 +109,19 @@ class CompanyTest extends TestCase
|
|||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company->toArray())
|
])->put('/api/v1/companies/'.$this->encodePrimaryKey($company->id), $company->toArray())
|
||||||
->assertStatus(200)->decodeResponseJson();
|
->assertStatus(200)->decodeResponseJson();
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->get('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
|
])->get('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
|
||||||
->assertStatus(200)->decodeResponseJson();
|
->assertStatus(200)->decodeResponseJson();
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $token,
|
'X-API-TOKEN' => $this->token,
|
||||||
])->delete('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
|
])->delete('/api/v1/companies/'.$this->encodePrimaryKey($company->id))
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,11 @@ class CreditTest extends TestCase
|
|||||||
|
|
||||||
public function testCreditsList()
|
public function testCreditsList()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Account::all()->each(function($account) {
|
||||||
|
$account->delete();
|
||||||
|
});
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'first_name' => $this->faker->firstName,
|
'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
'last_name' => $this->faker->lastName,
|
||||||
|
@ -44,6 +44,10 @@ class InvoiceTest extends TestCase
|
|||||||
|
|
||||||
public function testInvoiceList()
|
public function testInvoiceList()
|
||||||
{
|
{
|
||||||
|
Account::all()->each(function($account) {
|
||||||
|
$account->delete();
|
||||||
|
});
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'first_name' => $this->faker->firstName,
|
'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
'last_name' => $this->faker->lastName,
|
||||||
|
@ -56,13 +56,11 @@ class PreviewTest extends TestCase
|
|||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
'X-API-TOKEN' => $this->token
|
'X-API-TOKEN' => $this->token
|
||||||
])->post('/api/v1/preview', $data);
|
])->post('/api/v1/preview/', $data)->assertStatus(200);
|
||||||
|
|
||||||
|
|
||||||
$response->assertStatus(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +44,12 @@ class ProductTest extends TestCase
|
|||||||
|
|
||||||
public function testProductList()
|
public function testProductList()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Account::all()->each(function($account) {
|
||||||
|
$account->delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'first_name' => $this->faker->firstName,
|
'first_name' => $this->faker->firstName,
|
||||||
'last_name' => $this->faker->lastName,
|
'last_name' => $this->faker->lastName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user