Skip to content

Commit

Permalink
Merge pull request #8 from EscolaLMS/feature/nullable-desc
Browse files Browse the repository at this point in the history
Make description field nullable
  • Loading branch information
mako321 committed Apr 15, 2024
2 parents 5233be9 + 8c9fe32 commit 1961960
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

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

return new class extends Migration
{
public function up(): void
{
Schema::table('dictionary_words', function (Blueprint $table) {
$table->text('description')->nullable()->change();
});
}

public function down(): void
{
Schema::table('dictionary_words', function (Blueprint $table) {
$table->text('description')->nullable(false)->change();
});
}
};
2 changes: 1 addition & 1 deletion src/Imports/DictionaryWordsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function model(array $row): DictionaryWord
public function rules(): array
{
return [
'*.0' => ['required', 'string', 'max:255'],
'*.0' => ['required', 'max:255'],
'*.1' => ['nullable', 'string'],
'*.2' => ['nullable', 'array'],
'*.2.*' => ['string', 'exists:categories,name'],
Expand Down
17 changes: 17 additions & 0 deletions tests/Api/DictionaryWord/AdminCreateDictionaryWordApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,21 @@ public function testAdminCreateDictionaryWord(): void
])
->assertJsonCount(3, 'data.categories');
}

public function testAdminCreateDictionaryWordWithNullDescription(): void
{
$dictionaryWordData = DictionaryWord::factory()->make();
$this->actingAs($this->makeAdmin(), 'api')
->postJson('api/admin/dictionary-words', [
...$dictionaryWordData->toArray(),
'description' => null,
])
->assertCreated()
->assertJsonFragment([
'word' => $dictionaryWordData->word,
'dictionary_id' => $dictionaryWordData->dictionary_id,
'description' => null,
'data' => $dictionaryWordData->data,
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function testAdminImportDictionaryWordsValidation(): void
null,
true
),

])
->assertUnprocessable();
}
Expand Down

0 comments on commit 1961960

Please sign in to comment.