Skip to content

Commit

Permalink
oops seems I never added meta_data to Transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Jun 17, 2023
1 parent c8648da commit ecccde4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@ class JsonTransformerTransformerController extends BaseTransformerController
{
public function create(Project $project)
{
Transformer::create([
$transformer = Transformer::create([
'type' => TransformerEnum::JsonTransformer,
'order' => $project->transformers->count() + 1,
'project_id' => $project->id,
'meta_data' => [
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
]
]);

request()->session()->flash('flash.banner', 'Created, you can sort the order using drag and drop');

return to_route('transformers.json_transformer.edit',
[
'project' => $project->id,
'transformer' => $transformer->id
]
);
}

public function edit(Project $project, Transformer $transformer)
{
request()->session()->flash('flash.banner', 'There is no edit for this');

return to_route('projects.show', ['project' => $project->id]);
}

Expand Down
1 change: 1 addition & 0 deletions app/Models/Transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Transformer extends BaseTypeModel
protected $casts = [
'prompt_token' => 'encrypted:array',
'type' => TransformerEnum::class,
'meta_data' => "encrypted:array"
];

public function project()
Expand Down
12 changes: 12 additions & 0 deletions database/factories/TransformerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public function definition(): array
'prompt_token' => [],
'type' => TransformerEnum::PdfTransformer,
'project_id' => Project::factory(),
'meta_data' => [
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
]
];
}

Expand All @@ -40,6 +46,12 @@ public function json()
return $this->state(function (array $attributes) {
return [
'type' => TransformerEnum::JsonTransformer,
'meta_data' => [
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
]
];
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('transformers', function (Blueprint $table) {
$table->longText("meta_data")->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('transformers', function (Blueprint $table) {
//
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ public function test_show_form_for_json_transformer()
->get(route('transformers.json_transformer.create', [
'project' => $project->id,
]))
->assertRedirect(route('projects.show', [
'project' => $project->id,
]));
->assertRedirect(route('transformers.json_transformer.edit',
[
'project' => $project->id,
'transformer' => Transformer::first()->id
]));
}

public function test_allow_edit_json_transformer()
{
$this->markTestSkipped('@TODO there will be a mapping edit soon');
$user = User::factory()->withPersonalTeam()->create();
$user = $this->createTeam($user);

$project = Project::factory()->create([
'team_id' => $user->current_team_id,
]);

$transformer = Transformer::factory()->create([
$transformer = Transformer::factory()->json()->create([
'project_id' => $project->id,
]);

Expand Down
15 changes: 12 additions & 3 deletions tests/Feature/Models/TransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ class TransformerTest extends TestCase

public function test_transformer_factory()
{
$this->webFileDownloadSetup();
$model = Transformer::factory()->create();
$model = Transformer::factory()->json()->create();
$this->assertNotNull($model->project->id);
$this->assertNotNull($model->project->transformers->first()->id);
$this->assertEquals(TransformerEnum::PdfTransformer, $model->type);
$this->assertEquals(TransformerEnum::JsonTransformer, $model->type);

$this->assertEquals(
[
'mappings' => [
'optional.path.to.store_one',
'optional.path.to.store_two',
]
],
$model->meta_data
);
}

public function test_runs_transformers()
Expand Down

0 comments on commit ecccde4

Please sign in to comment.