2017-02-21 14:26:46 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class ApiComponentsAssetsCest
|
|
|
|
{
|
|
|
|
protected $faker;
|
|
|
|
protected $user;
|
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// public function _before(ApiTester $I)
|
|
|
|
// {
|
|
|
|
// $this->faker = \Faker\Factory::create();
|
|
|
|
// $this->user = \App\Models\User::find(1);
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// $I->amBearerAuthenticated($I->getToken($this->user));
|
|
|
|
// }
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // /** @test */
|
|
|
|
// // public function indexComponentsAssets(ApiTester $I)
|
|
|
|
// // {
|
|
|
|
// // $I->wantTo('Get a list of assets related to a component');
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // // generate component
|
|
|
|
// // $component = factory(\App\Models\Component::class)
|
|
|
|
// // ->create(['user_id' => $this->user->id, 'qty' => 20]);
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // // generate assets and associate component
|
|
|
|
// // $assets = factory(\App\Models\Asset::class, 2)
|
|
|
|
// // ->create(['user_id' => $this->user->id])
|
|
|
|
// // ->each(function ($asset) use ($component) {
|
|
|
|
// // $component->assets()->attach($component->id, [
|
|
|
|
// // 'component_id' => $component->id,
|
|
|
|
// // 'user_id' => $this->user->id,
|
|
|
|
// // 'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
// // 'assigned_qty' => 2,
|
|
|
|
// // 'asset_id' => $asset->id
|
|
|
|
// // ]);
|
|
|
|
// // });
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // // verify
|
|
|
|
// // $I->sendGET('/components/' . $component->id . '/assets/');
|
|
|
|
// // $I->seeResponseIsJson();
|
|
|
|
// // $I->seeResponseCodeIs(200);
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // $response = json_decode($I->grabResponse());
|
|
|
|
// // $I->assertEquals(2, $response->total);
|
2017-02-23 16:32:35 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // $I->assertInstanceOf(\Illuminate\Database\Eloquent\Collection::class, $assets);
|
2017-02-21 14:26:46 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // $I->seeResponseContainsJson(['rows' => [
|
|
|
|
// // 0 => [
|
|
|
|
// // 'name' => $assets[0]->name,
|
|
|
|
// // 'id' => $assets[0]->id,
|
|
|
|
// // 'created_at' => $assets[0]->created_at->format('Y-m-d'),
|
|
|
|
// // ],
|
|
|
|
// // 1 => [
|
|
|
|
// // 'name' => $assets[1]->name,
|
|
|
|
// // 'id' => $assets[1]->id,
|
|
|
|
// // 'created_at' => $assets[1]->created_at->format('Y-m-d'),
|
|
|
|
// // ],
|
|
|
|
// // ]
|
|
|
|
// // ]);
|
|
|
|
// // }
|
2017-02-23 16:32:35 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // /** @test */
|
|
|
|
// // public function expectEmptyResponseWithoutAssociatedAssets(ApiTester $I, $scenario)
|
|
|
|
// // {
|
|
|
|
// // $I->wantTo('See an empty response when there are no associated assets to a component');
|
2017-02-23 16:32:35 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // $component = factory(\App\Models\Component::class)
|
|
|
|
// // ->create(['user_id' => $this->user->id, 'qty' => 20]);
|
2017-02-23 16:32:35 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // $I->sendGET('/components/' . $component->id . '/assets');
|
|
|
|
// // $I->seeResponseCodeIs(200);
|
|
|
|
// // $I->seeResponseIsJson();
|
2017-02-23 16:32:35 -08:00
|
|
|
|
2018-02-22 21:46:58 -08:00
|
|
|
// // $response = json_decode($I->grabResponse());
|
|
|
|
// // $I->assertEquals(0, $response->total);
|
|
|
|
// // $I->assertEquals([], $response->rows);
|
|
|
|
// // $I->seeResponseContainsJson(['total' => 0, 'rows' => []]);
|
|
|
|
// // }
|
2017-02-21 14:26:46 -08:00
|
|
|
}
|