Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purchase Request Test Case #422

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/Console/Commands/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function handle()
return;
}

ini_set('memory_limit', '4095M');
ini_set('max_execution_time', '0');

$dbName = $this->argument('database_name') ?? env('DB_DATABASE');

$this->line('create '.$dbName.' database');
Expand Down Expand Up @@ -100,5 +103,6 @@ public function handle()
$projectUser->save();

Artisan::call('tenant:database:reset', ['project_code' => 'dev']);
$this->line('process completed');
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
"optimize-autoloader": true,
"process-timeout":0
}
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ services:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
networks:
- point_network
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'phpmyadmin'
restart: unless-stopped
links:
- db
ports:
- '80:80'
networks:
- point_network
networks:
Expand Down
5 changes: 5 additions & 0 deletions routes/api/purchase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
Route::post('requests/{id}/reject', 'PurchaseRequest\\PurchaseRequestApprovalController@reject');
Route::post('requests/{id}/cancellation-approve', 'PurchaseRequest\\PurchaseRequestCancellationApprovalController@approve');
Route::post('requests/{id}/cancellation-reject', 'PurchaseRequest\\PurchaseRequestCancellationApprovalController@reject');
Route::post('requests/{id}/close', 'PurchaseRequest\\PurchaseRequestCloseController@close');
// Route::post('requests/{id}/close-approve', 'PurchaseRequest\\PurchaseRequestCloseController@approve');
// Route::post('requests/{id}/close-reject', 'PurchaseRequest\\PurchaseRequestCloseController@reject');
Route::post('requests/send-bulk-request-approval', 'PurchaseRequest\\PurchaseRequestController@sendBulkRequestApproval');
Route::post('requests/approval-with-token/bulk', 'PurchaseRequest\\PurchaseRequestApprovalController@bulkApprovalWithToken');
Route::apiResource('requests', 'PurchaseRequest\\PurchaseRequestController');
Route::post('orders/{id}/approve', 'PurchaseOrder\\PurchaseOrderApprovalController@approve');
Route::post('orders/{id}/reject', 'PurchaseOrder\\PurchaseOrderApprovalController@reject');
Expand Down
209 changes: 209 additions & 0 deletions tests/Feature/Http/Purchase/Request/PurchaseRequestApprovalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
<?php

namespace Tests\Feature\Http\Purchase\Request;

use Tests\TestCase;
use App\Model\Token;

class PurchaseRequestApprovalTest extends TestCase
{
use PurchaseRequestSetup;

public function success_create_purchase_request()
{
$data = $this->createDataPurchaseRequest();

$response = $this->json('POST', self::$path, $data, $this->headers);

// save data
$this->purchase = json_decode($response->getContent())->data;
}

/** @test */
public function unauthorized_reject_purchase_request()
{
$this->success_create_purchase_request();
$this->unsetUserRole();

$data = [
'id' => $this->purchase->id,
'reason' => 'reason'
];

$response = $this->json('POST', self::$path.'/'.$this->purchase->id.'/reject', $data, $this->headers);

$response->assertStatus(422)
->assertJson([
"code" => 422,
"message" => "Unauthorized"
]);
}

/** @test */
public function failed_reject_purchase_request()
{
//create purchase request and save to $this->purchase
$this->success_create_purchase_request();

$data = [
'id' => $this->purchase->id,
];

$response = $this->json('POST', self::$path.'/'.$this->purchase->id.'/reject', $data, $this->headers);
$response->assertStatus(422)->assertJson([
"code" => 422,
"message" => "The given data was invalid."
]);
}

/** @test */
public function success_reject_purchase_request()
{
//create purchase request and save to $this->purchase
$this->success_create_purchase_request();
/* s: reject test */
$data = [
'id' => $this->purchase->id,
'reason' => 'reason'
];

$response = $this->json('POST', self::$path.'/'.$this->purchase->id.'/reject', $data, $this->headers);
$response->assertStatus(200);
/* e: reject test */
}

/** @test */
public function unauthorized_approve_purchase_request()
{
$this->success_create_purchase_request();
$this->unsetUserRole();

$response = $this->json('POST', self::$path . '/' . $this->purchase->id . '/approve', [], $this->headers);

$response->assertStatus(422)
->assertJson([
"code" => 422,
"message" => "Unauthorized"
]);
}

/** @test */
public function success_approve_purchase_request()
{
//create purchase request and save to $this->purchase
$this->success_create_purchase_request();
/* s: reject test */
$data = [
'id' => $this->purchase->id
];

$response = $this->json('POST', self::$path.'/'.$this->purchase->id.'/approve', $data, $this->headers);
$response->assertStatus(200);
/* e: reject test */
}

/** @test */
public function failed_request_approval_by_email_purchase_request()
{
//create purchase request and save to $this->purchase
$this->success_create_purchase_request();

$response = $this->json('POST', self::$path.'/send-bulk-request-approval', [], $this->headers);
$response->assertStatus(422);
}

/** @test */
public function success_request_approval_by_email_purchase_request()
{
//create purchase request and save to $this->purchase
$this->success_create_purchase_request();

/* s: send request approval email */
$data = [
'bulk_id'=> array($this->purchase->id),
'tenant_url' => 'http://dev.localhost:8080'
];

$response = $this->json('POST', self::$path.'/send-bulk-request-approval', $data, $this->headers);
$response->assertStatus(204);
/* e: send request approval email */
}

/** @test */
public function failed_approval_by_email_purchase_request()
{
$this->success_request_approval_by_email_purchase_request();

/* s: bulk approval email fail test */
$data = [
'token' => 'NGAWUR',
'bulk_id' => array($this->purchase->id),
'status' => -1
];

$response = $this->json('POST', self::$path.'/approval-with-token/bulk', $data, $this->headers);
$response->assertStatus(422)->assertJson([
"code" => 422,
"message" => "Not Authorized"
]);
/* e: bulk approval email fail test */
}

/** @test */
public function success_reject_by_email_purchase_request()
{
$this->success_request_approval_by_email_purchase_request();

/* s: bulk approval email test */
$token = Token::where('user_id', $this->user->id)->first();
$data = [
'token' => $token->token,
'bulk_id' => array($this->purchase->id),
'status' => -1
];

$response = $this->json('POST', self::$path.'/approval-with-token/bulk', $data, $this->headers);
$response->assertStatus(200);
/* e: bulk approval email test */
}

/** @test */
public function success_approve_by_email_purchase_request()
{
$this->success_request_approval_by_email_purchase_request();

/* s: bulk approval email test */
$token = Token::where('user_id', $this->user->id)->first();
$data = [
'token' => $token->token,
'bulk_id' => array($this->purchase->id),
'status' => 1
];

$response = $this->json('POST', self::$path.'/approval-with-token/bulk', $data, $this->headers);
$response->assertStatus(200);
/* e: bulk approval email test */
}

/** @test */
public function failed_approve_by_email_purchase_request_not_default_branch()
{
$this->success_request_approval_by_email_purchase_request();
$this->setDefaultBranch(false);

/* s: bulk approval email test */
$token = Token::where('user_id', $this->user->id)->first();
$data = [
'token' => $token->token,
'bulk_id' => array($this->purchase->id),
'status' => 1
];

$response = $this->json('POST', self::$path.'/approval-with-token/bulk', $data, $this->headers);
$response->assertStatus(422)->assertJson([
'code' => 422,
'message' => 'Please set as default branch',
]);
/* e: bulk approval email test */
}
}
Loading