LimitNumberOfDiscussionCreatedTest.php 1.18 KB
<?php

namespace FootyRoom\Tests;

class LimitNumberOfDiscussionCreatedTest extends TestCase
{
    use SetsUpFixtures;

    public function testUserShouldNotAllowedToCreateThreePostPerHour()
    {
        $faker = \Faker\Factory::create();

        $data = [
            'title' => $faker->sentence(),
            'content' => $faker->paragraph(),
            'category' => 53,
        ];

        // Already have 1 post while db setup in listener

        $user = factory('FootyRoom\User\User')->make(['user_id' => 1]);
        $response = $this->actingAs($user)->call('POST', '/forum/discussions', $data);
        $this->assertEquals(201, $response->status());

        $user = factory('FootyRoom\User\User')->make(['user_id' => 1]);
        $response = $this->actingAs($user)->call('POST', '/forum/discussions', $data);
        $this->assertEquals(201, $response->status());

        $user = factory('FootyRoom\User\User')->make(['user_id' => 1]);
        $response = $this->actingAs($user)->call('POST', '/forum/discussions', $data);
        $this->assertEquals(500, $response->status());
        $this->assertContains('Members can post in forum 3 times per hour.', $response->getContent());
    }
}