|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Routes\Backend; |
| 4 | + |
| 5 | +use App\Wiki; |
| 6 | +use App\WikiDb; |
| 7 | +use Illuminate\Foundation\Testing\RefreshDatabase; |
| 8 | +use Tests\TestCase; |
| 9 | + |
| 10 | +class MediaWikiHostsControllerTest extends TestCase { |
| 11 | + use RefreshDatabase; |
| 12 | + |
| 13 | + protected $route = '/backend/getWikiHostsForDomain'; |
| 14 | + |
| 15 | + public function testSuccess() { |
| 16 | + $expectedHosts = [ |
| 17 | + 'backend' => 'mediawiki-143-app-backend.default.svc.cluster.local', |
| 18 | + 'web' => 'mediawiki-143-app-web.default.svc.cluster.local', |
| 19 | + 'api' => 'mediawiki-143-app-api.default.svc.cluster.local', |
| 20 | + 'alpha' => 'mediawiki-143-app-alpha.default.svc.cluster.local', |
| 21 | + ]; |
| 22 | + |
| 23 | + $this->createWiki('test139.wikibase.cloud', 'mw1.39-wbs1'); |
| 24 | + $this->createWiki('test143.wikibase.cloud', 'mw1.43-wbs1'); |
| 25 | + |
| 26 | + $this->getJson("$this->route?domain=test143.wikibase.cloud") |
| 27 | + ->assertStatus(200) |
| 28 | + ->assertHeader('x-backend-host', $expectedHosts['backend']) |
| 29 | + ->assertHeader('x-web-host', $expectedHosts['web']) |
| 30 | + ->assertHeader('x-api-host', $expectedHosts['api']) |
| 31 | + ->assertHeader('x-alpha-host', $expectedHosts['alpha']) |
| 32 | + ->assertJson([ |
| 33 | + 'domain' => 'test143.wikibase.cloud', |
| 34 | + 'backend-host' => $expectedHosts['backend'], |
| 35 | + 'web-host' => $expectedHosts['web'], |
| 36 | + 'api-host' => $expectedHosts['api'], |
| 37 | + 'alpha-host' => $expectedHosts['alpha'], |
| 38 | + ]); |
| 39 | + } |
| 40 | + |
| 41 | + public function testDomainNotfound() { |
| 42 | + $this->getJson("$this->route?domain=notfound.wikibase.cloud") |
| 43 | + ->assertStatus(404); |
| 44 | + } |
| 45 | + |
| 46 | + public function testUnknownDbVersion() { |
| 47 | + $this->createWiki('test.wikibase.cloud', 'unknownVersion'); |
| 48 | + |
| 49 | + $this->getJson("$this->route?domain=test.wikibase.cloud") |
| 50 | + ->assertStatus(500); |
| 51 | + } |
| 52 | + |
| 53 | + private function createWiki(string $domain, string $version) { |
| 54 | + $wiki = Wiki::factory()->create(['domain' => $domain]); |
| 55 | + WikiDb::create([ |
| 56 | + 'name' => $domain, |
| 57 | + 'user' => 'someUser', |
| 58 | + 'password' => 'somePassword', |
| 59 | + 'version' => $version, |
| 60 | + 'prefix' => 'somePrefix', |
| 61 | + 'wiki_id' => $wiki->id, |
| 62 | + ]); |
| 63 | + } |
| 64 | +} |
0 commit comments