test unified uploads
This commit is contained in:
parent
a2c3ffad8b
commit
b6da71ecd2
6 changed files with 144 additions and 27 deletions
|
|
@ -122,7 +122,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = $this->patchJson("/api/elements/{$element->getId()}", [
|
$response = $this->postJson("/api/elements/{$element->getId()}", [
|
||||||
'title' => 'Updated title',
|
'title' => 'Updated title',
|
||||||
'description' => 'Updated description',
|
'description' => 'Updated description',
|
||||||
'iconImageUrl' => '/assets/updated-icon.png',
|
'iconImageUrl' => '/assets/updated-icon.png',
|
||||||
|
|
@ -162,7 +162,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
$response = $this->withCredentials()
|
||||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||||
->patchJson("/api/elements/{$element->getId()}", [
|
->postJson("/api/elements/{$element->getId()}", [
|
||||||
'title' => 'Updated title',
|
'title' => 'Updated title',
|
||||||
'description' => 'Updated description',
|
'description' => 'Updated description',
|
||||||
'iconImageUrl' => '/assets/updated-icon.png',
|
'iconImageUrl' => '/assets/updated-icon.png',
|
||||||
|
|
@ -212,7 +212,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
"/api/elements/{$element->getId()}/icon-image",
|
"/api/elements/{$element->getId()}",
|
||||||
['iconImage' => $this->iconImageUpload()],
|
['iconImage' => $this->iconImageUpload()],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -247,7 +247,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
$response = $this->withCredentials()
|
$response = $this->withCredentials()
|
||||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||||
->post(
|
->post(
|
||||||
"/api/elements/{$element->getId()}/icon-image",
|
"/api/elements/{$element->getId()}",
|
||||||
['iconImage' => $this->iconImageUpload()],
|
['iconImage' => $this->iconImageUpload()],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -290,7 +290,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
));
|
));
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
"/api/elements/{$element->getId()}/pdf",
|
"/api/elements/{$element->getId()}",
|
||||||
['pdf' => $this->pdfUpload()],
|
['pdf' => $this->pdfUpload()],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -325,7 +325,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
$response = $this->withCredentials()
|
$response = $this->withCredentials()
|
||||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||||
->post(
|
->post(
|
||||||
"/api/elements/{$element->getId()}/pdf",
|
"/api/elements/{$element->getId()}",
|
||||||
['pdf' => $this->pdfUpload()],
|
['pdf' => $this->pdfUpload()],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -369,9 +369,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
|
|
||||||
private function iconImageUpload(): UploadedFile
|
private function iconImageUpload(): UploadedFile
|
||||||
{
|
{
|
||||||
$fixturePath = __DIR__
|
$fixturePath = __DIR__ . '/../fixtures/icon.png';
|
||||||
. '/../../../frontend/rabbi_gerzi/public/assets/'
|
|
||||||
. 'baderech-haavodah-icon.png';
|
|
||||||
|
|
||||||
return new UploadedFile(
|
return new UploadedFile(
|
||||||
$fixturePath,
|
$fixturePath,
|
||||||
|
|
@ -384,9 +382,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
|
|
||||||
private function pdfUpload(): UploadedFile
|
private function pdfUpload(): UploadedFile
|
||||||
{
|
{
|
||||||
$fixturePath = __DIR__
|
$fixturePath = __DIR__ . '/../fixtures/baderech.pdf';
|
||||||
. '/../../../frontend/rabbi_gerzi/public/assets/pdfs/'
|
|
||||||
. 'baderech.pdf';
|
|
||||||
|
|
||||||
return new UploadedFile(
|
return new UploadedFile(
|
||||||
$fixturePath,
|
$fixturePath,
|
||||||
|
|
|
||||||
|
|
@ -42,11 +42,6 @@ class ElementControllerTest extends TestCase
|
||||||
new UpdateRichText($this->elementRepo),
|
new UpdateRichText($this->elementRepo),
|
||||||
new UpdatePdfPath($this->elementRepo),
|
new UpdatePdfPath($this->elementRepo),
|
||||||
new UpdateYoutubeUrl($this->elementRepo),
|
new UpdateYoutubeUrl($this->elementRepo),
|
||||||
$this->elementRepo,
|
|
||||||
);
|
|
||||||
$this->controller = new ElementController(
|
|
||||||
$getElement,
|
|
||||||
$updateElement,
|
|
||||||
new UpdateElementIconImage(
|
new UpdateElementIconImage(
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
|
|
@ -55,6 +50,11 @@ class ElementControllerTest extends TestCase
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
),
|
),
|
||||||
|
$this->elementRepo,
|
||||||
|
);
|
||||||
|
$this->controller = new ElementController(
|
||||||
|
$getElement,
|
||||||
|
$updateElement,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +155,7 @@ class ElementControllerTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUploadIconImageReturnsElementPayload(): void
|
public function testUpdateWithIconImageReturnsElementPayload(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet(1, 'Baderech');
|
$set = $this->createSet(1, 'Baderech');
|
||||||
$element = $this->createElement(
|
$element = $this->createElement(
|
||||||
|
|
@ -168,9 +168,7 @@ class ElementControllerTest extends TestCase
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
$fixturePath = __DIR__
|
$fixturePath = __DIR__ . '/../../fixtures/icon.png';
|
||||||
. '/../../../../frontend/rabbi_gerzi/public/assets/'
|
|
||||||
. 'baderech-haavodah-icon.png';
|
|
||||||
$request = new Request([], [], [], [], [
|
$request = new Request([], [], [], [], [
|
||||||
'iconImage' => new UploadedFile(
|
'iconImage' => new UploadedFile(
|
||||||
$fixturePath,
|
$fixturePath,
|
||||||
|
|
@ -181,7 +179,7 @@ class ElementControllerTest extends TestCase
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->controller->uploadIconImage(
|
$response = $this->controller->update(
|
||||||
$element->getId(),
|
$element->getId(),
|
||||||
$request,
|
$request,
|
||||||
);
|
);
|
||||||
|
|
@ -199,7 +197,7 @@ class ElementControllerTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUploadPdfReturnsElementPayload(): void
|
public function testUpdateWithPdfReturnsElementPayload(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet(1, 'Baderech');
|
$set = $this->createSet(1, 'Baderech');
|
||||||
$element = $this->createElement(
|
$element = $this->createElement(
|
||||||
|
|
@ -212,9 +210,7 @@ class ElementControllerTest extends TestCase
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
$fixturePath = __DIR__
|
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
||||||
. '/../../../../frontend/rabbi_gerzi/public/assets/pdfs/'
|
|
||||||
. 'baderech.pdf';
|
|
||||||
$request = new Request([], [], [], [], [
|
$request = new Request([], [], [], [], [
|
||||||
'pdf' => new UploadedFile(
|
'pdf' => new UploadedFile(
|
||||||
$fixturePath,
|
$fixturePath,
|
||||||
|
|
@ -225,7 +221,7 @@ class ElementControllerTest extends TestCase
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response = $this->controller->uploadPdf(
|
$response = $this->controller->update(
|
||||||
$element->getId(),
|
$element->getId(),
|
||||||
$request,
|
$request,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use App\Element\Element;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateDescription;
|
use App\Element\UseCases\UpdateElement\UpdateDescription;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateElement;
|
use App\Element\UseCases\UpdateElement\UpdateElement;
|
||||||
|
use App\Element\UseCases\UpdateElement\UpdateElementIconImage;
|
||||||
|
use App\Element\UseCases\UpdateElement\UpdateElementPdf;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
|
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
|
||||||
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||||
|
|
@ -16,17 +18,21 @@ use App\Exceptions\BadRequestException;
|
||||||
use App\Exceptions\NotFoundException;
|
use App\Exceptions\NotFoundException;
|
||||||
use App\Set\Set as DomainSet;
|
use App\Set\Set as DomainSet;
|
||||||
use Tests\Fakes\FakeElementRepository;
|
use Tests\Fakes\FakeElementRepository;
|
||||||
|
use Tests\Fakes\FakeFileUploader;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UpdateElementTest extends TestCase
|
class UpdateElementTest extends TestCase
|
||||||
{
|
{
|
||||||
private FakeElementRepository $elementRepo;
|
private FakeElementRepository $elementRepo;
|
||||||
|
|
||||||
|
private FakeFileUploader $fileUploader;
|
||||||
|
|
||||||
private UpdateElement $updateElement;
|
private UpdateElement $updateElement;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->elementRepo = new FakeElementRepository();
|
$this->elementRepo = new FakeElementRepository();
|
||||||
|
$this->fileUploader = new FakeFileUploader();
|
||||||
$this->updateElement = new UpdateElement(
|
$this->updateElement = new UpdateElement(
|
||||||
new UpdateTitle($this->elementRepo),
|
new UpdateTitle($this->elementRepo),
|
||||||
new UpdateDescription($this->elementRepo),
|
new UpdateDescription($this->elementRepo),
|
||||||
|
|
@ -34,6 +40,14 @@ class UpdateElementTest extends TestCase
|
||||||
new UpdateRichText($this->elementRepo),
|
new UpdateRichText($this->elementRepo),
|
||||||
new UpdatePdfPath($this->elementRepo),
|
new UpdatePdfPath($this->elementRepo),
|
||||||
new UpdateYoutubeUrl($this->elementRepo),
|
new UpdateYoutubeUrl($this->elementRepo),
|
||||||
|
new UpdateElementIconImage(
|
||||||
|
$this->elementRepo,
|
||||||
|
$this->fileUploader,
|
||||||
|
),
|
||||||
|
new UpdateElementPdf(
|
||||||
|
$this->elementRepo,
|
||||||
|
$this->fileUploader,
|
||||||
|
),
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +75,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
pdfPath: '/assets/pdfs/updated.pdf',
|
pdfPath: '/assets/pdfs/updated.pdf',
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -115,6 +137,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
pdfPath: '',
|
pdfPath: '',
|
||||||
youtubeUrl: '',
|
youtubeUrl: '',
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -146,6 +176,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: null,
|
richText: null,
|
||||||
pdfPath: null,
|
pdfPath: null,
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -172,6 +210,58 @@ class UpdateElementTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdatesUploadedFiles(): void
|
||||||
|
{
|
||||||
|
$set = $this->createSet(1, 'Baderech');
|
||||||
|
$element = $this->createElement(
|
||||||
|
$set,
|
||||||
|
'Original title',
|
||||||
|
'Original description',
|
||||||
|
null,
|
||||||
|
'<p>Original rich text</p>',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
$updatedElement = $this->updateElement->execute(
|
||||||
|
new UpdateElementRequest(
|
||||||
|
id: $element->getId(),
|
||||||
|
title: null,
|
||||||
|
description: null,
|
||||||
|
iconImageUrl: null,
|
||||||
|
richText: null,
|
||||||
|
pdfPath: null,
|
||||||
|
youtubeUrl: null,
|
||||||
|
iconImageContents: 'binary-image-bytes',
|
||||||
|
iconImageOriginalName: 'icon.png',
|
||||||
|
iconImageMimeType: 'image/png',
|
||||||
|
iconImageSizeBytes: 1024,
|
||||||
|
pdfContents: 'binary-pdf-bytes',
|
||||||
|
pdfOriginalName: 'baderech.pdf',
|
||||||
|
pdfMimeType: 'application/pdf',
|
||||||
|
pdfSizeBytes: 1024,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'element-icons/fake-icon.png',
|
||||||
|
$updatedElement->getIconImageUrl(),
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
'element-pdfs/fake-baderech.pdf',
|
||||||
|
$updatedElement->getPdfPath(),
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
'element-icons',
|
||||||
|
$this->fileUploader->uploads[0]['folder'],
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
'element-pdfs',
|
||||||
|
$this->fileUploader->uploads[1]['folder'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testThrowsWhenIdMissing(): void
|
public function testThrowsWhenIdMissing(): void
|
||||||
{
|
{
|
||||||
$this->expectException(BadRequestException::class);
|
$this->expectException(BadRequestException::class);
|
||||||
|
|
@ -185,6 +275,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
pdfPath: null,
|
pdfPath: null,
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,6 +299,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: null,
|
richText: null,
|
||||||
pdfPath: null,
|
pdfPath: null,
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,6 +323,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
pdfPath: null,
|
pdfPath: null,
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,6 +347,14 @@ class UpdateElementTest extends TestCase
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
pdfPath: null,
|
pdfPath: null,
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
|
iconImageContents: null,
|
||||||
|
iconImageOriginalName: null,
|
||||||
|
iconImageMimeType: null,
|
||||||
|
iconImageSizeBytes: null,
|
||||||
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
backend/tests/fixtures/baderech.pdf
vendored
Normal file
BIN
backend/tests/fixtures/baderech.pdf
vendored
Normal file
Binary file not shown.
BIN
backend/tests/fixtures/icon.png
vendored
Normal file
BIN
backend/tests/fixtures/icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
|
|
@ -111,11 +111,13 @@ describe('admin element editing', () => {
|
||||||
cy.resetDb()
|
cy.resetDb()
|
||||||
loginAsAdmin()
|
loginAsAdmin()
|
||||||
cy.visit('/admin/element/1')
|
cy.visit('/admin/element/1')
|
||||||
|
cy.intercept('POST', /\/api\/elements\/1$/).as('updateElement')
|
||||||
|
|
||||||
cy.get('[data-cy="admin-element-icon-image-input"]').selectFile(
|
cy.get('[data-cy="admin-element-icon-image-input"]').selectFile(
|
||||||
'public/assets/baderech-haavodah-icon.png',
|
'public/assets/baderech-haavodah-icon.png',
|
||||||
{ force: true },
|
{ force: true },
|
||||||
)
|
)
|
||||||
|
cy.wait('@updateElement')
|
||||||
cy.get('[data-cy="admin-element-icon-image-status"]')
|
cy.get('[data-cy="admin-element-icon-image-status"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('contain.text', 'Icon image updated')
|
.and('contain.text', 'Icon image updated')
|
||||||
|
|
@ -128,6 +130,7 @@ describe('admin element editing', () => {
|
||||||
'public/assets/pdfs/baderech.pdf',
|
'public/assets/pdfs/baderech.pdf',
|
||||||
{ force: true },
|
{ force: true },
|
||||||
)
|
)
|
||||||
|
cy.wait('@updateElement')
|
||||||
cy.get('[data-cy="admin-element-pdf-status"]')
|
cy.get('[data-cy="admin-element-pdf-status"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('contain.text', 'PDF updated')
|
.and('contain.text', 'PDF updated')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue