Revert "Release 20200823.1100"

This commit is contained in:
shibafu
2020-08-23 12:28:21 +09:00
committed by GitHub
parent f377b143d2
commit 1b5f690f4e
71 changed files with 1200 additions and 4372 deletions

View File

@@ -1,148 +0,0 @@
<?php
namespace Tests\Feature\Api\Webhook;
use App\CheckinWebhook;
use App\Ejaculation;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Tests\TestCase;
class CheckinWebhookTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed();
Carbon::setTestNow('2020-07-21 19:19:19');
}
protected function tearDown(): void
{
parent::tearDown();
Carbon::setTestNow();
}
public function testSuccessful()
{
$user = factory(User::class)->create();
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
$response = $this->postJson('/api/webhooks/checkin/' . $webhook->id, [
'checked_in_at' => Carbon::create(2019, 7, 21, 19, 19, 19)->toIso8601String(),
'note' => 'test test test',
'link' => 'http://example.com',
'tags' => ['foo', 'bar'],
'is_private' => false,
'is_too_sensitive' => false,
]);
$response->assertStatus(200)
->assertJsonPath('status', 200);
$checkinId = $response->json('checkin.id');
$ejaculation = Ejaculation::find($checkinId);
$this->assertEquals(Carbon::create(2019, 7, 21, 19, 19, 0), $ejaculation->ejaculated_date);
$this->assertSame('test test test', $ejaculation->note);
$this->assertSame('http://example.com', $ejaculation->link);
$this->assertCount(2, $ejaculation->tags);
$this->assertFalse($ejaculation->is_private);
$this->assertFalse($ejaculation->is_too_sensitive);
$this->assertSame(Ejaculation::SOURCE_WEBHOOK, $ejaculation->source);
$this->assertNotEmpty($ejaculation->checkin_webhook_id);
}
public function testSuccessfulPrivateAndSensitive()
{
$user = factory(User::class)->create();
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
$response = $this->postJson('/api/webhooks/checkin/' . $webhook->id, [
'is_private' => true,
'is_too_sensitive' => true,
]);
$response->assertStatus(200)
->assertJsonPath('status', 200);
$checkinId = $response->json('checkin.id');
$ejaculation = Ejaculation::find($checkinId);
$this->assertTrue($ejaculation->is_private);
$this->assertTrue($ejaculation->is_too_sensitive);
$this->assertSame(Ejaculation::SOURCE_WEBHOOK, $ejaculation->source);
$this->assertNotEmpty($ejaculation->checkin_webhook_id);
}
public function testSuccessfulAllDefault()
{
$user = factory(User::class)->create();
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
$response = $this->postJson('/api/webhooks/checkin/' . $webhook->id);
$response->assertStatus(200)
->assertJsonPath('status', 200);
$checkinId = $response->json('checkin.id');
$ejaculation = Ejaculation::find($checkinId);
$this->assertEquals(Carbon::create(2020, 7, 21, 19, 19, 0), $ejaculation->ejaculated_date);
$this->assertEmpty($ejaculation->note);
$this->assertEmpty($ejaculation->link);
$this->assertEmpty($ejaculation->tags);
$this->assertFalse($ejaculation->is_private);
$this->assertFalse($ejaculation->is_too_sensitive);
$this->assertSame(Ejaculation::SOURCE_WEBHOOK, $ejaculation->source);
$this->assertNotEmpty($ejaculation->checkin_webhook_id);
}
public function testUserDestroyed()
{
$webhook = factory(CheckinWebhook::class)->create(['user_id' => null]);
$response = $this->postJson('/api/webhooks/checkin/' . $webhook->id);
$response->assertStatus(404)
->assertJsonPath('status', 404)
->assertJsonPath('error.message', 'The webhook is unavailable');
}
public function testValidationFailed()
{
$user = factory(User::class)->create();
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
$response = $this->postJson('/api/webhooks/checkin/' . $webhook->id, [
'checked_in_at' => new Carbon('1999-12-31T23:59:00+0900'),
'tags' => [
'Has spaces'
]
]);
$response->assertStatus(422)
->assertJsonPath('status', 422)
->assertJsonPath('error.message', 'Validation failed')
->assertJsonCount(2, 'error.violations');
}
public function testConflictCheckedInAt()
{
$user = factory(User::class)->create();
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
$ejaculatedDate = new Carbon('2020-07-21T19:19:00+0900');
factory(Ejaculation::class)->create([
'user_id' => $user->id,
'ejaculated_date' => $ejaculatedDate
]);
$response = $this->postJson('/api/webhooks/checkin/' . $webhook->id, [
'checked_in_at' => $ejaculatedDate,
]);
$response->assertStatus(422)
->assertJsonPath('status', 422)
->assertJsonPath('error.message', 'Checkin already exists in this time');
}
}

View File

