DuplicateCommentTest.php
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace FootyRoom\Tests;
use Illuminate\Database\Connection;
class DuplicateCommentTest extends TestCase
{
use SetsUpFixtures;
public function setup()
{
parent::setup();
$this->mysql = $this->app->make(Connection::class);
}
public function testDuplicateCommentShouldThrowException()
{
$comments[] = [
'user_id' => 1,
'discussion_id' => 'forumPost:1',
'content' => 'i am cj',
'html' => 'i am cj',
'datetime' => date('Y-m-d H:i:s'),
'status' => 0,
'author' => 'chandu',
];
$this->mysql->table('comments')->insert($comments);
$user = factory('FootyRoom\User\User')->make(['user_id' => 1]);
$response = $this->actingAs($user)->call('POST', '/forum/comments', ['content' => 'i am cj', 'postId' => 1]);
$this->assertEquals(500, $response->status());
$this->assertContains('Seems like you have already posted a comment like that recently. Is this a duplicate? You might want to refresh the page to see your comment.', $response->getContent());
}
public function testDuplicateCommentAllowedIfAlreadyBeyondTimeLimit()
{
//time limit now is 30 seconds
$faker = \Faker\Factory::create();
$comments[] = [
'user_id' => 1,
'discussion_id' => 'forumPost:1',
'content' => 'i am chandu',
'html' => 'i am chandu',
'datetime' => $faker->date('Y-m-d H:i:s', '-1 hour'),
'status' => 0,
'author' => 'chandu',
];
$this->mysql->table('comments')->insert($comments);
$user = factory('FootyRoom\User\User')->make(['user_id' => 1]);
$response = $this->actingAs($user)->call('POST', '/forum/comments', ['content' => 'i am chandu', 'postId' => 1]);
$this->assertEquals(200, $response->status());
}
}