Skip to content

Commit

Permalink
Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Amitesh authored and Amitesh committed Aug 11, 2020
1 parent 2fd5a27 commit 0e90e1f
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 120 deletions.
39 changes: 31 additions & 8 deletions app/Imports/ImportServerDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,27 @@ class ImportServerDetail implements ToModel, WithHeadingRow
*/
public function model(array $row)
{
/**
* Todo - parse price and save as float and unit as seperate column
* Method already written - parsePrice
*/


/**
* Store server Details
* @param Model information
* @return Model object
*/
return new ServerDetail([
'model' => @$row['model'],
'ram' => @$row['ram'],
'hardisk' => @$row['hdd'],
'location' => @$row['location'],
'price' => $this->validateRam($row['price']),
'ram' => @$row['ram'],
'hardisk' => @$row['hdd'],
'location' => @$row['location'],
'price' => @$row['price'],
'hardisk_capacity_mb' => $this->capacityHardiskMB($row['hdd']),
'ram_capacity_mb' => $this->capacityRamMB($row['ram'])
]);
}


/**
* Return the integer version of hardisk size
* @param Hardisk value is string formate ex: 2x2TBSATA2
Expand All @@ -43,8 +52,8 @@ private function capacityHardiskMB($data)

/**
* Return the integer version of ram size
* @param Ram value is string formate ex: 16GBDDR3
* @return capacity in MB
* @param String Ram value is string formate ex: 16GBDDR3
* @return String capacity in MB
*/
private function capacityRamMB($data)
{
Expand All @@ -54,4 +63,18 @@ private function capacityRamMB($data)
return $capacity;
}
}

