Skip to content

Commit

Permalink
ok generator there and working on html to text
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed May 28, 2023
1 parent 9e8c7e7 commit 4fa13c1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 27 deletions.
7 changes: 3 additions & 4 deletions app/Source/Types/WebFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace App\Source\Types;

use App\Models\Document;
use App\Exceptions\SourceMissingRequiredMetaDataException;
use App\Ingress\StatusEnum;
use App\Models\Document;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use App\Exceptions\SourceMissingRequiredMetaDataException;

class WebFile extends BaseSourceType
{
Expand All @@ -31,7 +30,7 @@ public function handle(): Document
],
[
'status' => StatusEnum::Complete,
'content' => $fileContents
'content' => $fileContents,
]
);

Expand Down
6 changes: 3 additions & 3 deletions app/Transformers/Types/Html2Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
namespace App\Transformers\Types;

use App\Models\Document;
use App\Models\Transformer;
use App\Models\DocumentChunk;
use Soundasleep\Html2Text as Helper;
use App\Models\Transformer;
use App\Transformers\BaseTransformer;
use Soundasleep\Html2Text as Helper;

class Html2Text extends BaseTransformer
{
public function handle(Transformer $transformer): Document
{
$filePath = $this->document->pathToFile();

if (str($this->document->guid)->endsWith(".html")) {
if (str($this->document->guid)->endsWith('.html')) {
if (! DocumentChunk::query()
->where('document_id', $this->document->id)
->exists()) {
Expand Down
6 changes: 3 additions & 3 deletions database/factories/DocumentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Database\Factories;

use App\Models\Source;
use App\Ingress\StatusEnum;
use App\Models\Source;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand Down Expand Up @@ -31,11 +31,11 @@ public function definition(): array
}

public function html()
{
{
return $this->state(function (array $attributes) {
return [
'content' => fake()->randomHtml(),
'guid' => "foo.html"
'guid' => 'foo.html',
];
});
}
Expand Down
11 changes: 4 additions & 7 deletions tests/Feature/Html2TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@

namespace Tests\Feature;

use Mockery;
use Tests\TestCase;
use App\Models\Document;
use App\Models\Transformer;
use Illuminate\Support\Facades\Http;
use App\Transformers\TransformerTypeEnum;
use App\Transformers\Types\Html2Text;
use Illuminate\Support\Facades\Storage;
use App\Transformers\TransformerTypeEnum;
use Tests\TestCase;

class Html2TextTest extends TestCase
{
use SharedSetupForPdfFile;

public function test_parses()
{
$document = Document::factory()->html()->create();

$transformerModel = Transformer::factory()->create([
'type' => TransformerTypeEnum::Html2Text,
]);

Storage::fake('projects');

$transformer = new Html2Text($document);
Expand All @@ -36,5 +34,4 @@ public function test_parses()
$this->assertNotNull($content);

}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use App\Models\User;
use App\Models\Project;
use App\Models\Transformer;
use App\Models\User;
use Illuminate\Support\Facades\Queue;
use function Pest\Laravel\assertDatabaseCount;

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/PdfTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Tests\Feature;

use Tests\TestCase;
use App\Models\Transformer;
use Illuminate\Support\Facades\File;
use App\Transformers\Types\PdfTransformer;
use Illuminate\Support\Facades\File;
use Tests\TestCase;

class PdfTransformerTest extends TestCase
{
Expand Down
11 changes: 4 additions & 7 deletions tests/Feature/WebFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@

namespace Tests\Feature;

use Mockery;
use Tests\TestCase;
use App\Models\Source;
use App\Models\Document;
use App\Models\Source;
use App\Source\Types\WebFile;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Mockery;
use Tests\TestCase;

class WebFileTest extends TestCase
{



public function test_gets_file()
{
$source = Source::factory()->webFileMetaData()->create();
Expand All @@ -32,7 +29,7 @@ public function test_gets_file()

$document = Document::first();

$this->assertEquals("foo", $document->content);
$this->assertEquals('foo', $document->content);

}

Expand Down

0 comments on commit 4fa13c1

Please sign in to comment.