-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWikiMetricsTest.php
More file actions
79 lines (67 loc) · 2.22 KB
/
WikiMetricsTest.php
File metadata and controls
79 lines (67 loc) · 2.22 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Tests\Metrics;
use App\Metrics\App\WikiMetrics;
use App\Wiki;
use App\WikiDailyMetrics;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class WikiMetricsTest extends TestCase
{
use RefreshDatabase;
public function testSuccessfullyAddRecords()
{
$wiki = Wiki::factory()->create([
'domain' => 'thisfake.wikibase.cloud'
]);
(new WikiMetrics())->saveMetrics($wiki);
// Assert the metric is updated in the database
$this->assertDatabaseHas('wiki_daily_metrics', [
'date' => now()->toDateString()
]);
}
public function testDoesNotAddDuplicateRecordsWithOnlyDateChange()
{
$wiki = Wiki::factory()->create([
'domain' => 'thisfake.wikibase.cloud'
]);
//Insert an old metric value for a wiki
WikiDailyMetrics::create([
'id' => $wiki->id. '_'. Carbon::yesterday()->toDateString(),
'wiki_id' => $wiki->id,
'date' => Carbon::yesterday()->toDateString(),
'pages' => 0,
'is_deleted' => 0
]);
(new WikiMetrics())->saveMetrics($wiki);
//Assert No new record was created for today
$this->assertDatabaseMissing('wiki_daily_metrics', [
'wiki_id' => $wiki->id,
'date' => Carbon::today()->toDateString()
]);
}
public function testAddRecordsWikiIsDeleted()
{
$wiki = Wiki::factory()->create([
'domain' => 'thisfake.wikibase.cloud'
]);
//Insert an old metric value for a wiki
WikiDailyMetrics::create([
'id' => $wiki->id. '_'. Carbon::yesterday()->toDateString(),
'wiki_id' => $wiki->id,
'date' => Carbon::yesterday()->toDateString(),
'pages' => 0,
'is_deleted' => 1
]);
//delete the wiki
$wiki->delete();
$wiki->save();
(new WikiMetrics())->saveMetrics($wiki);
//Assert No new record was created for today
$this->assertDatabaseMissing('wiki_daily_metrics', [
'wiki_id' => $wiki->id,
'is_deleted' => 1,
'date' => now()->toDateString()
]);
}
}