44
55use App \Metrics \App \WikiMetrics ;
66use App \Wiki ;
7+ use App \WikiDb ;
78use App \WikiDailyMetrics ;
9+ use App \Jobs \ProvisionWikiDbJob ;
810use Carbon \Carbon ;
911use Illuminate \Foundation \Testing \RefreshDatabase ;
1012use Tests \TestCase ;
@@ -13,25 +15,39 @@ class WikiMetricsTest extends TestCase
1315{
1416 use RefreshDatabase;
1517
18+ public function setUp (): void {
19+ parent ::setUp ();
20+ $ manager = $ this ->app ->make ('db ' );
21+ $ job = new ProvisionWikiDbJob ();
22+ $ job ->handle ($ manager );
23+ }
1624
1725 public function testSuccessfullyAddRecords ()
1826 {
1927 $ wiki = Wiki::factory ()->create ([
2028 'domain ' => 'thisfake.wikibase.cloud '
2129 ]);
2230
31+ $ wikiDb = WikiDb::first ();
32+ $ wikiDb ->update ( ['wiki_id ' => $ wiki ->id ] );
33+
2334 (new WikiMetrics ())->saveMetrics ($ wiki );
2435 // Assert the metric is updated in the database
2536 $ this ->assertDatabaseHas ('wiki_daily_metrics ' , [
2637 'date ' => now ()->toDateString ()
2738 ]);
2839 }
2940
41+
3042 public function testDoesNotAddDuplicateRecordsWithOnlyDateChange ()
3143 {
3244 $ wiki = Wiki::factory ()->create ([
3345 'domain ' => 'thisfake.wikibase.cloud '
3446 ]);
47+
48+ $ wikiDb = WikiDb::first ();
49+ $ wikiDb ->update ( ['wiki_id ' => $ wiki ->id ] );
50+
3551 //Insert an old metric value for a wiki
3652 WikiDailyMetrics::create ([
3753 'id ' => $ wiki ->id . '_ ' . Carbon::yesterday ()->toDateString (),
@@ -54,6 +70,10 @@ public function testAddRecordsWikiIsDeleted()
5470 $ wiki = Wiki::factory ()->create ([
5571 'domain ' => 'thisfake.wikibase.cloud '
5672 ]);
73+
74+ $ wikiDb = WikiDb::first ();
75+ $ wikiDb ->update ( ['wiki_id ' => $ wiki ->id ] );
76+
5777 //Insert an old metric value for a wiki
5878 WikiDailyMetrics::create ([
5979 'id ' => $ wiki ->id . '_ ' . Carbon::yesterday ()->toDateString (),
0 commit comments