the browser-facing portion of osu!
at master 3.2 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace Tests\Controllers; 7 8use App\Libraries\MorphMap; 9use App\Models\Follow; 10use App\Models\User; 11use Tests\TestCase; 12 13class FollowsControllerTest extends TestCase 14{ 15 public function testDestroy() 16 { 17 $user = User::factory()->create(); 18 $mapper = User::factory()->create(); 19 20 Follow::create([ 21 'notifiable_id' => $mapper->getKey(), 22 'notifiable_type' => MorphMap::getType($mapper), 23 'subtype' => 'mapping', 24 'user_id' => $user->getKey(), 25 ]); 26 27 $initialCount = Follow::count(); 28 29 $this 30 ->actingAsVerified($user) 31 ->json('DELETE', route('follows.destroy'), [ 32 'follow' => [ 33 'notifiable_type' => MorphMap::getType($mapper), 34 'notifiable_id' => $mapper->getKey(), 35 'subtype' => 'mapping', 36 ], 37 ])->assertSuccessful(); 38 39 $this->assertSame(Follow::count(), $initialCount - 1); 40 } 41 42 public function testDestroyNonexistent() 43 { 44 $user = User::factory()->create(); 45 $mapper = User::factory()->create(); 46 47 $initialCount = Follow::count(); 48 49 $this 50 ->actingAsVerified($user) 51 ->json('DELETE', route('follows.destroy'), [ 52 'follow' => [ 53 'notifiable_type' => MorphMap::getType($mapper), 54 'notifiable_id' => $mapper->getKey(), 55 'subtype' => 'mapping', 56 ], 57 ])->assertSuccessful(); 58 59 $this->assertSame(Follow::count(), $initialCount); 60 } 61 62 public function testStore() 63 { 64 $user = User::factory()->create(); 65 $mapper = User::factory()->create(); 66 67 $initialCount = Follow::count(); 68 69 $this 70 ->actingAsVerified($user) 71 ->json('POST', route('follows.store'), [ 72 'follow' => [ 73 'notifiable_type' => MorphMap::getType($mapper), 74 'notifiable_id' => $mapper->getKey(), 75 'subtype' => 'mapping', 76 ], 77 ])->assertSuccessful(); 78 79 $this->assertSame(Follow::count(), $initialCount + 1); 80 } 81 82 public function testStoreDuplicate() 83 { 84 $user = User::factory()->create(); 85 $mapper = User::factory()->create(); 86 87 Follow::create([ 88 'notifiable_id' => $mapper->getKey(), 89 'notifiable_type' => MorphMap::getType($mapper), 90 'subtype' => 'mapping', 91 'user_id' => $user->getKey(), 92 ]); 93 94 $initialCount = Follow::count(); 95 96 $this 97 ->actingAsVerified($user) 98 ->json('POST', route('follows.store'), [ 99 'follow' => [ 100 'notifiable_type' => MorphMap::getType($mapper), 101 'notifiable_id' => $mapper->getKey(), 102 'subtype' => 'mapping', 103 ], 104 ])->assertSuccessful(); 105 106 $this->assertSame(Follow::count(), $initialCount); 107 } 108}