Add test for the GetLink endpoints

This commit is contained in:
Daniel_I_Am 2020-08-29 13:33:23 +02:00
parent 4722d74ad8
commit d0ca2ae497
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84

View File

@ -0,0 +1,86 @@
<?php
namespace Tests\Unit;
use App\Http\Controllers\LodestoneLinkController;
use App\LinkCode;
use App\Services\CodeGeneratorService;
use App\Services\LodestoneApiService;
use App\Services\LodestoneCacheService;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
class LodestoneLinkTest extends TestCase
{
use DatabaseTransactions;
private $lodestoneId = 29778775;
private $server = 'Siren';
private $name = 'Jisva Fralgo';
private $websiteName = 'ffxivhelix.com';
private $websiteId = 6;
private $discordGuildId = 618857558740041738;
private $discordUserId = 208258599565262848;
private $lodestoneLinkController;
protected function setUp(): void {
parent::setUp();
$this->lodestoneLinkController = new LodestoneLinkController(
new CodeGeneratorService(),
new LodestoneCacheService(),
new LodestoneApiService()
);
}
public function testGetLinkCodeByDiscordAndId()
{
LinkCode::where('lodestoneId', $this->lodestoneId)->delete();
$response = $this->lodestoneLinkController->checkDiscordId($this->lodestoneId, $this->discordGuildId, $this->discordUserId);
$this->assertDatabaseHas('link_codes', [
'lodestoneId' => $this->lodestoneId,
'code' => $response['linkCode']
]);
}
public function testGetLinkCodeByDiscordAndName()
{
LinkCode::where('lodestoneId', $this->lodestoneId)->delete();
$response = $this->lodestoneLinkController->checkDiscordName($this->server, $this->name, $this->discordGuildId, $this->discordUserId);
$this->assertDatabaseHas('link_codes', [
'lodestoneId' => $this->lodestoneId,
'code' => $response['linkCode']
]);
}
public function testGetLinkCodeByWebsiteAndId()
{
LinkCode::where('lodestoneId', $this->lodestoneId)->delete();
$response = $this->lodestoneLinkController->checkWebsiteId($this->lodestoneId, $this->websiteName, $this->websiteId);
$this->assertDatabaseHas('link_codes', [
'lodestoneId' => $this->lodestoneId,
'code' => $response['linkCode']
]);
}
public function testGetLinkCodeByWebsiteAndName()
{
LinkCode::where('lodestoneId', $this->lodestoneId)->delete();
$response = $this->lodestoneLinkController->checkWebsiteName($this->server, $this->name, $this->websiteName, $this->websiteId);
$this->assertDatabaseHas('link_codes', [
'lodestoneId' => $this->lodestoneId,
'code' => $response['linkCode']
]);
}
}