Skip to content

Commit 9d6f574

Browse files
committed
Updated attachment tests to align with front-end changes
1 parent d41452f commit 9d6f574

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

tests/Uploads/AttachmentTest.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function uploadFile($name, $uploadedTo = 0)
3636
protected function deleteUploads()
3737
{
3838
$fileService = $this->app->make(\BookStack\Uploads\AttachmentService::class);
39-
foreach (\BookStack\Uploads\Attachment::all() as $file) {
39+
foreach (Attachment::all() as $file) {
4040
$fileService->deleteFile($file);
4141
}
4242
}
@@ -110,12 +110,12 @@ public function test_attaching_link_to_page()
110110
$this->asAdmin();
111111

112112
$linkReq = $this->call('POST', 'attachments/link', [
113-
'link' => 'https://example.com',
114-
'name' => 'Example Attachment Link',
115-
'uploaded_to' => $page->id,
113+
'attachment_link_url' => 'https://example.com',
114+
'attachment_link_name' => 'Example Attachment Link',
115+
'attachment_link_uploaded_to' => $page->id,
116116
]);
117117

118-
$expectedResp = [
118+
$expectedData = [
119119
'path' => 'https://example.com',
120120
'name' => 'Example Attachment Link',
121121
'uploaded_to' => $page->id,
@@ -127,8 +127,7 @@ public function test_attaching_link_to_page()
127127
];
128128

129129
$linkReq->assertStatus(200);
130-
$linkReq->assertJson($expectedResp);
131-
$this->assertDatabaseHas('attachments', $expectedResp);
130+
$this->assertDatabaseHas('attachments', $expectedData);
132131
$attachment = Attachment::orderBy('id', 'desc')->take(1)->first();
133132

134133
$pageGet = $this->get($page->getUrl());
@@ -147,28 +146,27 @@ public function test_attachment_updating()
147146
$this->asAdmin();
148147

149148
$this->call('POST', 'attachments/link', [
150-
'link' => 'https://example.com',
151-
'name' => 'Example Attachment Link',
152-
'uploaded_to' => $page->id,
149+
'attachment_link_url' => 'https://example.com',
150+
'attachment_link_name' => 'Example Attachment Link',
151+
'attachment_link_uploaded_to' => $page->id,
153152
]);
154153

155-
$attachmentId = \BookStack\Uploads\Attachment::first()->id;
154+
$attachmentId = Attachment::first()->id;
156155

157156
$update = $this->call('PUT', 'attachments/' . $attachmentId, [
158-
'uploaded_to' => $page->id,
159-
'name' => 'My new attachment name',
160-
'link' => 'https://test.example.com'
157+
'attachment_edit_name' => 'My new attachment name',
158+
'attachment_edit_url' => 'https://test.example.com'
161159
]);
162160

163-
$expectedResp = [
161+
$expectedData = [
162+
'id' => $attachmentId,
164163
'path' => 'https://test.example.com',
165164
'name' => 'My new attachment name',
166165
'uploaded_to' => $page->id
167166
];
168167

169168
$update->assertStatus(200);
170-
$update->assertJson($expectedResp);
171-
$this->assertDatabaseHas('attachments', $expectedResp);
169+
$this->assertDatabaseHas('attachments', $expectedData);
172170

173171
$this->deleteUploads();
174172
}
@@ -184,7 +182,7 @@ public function test_file_deletion()
184182
$filePath = storage_path($attachment->path);
185183
$this->assertTrue(file_exists($filePath), 'File at path ' . $filePath . ' does not exist');
186184

187-
$attachment = \BookStack\Uploads\Attachment::first();
185+
$attachment = Attachment::first();
188186
$this->delete($attachment->getUrl());
189187

190188
$this->assertDatabaseMissing('attachments', [

0 commit comments

Comments
 (0)