Skip to content

Commit

Permalink
Create tests for PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
KoukiFactori committed Feb 10, 2023
1 parent 4593543 commit 85c9cbe
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/Api/Rating/RatingPutCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Tests\Api\Rating;

use App\Factory\UserFactory;
use App\Factory\RatingFactory;
use App\Factory\BookmarkFactory;
use App\Tests\Support\ApiTester;

class RatingPutCest
{
public function putRatingAnonymous(ApiTester $I)
{
RatingFactory::createOne();

$I->sendPut('/api/ratings/1', [
'user' => '/api/users/1',
'bookmark' => '/api/bookmarks/1',
'value' => 3,
]);

$I->seeResponseCodeIs(401);
}

public function putRatingNotOwning(ApiTester $I)
{
RatingFactory::createOne();

$user = UserFactory::createOne(['login' => 'user1'])->object();
$I->amLoggedInAs($user);

$I->sendPut('/api/ratings/1', [
'user' => '/api/users/1',
'bookmark' => '/api/bookmarks/1',
'value' => 10,
]);

$I->seeResponseCodeIs(403);
}

public function putRatingOwning(ApiTester $I)
{
$bookmark = BookmarkFactory::createOne();

$user = UserFactory::createOne(['login' => 'user1'])->object();
$I->amLoggedInAs($user);

RatingFactory::createOne([
'user' => $user,
'bookmark' => $bookmark
]);

$I->sendPut('/api/ratings/1', [
'user' => '/api/users/1',
'bookmark' => '/api/bookmarks/1',
'value' => 10
]);

$I->seeResponseCodeIs(200);
}
}

0 comments on commit 85c9cbe

Please sign in to comment.