Skip to content

Commit cd63657

Browse files
authored
Merge pull request #16694 from r-xyz/api-files-notes
Fixed #16689: re-add `note` field in API files listing for AssetModel
2 parents 54f2b62 + 565b8f5 commit cd63657

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

app/Http/Transformers/AssetModelsTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function transformAssetModelFile($file, $assetmodel)
105105
$array = [
106106
'id' => (int) $file->id,
107107
'filename' => e($file->filename),
108+
'note' => $file->note,
108109
'url' => route('show/modelfile', [$assetmodel->id, $file->id]),
109110
'created_by' => ($file->adminuser) ? [
110111
'id' => (int) $file->adminuser->id,

tests/Feature/AssetModels/Api/AssetModelFilesTest.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,24 @@ public function testAssetModelApiDownloadsFile()
5959
// Create a superuser to run this as
6060
$user = User::factory()->superuser()->create();
6161

62-
//Upload a file
62+
// Upload a file
6363
$this->actingAsForApi($user)
6464
->post(
6565
route('api.models.files.store', ['model_id' => $model[0]["id"]]), [
66-
'file' => [UploadedFile::fake()->create("test.jpg", 100)]
66+
'file' => [UploadedFile::fake()->create("test.jpg", 100)],
67+
])
68+
->assertOk()
69+
->assertJsonStructure([
70+
'status',
71+
'messages',
72+
]);
73+
74+
// Upload a file with notes
75+
$this->actingAsForApi($user)
76+
->post(
77+
route('api.models.files.store', ['model_id' => $model[0]["id"]]), [
78+
'file' => [UploadedFile::fake()->create("test.jpg", 100)],
79+
'notes' => 'manual'
6780
])
6881
->assertOk()
6982
->assertJsonStructure([
@@ -75,7 +88,26 @@ public function testAssetModelApiDownloadsFile()
7588
$result = $this->actingAsForApi($user)
7689
->getJson(
7790
route('api.models.files.index', ['model_id' => $model[0]["id"]]))
78-
->assertOk();
91+
->assertOk()
92+
->assertJsonStructure([
93+
'total',
94+
'rows'=>[
95+
'*' => [
96+
'id',
97+
'filename',
98+
'url',
99+
'created_by',
100+
'created_at',
101+
'updated_at',
102+
'deleted_at',
103+
'note',
104+
'available_actions'
105+
]
106+
]
107+
])
108+
->assertJsonPath('rows.0.note','')
109+
->assertJsonPath('rows.1.note','manual');
110+
79111

80112

81113
// Get the file

0 commit comments

Comments
 (0)