@@ -1,75 +0,0 @@
<?php
namespace Tests\Feature\Setting;
use App\CheckinWebhook;
use App\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class WebhookTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed();
}
public function testStoreWebhooks()
{
$user = factory(User::class)->create();
$response = $this->actingAs($user)
->followingRedirects()
->post('/setting/webhooks', ['name' => 'example']);
$response->assertStatus(200)
->assertViewIs('setting.webhooks');
$this->assertDatabaseHas('checkin_webhooks', ['user_id' => $user->id, 'name' => 'example']);
}
public function testStoreWebhooksHas9Hooks()
{
$user = factory(User::class)->create();
$webhooks = factory(CheckinWebhook::class, CheckinWebhook::PER_USER_LIMIT - 1)->create(['user_id' => $user->id]);
$response = $this->actingAs($user)
->followingRedirects()
->post('/setting/webhooks', ['name' => 'example9']);
$response->assertStatus(200)
->assertViewIs('setting.webhooks');
$this->assertDatabaseHas('checkin_webhooks', ['user_id' => $user->id, 'name' => 'example9']);
}
public function testStoreWebhooksHas10Hooks()
{
$user = factory(User::class)->create();
$webhooks = factory(CheckinWebhook::class, CheckinWebhook::PER_USER_LIMIT)->create(['user_id' => $user->id]);
$response = $this->actingAs($user)
->followingRedirects()
->post('/setting/webhooks', ['name' => 'example10']);
$response->assertStatus(200)
->assertViewIs('setting.webhooks');
$this->assertDatabaseMissing('checkin_webhooks', ['user_id' => $user->id, 'name' => 'example10']);
}
public function testDestroyWebhooks()
{
$user = factory(User::class)->create();
$webhook = factory(CheckinWebhook::class)->create(['user_id' => $user->id]);
$response = $this->actingAs($user)
->followingRedirects()
->delete('/setting/webhooks/' . $webhook->id);
$response->assertStatus(200)
->assertViewIs('setting.webhooks')
->assertSee('削除しました');
$this->assertTrue($webhook->refresh()->trashed());
}
}

View File

