Skip to content

Commit

Permalink
fixes and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Redjik committed Aug 14, 2015
1 parent da7e596 commit 8fe58b1
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 33 deletions.
6 changes: 3 additions & 3 deletions api/app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function login(Request $request)
}

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->item($token);
}

Expand All @@ -106,7 +106,7 @@ public function refresh()
$token = $this->jwtAuth->refresh($token);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->item($token);
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public function token(Request $request, User $userModel)
$token = $this->jwtAuth->fromUser($user);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->item($token);
}

Expand Down
10 changes: 5 additions & 5 deletions api/app/Http/Controllers/ChildEntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getAll($id)
$childEntities = $this->findAllChildren($model);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->collection($childEntities);
}

Expand All @@ -84,7 +84,7 @@ public function getOne($id, $childId)
$childModel = $this->findOrFailChildEntity($childId, $model);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->item($childModel);
}

Expand All @@ -106,7 +106,7 @@ public function postOne($id, Request $request)
$this->getRelation($model)->save($childModel);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdItem($childModel);
}

Expand All @@ -131,7 +131,7 @@ public function putOne($id, $childId, Request $request)
$this->getRelation($model)->save($childModel);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdItem($childModel);
}

Expand Down Expand Up @@ -178,7 +178,7 @@ public function putMany($id, Request $request)
$this->getRelation($model)->saveMany($childModels);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdCollection($childModels);
}

Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/CountriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Countries $countries, EloquentModelTransformer $tran
public function getAll()
{
return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->collection($this->countries->all());
}
}
12 changes: 6 additions & 6 deletions api/app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(BaseModel $model, TransformerInterface $transformer)
public function getAll()
{
return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->collection($this->getAllEntities());
}

Expand All @@ -56,7 +56,7 @@ public function getAllPaginated(PaginatedRequestDecoratorInterface $request)
$collection = $this->getAllEntities($limit, $offset);

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->paginatedCollection($collection, $offset, $count);
}

Expand All @@ -70,7 +70,7 @@ public function getOne($id)
{
$model = $this->findOrFailEntity($id);
return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->item($model)
;
}
Expand All @@ -89,7 +89,7 @@ public function postOne(Request $request)
$model->save();

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdItem($model);
}

Expand All @@ -112,7 +112,7 @@ public function putOne($id, Request $request)
$model->save();

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdItem($model);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ public function putMany(Request $request)
}

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdCollection($models);
}

Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/TimezoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Timezones $timezones, EloquentModelTransformer $tran
public function getAll()
{
return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->collection($this->timezones->all());
}
}
4 changes: 2 additions & 2 deletions api/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function putOne($id, Request $request)
}

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->createdItem($model);
}

Expand Down Expand Up @@ -230,7 +230,7 @@ public function getProfile($id)
}

return $this->getResponse()
->transformer($this->transformer)
->transformer($this->getTransformer())
->item($userProfile);
}
}
12 changes: 0 additions & 12 deletions api/app/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ abstract class BaseModel extends \Spira\Model\Model\BaseModel

public $incrementing = false;

/**
* @return ValidationFactory
*/
protected function getValidator()
{
if (is_null($this->validator)) {
$this->validator = \App::make('validator');
}

return $this->validator;
}

public static function getTableName()
{
return with(new static())->getTable();
Expand Down
40 changes: 37 additions & 3 deletions api/tests/integration/ArticleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testGetOne()
$this->assertTrue(is_string($object->permalink)||is_null($object->permalink));
}

public function testGetOneByPermalink()
public function testGetOneByFirstPermalink()
{
$entity = factory(Article::class)->create();
$this->addPermalinksToArticles([$entity]);
Expand Down Expand Up @@ -131,6 +131,35 @@ public function testGetOneByPermalink()
$this->assertTrue(is_string($object->permalink)||is_null($object->permalink));
}

public function testGetOneByLastPermalink()
{
$entity = factory(Article::class)->create();
$this->addPermalinksToArticles([$entity]);
$entity->push();

$permalink = $entity->permalinks->last();
$this->get('/articles/'.$permalink->permalink);

$this->assertResponseOk();
$this->shouldReturnJson();

$object = json_decode($this->response->getContent());

$this->assertTrue(is_object($object), 'Response is an object');

$this->assertObjectHasAttribute('_self', $object);
$this->assertTrue(is_string($object->_self), '_self is a string');

$this->assertObjectHasAttribute('articleId', $object);
$this->assertStringMatchesFormat('%x-%x-%x-%x-%x', $object->articleId);
$this->assertTrue(strlen($object->articleId) === 36, 'UUID has 36 chars');

$this->assertTrue(is_string($object->title));
$this->assertTrue(is_string($object->content));
$this->assertTrue(is_string($object->permalink)||is_null($object->permalink));
}


public function testPostOne()
{
$entity = factory(Article::class)->make();
Expand Down Expand Up @@ -296,25 +325,30 @@ public function testGetPermalinksNotFoundArticle()
public function testGetMetas()
{
$entity = factory(Article::class)->create();
$this->addPermalinksToArticles([$entity]);
$this->addMetasToArticles([$entity]);
$entity->push();

$count = ArticleMeta::where('article_id', '=', $entity->article_id)->count();

$this->get('/articles/'.$entity->article_id.'/meta');

$articleCheck = Article::find($entity->article_id);
$metaCheck = $articleCheck->metas->first();
$this->assertEquals($entity->article_id,$metaCheck->article->article_id);

$this->assertResponseOk();
$this->shouldReturnJson();

$object = json_decode($this->response->getContent());

$this->assertEquals(count($object), $count);

}

public function testPutMetas()
{
$article = factory(Article::class)->create();
$this->addPermalinksToArticles([$article]);
$this->addMetasToArticles([$article]);
$article->push();

$metaCount = ArticleMeta::where('article_id', '=', $article->article_id)->count();
Expand Down

0 comments on commit 8fe58b1

Please sign in to comment.