Skip to content

Commit

Permalink
remove invalid createReview(), add new incomplete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jul 28, 2024
1 parent 69880f8 commit 3dcf91f
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions tests/api/ReviewsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ final class ReviewsTest extends TestCase
use TestHelper;
use APIHelper;

private Review $dummy_review;

public static function setUpBeforeClass(): void
{
self::initFaker();
Expand All @@ -40,34 +38,32 @@ public function onNotSuccessfulTest(Throwable $t): never
parent::onNotSuccessfulTest($t);
}

/**
* @throws Exception
*/
public function setUp(): void
public function tearDown(): void
{
$this->dummy_review = self::createReview();
self::resetDatabase();
}

public function tearDown(): void
public function testCreateReview()
{
self::resetDatabase();
self::markTestIncomplete('TODO');
}

/**
* @throws GuzzleException
* @throws Exception
*/
public function testUpdateReview()
{
$review = self::createReview(self::createProduct(), self::createClient(), 4);

// Create new review data
$newData = [
'text' => 'Updated review text',
'rating' => 4,
'client_id' => $this->dummy_review->getClientID(),
'product_id' => $this->dummy_review->getProductID(),
];

// Send PUT request to update the review
$response = self::$guzzle->put('reviews/' . $this->dummy_review->getReviewID(), [
$response = self::$guzzle->put('reviews/' . $review->getReviewID(), [
'json' => $newData,
]);

Expand All @@ -79,28 +75,26 @@ public function testUpdateReview()
// Check if the update was successful
$this->assertEquals('Review updated successfully', $json['message']);

// Fetch the updated review
$response = self::$guzzle->get('reviews/' . $this->dummy_review->getReviewID());
$this->assertEquals(200, $response->getStatusCode());

$updatedReview = json_decode($response->getBody()->getContents(), true);
// Fetch the review from the database
$saved_review = Review::getByID($review->getReviewID());

// Verify the review was updated
$this->assertEquals($newData['text'], $updatedReview['text']);
$this->assertEquals($newData['rating'], $updatedReview['rating']);
$this->assertEquals($newData['text'], $saved_review->getText());
$this->assertEquals($newData['rating'], $saved_review->getRating());

// ensure that all other attributes did not change
assertEquals($review->getReviewID(), $saved_review->getReviewID());
assertEquals($review->getProductID(), $saved_review->getProductID());
assertEquals($review->getClientID(), $saved_review->getClientID());

$this->assertEquals(
$review->getCreatedDate()->format('Y-m-d'),
$saved_review->getCreatedDate()->format('Y-m-d')
);
}

// Helper function to create a review for testing
private static function createReview(): Review
public function testDeleteReview()
{
$review = new Review(
null,
self::$faker->randomDigitNotNull,
self::$faker->randomDigitNotNull,
self::$faker->text(100),
self::$faker->numberBetween(1, 5)
);
$review->save();
return $review;
self::markTestIncomplete('TODO');
}
}

0 comments on commit 3dcf91f

Please sign in to comment.