/**
* Return the integer version of ram size
* @param Prince value is string formate ex: 16GBDDR3
* @return Array
*/
private function parsePrice($data)
{
if (preg_match('(\€|\$|S\$)(\d*)(\.\d+)', $data, $m)) {
$priceData['unit'] = $m[1];
$priceData['price'] = $m[2] + $m[2];
return $priceData;
}
}
}
4 changes: 2 additions & 2 deletions app/Repositories/ServerDetailRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function fetchData($request) {
* @param Hardisk value is string formate ex: 2x2TBSATA2
* @return capacity in MB
*/
private function capacityHardiskMB($data)
public function capacityHardiskMB($data)
{
if (preg_match('/(\d+)x(\d+)(M|G|T)B/', $data, $m)) {
$capacity = $m[1];
Expand All @@ -74,7 +74,7 @@ private function capacityHardiskMB($data)
* @param Ram value is string formate ex: 16GBDDR3
* @return capacity in MB
*/
private function capacityRamMB($data)
public function capacityRamMB($data)
{
if (preg_match('/(\d+)(M|G|T)B/', $data, $m)) {
$capacity = $m[1];
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6400,7 +6400,7 @@ exports = module.exports = __webpack_require__(/*! ../../../../node_modules/css-


// module
exports.push([module.i, ".item2{\n background-color: red;\n}\n.filter-container { grid-area: filter-container; }\n.list-container { grid-area: list-container; }\n.count-container { grid-area: count-container;}\n\n.grid-main-container {\n display: grid;\n grid-template-areas:\n 'filter-container'\n 'count-container'\n 'list-container';\n grid-gap: 10px;\n background-color: #e8ecf1;\n padding: 10px;\n color: black;\n}\n\n.filter-container{\n padding: 0px 30px 20px 30px;\n}\n\n\n.list-header { grid-area: list-header; }\n.list-body { grid-area: list-body; }\n\n.list-container-dummy {\n display: grid;\n grid-template-areas:\n 'list-header'\n 'list-body';\n grid-gap: 20px;\n padding: 10px;\n color: #fff;\n background-color: #343a40;\n}\n.list-header {\n display: grid;\n grid-template-columns: 2fr repeat(4, 1fr);\n background: grey;\n color: white;\n font-weight: bold;\n height: 50px;\n align-items: center;\n}\n\n.list-body > div {\n display: grid;\n grid-template-columns: 2fr repeat(4, 1fr);\n height: 50px;\n}\n\n\n", ""]);
exports.push([module.i, ".item2{\n background-color: red;\n}\n.filter-container { grid-area: filter-container; }\n.list-container { grid-area: list-container; }\n.count-container { grid-area: count-container;}\n\n.grid-main-container {\n display: grid;\n grid-template-areas:\n 'filter-container'\n 'count-container'\n 'list-container';\n grid-gap: 10px;\n background-color: #e8ecf1;\n padding: 10px;\n color: black;\n}\n\n.filter-container{\n padding: 0px 30px 20px 30px;\n}\n\n\n.list-header { grid-area: list-header; }\n.list-body { grid-area: list-body; }\n\n.list-container-dummy {\n display: grid;\n grid-template-areas:\n 'list-header'\n 'list-body';\n grid-gap: 20px;\n padding: 10px;\n color: #fff;\n background-color: #343a40;\n margin: 0px 30px 0px 30px;\n}\n.list-header {\n display: grid;\n grid-template-columns: 2fr repeat(4, 1fr);\n background: grey;\n color: white;\n font-weight: bold;\n height: 50px;\n align-items: center;\n}\n\n.list-body > div {\n display: grid;\n grid-template-columns: 2fr repeat(4, 1fr);\n height: 50px;\n}\n\n\n", ""]);

// exports

Expand Down
1 change: 1 addition & 0 deletions resources/js/components/Main/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
padding: 10px;
color: #fff;
background-color: #343a40;
margin: 0px 30px 0px 30px;
}
.list-header {
display: grid;
Expand Down
104 changes: 104 additions & 0 deletions tests/Feature/ShowListTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use App\Model\ServerDetail;

class ShowServerDetailsControllerTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function testExample()
{
$response = $this->get('/');

$response->assertStatus(200);
}
/**
* fetch Data
**/
public function testshowData()
{

factory(ServerDetail::class)->create([
'id' => 1,
'model' => 'model1',
'ram' => 'ram1',
'hardisk' => 'hardisk1',
'location' => 'India1',
'price' => '$100',
'hardisk_capacity_mb' => 1000000,
'ram_capacity_mb' => 100000,
"created_at" => "2020-08-10T21:35:46.000000Z",
"updated_at" => "2020-08-10T21:35:46.000000Z"
]);

factory(ServerDetail::class)->create([
'id' => 2,
'model' => 'model2',
'ram' => 'ram2',
'hardisk' => 'hardisk2',
'location' => 'India2',
'price' => '$101',
'hardisk_capacity_mb' => 2000000,
'ram_capacity_mb' => 200000,
"created_at" => "2020-08-10T21:35:46.000000Z",
"updated_at" => "2020-08-10T21:35:46.000000Z"
]);

$response = $this->json('GET', '/api/v1/search')
->assertStatus(200)

//print_r($response->data); die;
->assertExactJson([ 'data' =>
[
[ 'id' => 1,
'model' => 'model1',
'ram' => 'ram1',
'hardisk' => 'hardisk1',
'location' => 'India1',
'price' => '$100',
'hardisk_capacity_mb' => 1000000,
'ram_capacity_mb' => 100000,
"created_at" => "2020-08-10T21:35:46.000000Z",
"updated_at" => "2020-08-10T21:35:46.000000Z"
],
[
'id' => 2,
'model' => 'model2',
'ram' => 'ram2',
'hardisk' => 'hardisk2',
'location' => 'India2',
'price' => '$101',
'hardisk_capacity_mb' => 2000000,
'ram_capacity_mb' => 200000,
"created_at" => "2020-08-10T21:35:46.000000Z",
"updated_at" => "2020-08-10T21:35:46.000000Z"
]
]
])
->assertJsonStructure(
[
'data' => [
'*' => [
'model',
'ram',
'hardisk',
'location',
'price',
'hardisk_capacity_mb',
'ram_capacity_mb',
'created_at',
'updated_at'
]
]
]
);
}
}
74 changes: 0 additions & 74 deletions tests/Feature/ShowServerDetailsControllerTest.php

This file was deleted.

35 changes: 0 additions & 35 deletions tests/Unit/ServerDetailControllerTest.php

This file was deleted.

51 changes: 51 additions & 0 deletions tests/Unit/ServerDetailRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Http\UploadedFile;
use Maatwebsite\Excel\Facades\Excel;
use App\Model\ServerDetail;
use App\Repositories\ServerDetailRepository;


class ServerDetailRepositoryTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function testExample()
{
$this->assertTrue(true);
}

/**
* Test Hardisk conversion to mb from string.
*
* @return void
*/

public function testCapacityHardiskMB(){

$repository = new \App\Repositories\ServerDetailRepository();
$response = $repository->capacityHardiskMB('2x500GBSATA2');

$this->assertEquals('1000000', $response);

}

/**
* Test RAM conversion to mb from string input.
*
* @return void
*/
public function testCapacityRamMB()
{
$repository = new \App\Repositories\ServerDetailRepository();
$response = $repository->capacityRamMB('16GBDDR3');
$this->assertEquals('16000', $response);

}
}

0 comments on commit 0e90e1f

Please sign in to comment.