|
16 | 16 |
|
17 | 17 | class BeatmapTagsControllerTest extends TestCase
|
18 | 18 | {
|
19 |
| - private Tag $tag; |
20 |
| - private Beatmap $beatmap; |
21 |
| - private BeatmapTag $beatmapTag; |
| 19 | + public static function dataProviderForUpdate(): array |
| 20 | + { |
| 21 | + return [ |
| 22 | + [0, null, true], |
| 23 | + [0, 0, true], |
| 24 | + [0, 1, false], |
| 25 | + ]; |
| 26 | + } |
22 | 27 |
|
23 |
| - public function testStore(): void |
| 28 | + public function testDestroy(): void |
24 | 29 | {
|
25 |
| - $user = User::factory() |
26 |
| - ->has(Score::factory()->state(['beatmap_id' => $this->beatmap]), 'soloScores') |
27 |
| - ->create(); |
| 30 | + $beatmapTag = BeatmapTag::factory()->create(); |
28 | 31 |
|
29 |
| - $this->expectCountChange(fn () => BeatmapTag::count(), 1); |
| 32 | + $this->expectCountChange(fn () => BeatmapTag::count(), -1); |
30 | 33 |
|
31 |
| - $this->actAsScopedUser($user); |
| 34 | + $this->actAsScopedUser($beatmapTag->user); |
32 | 35 | $this
|
33 |
| - ->put(route('api.beatmaps.tags.update', ['beatmap' => $this->beatmap->getKey(), 'tag' => $this->tag->getKey()])) |
| 36 | + ->delete(route('api.beatmaps.tags.destroy', ['beatmap' => $beatmapTag->beatmap_id, 'tag' => $beatmapTag->tag_id])) |
34 | 37 | ->assertSuccessful();
|
35 | 38 | }
|
36 | 39 |
|
37 |
| - public function testStoreNoScore(): void |
| 40 | + /** |
| 41 | + * @dataProvider dataProviderForUpdate |
| 42 | + */ |
| 43 | + public function testUpdate(int $beatmapRulesetId, ?int $tagRulesetId, bool $successful): void |
38 | 44 | {
|
39 |
| - $this->expectCountChange(fn () => BeatmapTag::count(), 0); |
| 45 | + $tag = Tag::factory()->state(['ruleset_id' => $tagRulesetId])->create(); |
| 46 | + $beatmap = Beatmap::factory()->state(['playmode' => $beatmapRulesetId])->create(); |
40 | 47 |
|
41 |
| - $this->actAsScopedUser(User::factory()->create()); |
42 |
| - $this |
43 |
| - ->put(route('api.beatmaps.tags.update', ['beatmap' => $this->beatmap->getKey(), 'tag' => $this->tag->getKey()])) |
44 |
| - ->assertForbidden(); |
45 |
| - } |
| 48 | + $user = User::factory() |
| 49 | + ->has(Score::factory()->state(['beatmap_id' => $beatmap]), 'soloScores') |
| 50 | + ->create(); |
46 | 51 |
|
47 |
| - public function testDestroy(): void |
48 |
| - { |
49 |
| - $this->expectCountChange(fn () => BeatmapTag::count(), -1); |
| 52 | + $this->expectCountChange(fn () => BeatmapTag::count(), $successful ? 1 : 0); |
50 | 53 |
|
51 |
| - $this->actAsScopedUser($this->beatmapTag->user); |
52 |
| - $this |
53 |
| - ->delete(route('api.beatmaps.tags.destroy', ['beatmap' => $this->beatmap->getKey(), 'tag' => $this->tag->getKey()])) |
54 |
| - ->assertSuccessful(); |
| 54 | + $this->actAsScopedUser($user); |
| 55 | + $request = $this->put(route('api.beatmaps.tags.update', ['beatmap' => $beatmap->getKey(), 'tag' => $tag->getKey()])); |
| 56 | + |
| 57 | + if ($successful) { |
| 58 | + $request->assertSuccessful(); |
| 59 | + } else { |
| 60 | + $request->assertStatus(422); |
| 61 | + } |
55 | 62 | }
|
56 | 63 |
|
57 |
| - protected function setUp(): void |
| 64 | + public function testUpdateNoScore(): void |
58 | 65 | {
|
59 |
| - parent::setUp(); |
60 |
| - |
61 |
| - $this->tag = Tag::factory()->create(); |
62 |
| - $this->beatmap = Beatmap::factory()->create(); |
63 |
| - $this->beatmapTag = BeatmapTag::factory()->create([ |
64 |
| - 'tag_id' => $this->tag, |
65 |
| - 'beatmap_id' => $this->beatmap, |
66 |
| - ]); |
| 66 | + $tag = Tag::factory()->create(); |
| 67 | + $beatmap = Beatmap::factory()->create(); |
| 68 | + |
| 69 | + $this->expectCountChange(fn () => BeatmapTag::count(), 0); |
| 70 | + |
| 71 | + $this->actAsScopedUser(User::factory()->create()); |
| 72 | + $this |
| 73 | + ->put(route('api.beatmaps.tags.update', ['beatmap' => $beatmap->getKey(), 'tag' => $tag->getKey()])) |
| 74 | + ->assertForbidden(); |
67 | 75 | }
|
68 | 76 | }
|
0 commit comments