@@ -277,48 +277,6 @@ class CheckinCsvImporterTest extends TestCase
$this->assertEquals(Ejaculation::SOURCE_CSV, $ejaculation->source);
}
public function testIsPrivateUTF8()
{
$user = factory(User::class)->create();
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/private.utf8.csv');
$importer->execute();
$ejaculations = $user->ejaculations()->orderBy('ejaculated_date')->get();
$this->assertSame(9, $ejaculations->count());
$this->assertTrue($ejaculations[0]->is_private);
$this->assertTrue($ejaculations[1]->is_private);
$this->assertTrue($ejaculations[2]->is_private);
$this->assertTrue($ejaculations[3]->is_private);
$this->assertFalse($ejaculations[4]->is_private);
$this->assertFalse($ejaculations[5]->is_private);
$this->assertFalse($ejaculations[6]->is_private);
$this->assertFalse($ejaculations[7]->is_private);
$this->assertFalse($ejaculations[8]->is_private);
}
public function testIsTooSensitiveUTF8()
{
$user = factory(User::class)->create();
$importer = new CheckinCsvImporter($user, __DIR__ . '/../../fixture/Csv/too-sensitive.utf8.csv');
$importer->execute();
$ejaculations = $user->ejaculations()->orderBy('ejaculated_date')->get();
$this->assertSame(9, $ejaculations->count());
$this->assertTrue($ejaculations[0]->is_too_sensitive);
$this->assertTrue($ejaculations[1]->is_too_sensitive);
$this->assertTrue($ejaculations[2]->is_too_sensitive);
$this->assertTrue($ejaculations[3]->is_too_sensitive);
$this->assertFalse($ejaculations[4]->is_too_sensitive);
$this->assertFalse($ejaculations[5]->is_too_sensitive);
$this->assertFalse($ejaculations[6]->is_too_sensitive);
$this->assertFalse($ejaculations[7]->is_too_sensitive);
$this->assertFalse($ejaculations[8]->is_too_sensitive);
}
public function testDontThrowUniqueKeyViolation()
{
$user = factory(User::class)->create();

View File

@@ -1,185 +0,0 @@
<?php
namespace Tests\Unit\Services;
use App\ContentProvider;
use App\MetadataResolver\MetadataResolver;
use App\MetadataResolver\ResolverCircuitBreakException;
use App\MetadataResolver\UncaughtResolverException;
use App\Services\MetadataResolveService;
use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Mockery\MockInterface;
use Tests\TestCase;
class MetadataResolverServiceTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->seed();
Carbon::setTestNow('2020-07-21 19:19:19');
// FIXME: 今書かれてるテストはresolveのHTTPリクエストのみを考慮しているので、ContentProviderにデータがないとリクエスト回数がずれる
factory(ContentProvider::class)->create();
}
protected function tearDown(): void
{
parent::tearDown();
Carbon::setTestNow();
}
public function testOnRuntimeException()
{
$this->mock(MetadataResolver::class, function (MockInterface $mock) {
$mock->shouldReceive('resolve')->andReturnUsing(function ($url) {
throw new \RuntimeException('Something happened!');
});
});
try {
$service = app()->make(MetadataResolveService::class);
$service->execute('http://example.com');
} catch (UncaughtResolverException $e) {
$this->assertDatabaseHas('metadata', [
'url' => 'http://example.com',
'error_at' => new Carbon('2020-07-21 19:19:19'),
'error_count' => 1,
'error_exception_class' => \RuntimeException::class,
'error_http_code' => null,
'error_body' => 'Something happened!',
]);
return;
}
$this->fail();
}
public function testOnHttpClientError()
{
$handler = HandlerStack::create(new MockHandler([new Response(404)]));
$client = new Client(['handler' => $handler]);
$this->instance(Client::class, $client);
try {
$service = app()->make(MetadataResolveService::class);
$service->execute('http://example.com');
} catch (UncaughtResolverException $e) {
$this->assertDatabaseHas('metadata', [
'url' => 'http://example.com',
'error_at' => new Carbon('2020-07-21 19:19:19'),
'error_count' => 1,
'error_exception_class' => ClientException::class,
'error_http_code' => 404,
]);
return;
}
$this->fail();
}
public function testOnHttpServerError()
{
$handler = HandlerStack::create(new MockHandler([new Response(503), new Response(503)]));
$client = new Client(['handler' => $handler]);
$this->instance(Client::class, $client);
try {
$service = app()->make(MetadataResolveService::class);
$service->execute('http://example.com');
} catch (UncaughtResolverException $e) {
$this->assertDatabaseHas('metadata', [
'url' => 'http://example.com',
'error_at' => new Carbon('2020-07-21 19:19:19'),
'error_count' => 1,
'error_exception_class' => ServerException::class,
'error_http_code' => 503,
]);
return;
}
$this->fail();
}
public function testCircuitBreak()
{
$this->mock(MetadataResolver::class, function (MockInterface $mock) {
$mock->shouldReceive('resolve')->andReturnUsing(function ($url) {
throw new \RuntimeException('Something happened!');
});
});
try {
for ($i = 0; $i < 6; $i++) {
try {
$service = app()->make(MetadataResolveService::class);
$service->execute('http://example.com');
} catch (UncaughtResolverException $e) {
}
}
} catch (ResolverCircuitBreakException $e) {
$this->assertDatabaseHas('metadata', [
'url' => 'http://example.com',
'error_at' => new Carbon('2020-07-21 19:19:19'),
'error_count' => 5,
'error_exception_class' => \RuntimeException::class,
'error_http_code' => null,
'error_body' => 'Something happened!',
]);
return;
}
$this->fail();
}
public function testOnResurrect()
{
$successBody = <<<HTML
<!doctype html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="og:title" content="OGP Title">
<meta name="og:description" content="OGP Description">
<title>Test Document</title>
</head>
<body>
</body>
</html>
HTML;
$handler = HandlerStack::create(new MockHandler([
new Response(404),
new Response(200, ['Content-Type' => 'text/html'], $successBody),
]));
$client = new Client(['handler' => $handler]);
$this->instance(Client::class, $client);
for ($i = 0; $i < 2; $i++) {
try {
$service = app()->make(MetadataResolveService::class);
$service->execute('http://example.com');
} catch (UncaughtResolverException $e) {
}
}
$this->assertDatabaseHas('metadata', [
'url' => 'http://example.com',
'title' => 'OGP Title',
'description' => 'OGP Description',
'image' => '',
'error_at' => null,
'error_count' => 0,
'error_exception_class' => null,
'error_http_code' => null,
'error_body' => null,
]);
}
}

View File

@@ -1,10 +0,0 @@
日時,非公開
2020/01/23 06:01:00,true
2020/01/23 06:02:00,TRUE
2020/01/23 06:03:00,True
2020/01/23 06:04:00,1
2020/01/23 07:01:00,false
2020/01/23 07:02:00,FALSE
2020/01/23 07:03:00,False
2020/01/23 07:04:00,0
2020/01/23 07:05:00,
1 日時 非公開
2 2020/01/23 06:01:00 true
3 2020/01/23 06:02:00 TRUE
4 2020/01/23 06:03:00 True
5 2020/01/23 06:04:00 1
6 2020/01/23 07:01:00 false
7 2020/01/23 07:02:00 FALSE
8 2020/01/23 07:03:00 False
9 2020/01/23 07:04:00 0
10 2020/01/23 07:05:00

View File

@@ -1,10 +0,0 @@
日時,センシティブ
2020/01/23 06:01:00,true
2020/01/23 06:02:00,TRUE
2020/01/23 06:03:00,True
2020/01/23 06:04:00,1
2020/01/23 07:01:00,false
2020/01/23 07:02:00,FALSE
2020/01/23 07:03:00,False
2020/01/23 07:04:00,0
2020/01/23 07:05:00,
1 日時 センシティブ
2 2020/01/23 06:01:00 true
3 2020/01/23 06:02:00 TRUE
4 2020/01/23 06:03:00 True
5 2020/01/23 06:04:00 1
6 2020/01/23 07:01:00 false
7 2020/01/23 07:02:00 FALSE
8 2020/01/23 07:03:00 False
9 2020/01/23 07:04:00 0
10 2020/01/23 07:05:00