Skip to content

Commit 20dab4d

Browse files
committed
Simplify tests
1 parent e871481 commit 20dab4d

File tree

1 file changed

+10
-72
lines changed

1 file changed

+10
-72
lines changed

tests/Unit/Models/ReportTemplates/ReportTemplateActivityLoggingTest.php

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,26 @@ class ReportTemplateActivityLoggingTest extends TestCase
1313
{
1414
public function testCreatingReportTemplateIsLogged()
1515
{
16-
$reportTemplate = ReportTemplate::factory()->create();
17-
1816
$user = User::factory()->create();
1917
$this->actingAs($user);
20-
$reportTemplateWithActingUser = ReportTemplate::factory()->create();
2118

22-
$this->assertDatabaseHas('action_logs', [
23-
'created_by' => null,
24-
'action_type' => 'created',
25-
'target_id' => null,
26-
'target_type' => null,
27-
'item_type' => ReportTemplate::class,
28-
'item_id' => $reportTemplate->id,
29-
]);
19+
$reportTemplate = ReportTemplate::factory()->create();
3020

3121
$this->assertDatabaseHas('action_logs', [
3222
'created_by' => $user->id,
3323
'action_type' => 'created',
3424
'target_id' => null,
3525
'target_type' => null,
3626
'item_type' => ReportTemplate::class,
37-
'item_id' => $reportTemplateWithActingUser->id,
27+
'item_id' => $reportTemplate->id,
3828
]);
3929
}
4030

4131
public function testUpdatingReportTemplateIsLogged()
4232
{
33+
$user = User::factory()->create();
34+
$this->actingAs($user);
35+
4336
$reportTemplate = ReportTemplate::factory()->create([
4437
'name' => 'Name A',
4538
'options' => [
@@ -58,27 +51,8 @@ public function testUpdatingReportTemplateIsLogged()
5851
],
5952
]);
6053

61-
$user = User::factory()->create();
62-
$this->actingAs($user);
63-
$reportTemplateWithActingUser = ReportTemplate::factory()->create([
64-
'name' => 'Name B',
65-
'options' => [
66-
'company' => '1',
67-
'location' => '1',
68-
'by_company_id' => ['1'],
69-
'by_location_id' => ['17'],
70-
],
71-
]);
72-
$reportTemplateWithActingUser->update([
73-
'name' => 'Something Else',
74-
'options' => [
75-
'company' => '1',
76-
'by_company_id' => ['1'],
77-
],
78-
]);
79-
8054
$this->assertDatabaseHas('action_logs', [
81-
'created_by' => null,
55+
'created_by' => $user->id,
8256
'action_type' => 'update',
8357
'target_id' => null,
8458
'target_type' => null,
@@ -103,60 +77,24 @@ public function testUpdatingReportTemplateIsLogged()
10377
],
10478
]),
10579
]);
106-
107-
$this->assertDatabaseHas('action_logs', [
108-
'created_by' => $user->id,
109-
'action_type' => 'update',
110-
'target_id' => null,
111-
'target_type' => null,
112-
'item_type' => ReportTemplate::class,
113-
'item_id' => $reportTemplateWithActingUser->id,
114-
'log_meta' => json_encode([
115-
'name' => [
116-
'old' => 'Name B',
117-
'new' => 'Something Else'
118-
],
119-
'options' => [
120-
'old' => [
121-
'company' => '1',
122-
'location' => '1',
123-
'by_company_id' => ['1'],
124-
'by_location_id' => ['17'],
125-
],
126-
'new' => [
127-
'company' => '1',
128-
'by_company_id' => ['1'],
129-
],
130-
],
131-
]),
132-
]);
13380
}
13481

13582
public function testDeletingReportTemplateIsLogged()
13683
{
13784
$user = User::factory()->create();
138-
[$reportTemplateA, $reportTemplateB] = ReportTemplate::factory()->count(2)->create();
139-
140-
$reportTemplateA->delete();
14185
$this->actingAs($user);
142-
$reportTemplateB->delete();
14386

144-
$this->assertDatabaseHas('action_logs', [
145-
'created_by' => null,
146-
'action_type' => 'delete',
147-
'target_id' => null,
148-
'target_type' => null,
149-
'item_type' => ReportTemplate::class,
150-
'item_id' => $reportTemplateA->id,
151-
]);
87+
$reportTemplate = ReportTemplate::factory()->create();
88+
89+
$reportTemplate->delete();
15290

15391
$this->assertDatabaseHas('action_logs', [
15492
'created_by' => $user->id,
15593
'action_type' => 'delete',
15694
'target_id' => null,
15795
'target_type' => null,
15896
'item_type' => ReportTemplate::class,
159-
'item_id' => $reportTemplateB->id,
97+
'item_id' => $reportTemplate->id,
16098
]);
16199
}
162100
}

0 commit comments

Comments
 (0)