Compare commits
No commits in common. "3db7b9d98f8113a561bcab0b1e6964ab53316471" and "14d2ce2284fa4bb86ed3220bf6f1236322a2b4ef" have entirely different histories.
3db7b9d98f
...
14d2ce2284
41 changed files with 639 additions and 1582 deletions
|
|
@ -57,7 +57,8 @@ class ElementController
|
||||||
|
|
||||||
public function update(Request $request): JsonResponse
|
public function update(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$file = $this->uploadedFileInput($request, 'file');
|
$iconImage = $this->uploadedFileInput($request, 'iconImage');
|
||||||
|
$pdf = $this->uploadedFileInput($request, 'pdf');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$element = $this->updateElement->execute(
|
$element = $this->updateElement->execute(
|
||||||
|
|
@ -70,14 +71,16 @@ class ElementController
|
||||||
'iconImageUrl',
|
'iconImageUrl',
|
||||||
),
|
),
|
||||||
richText: $this->stringInput($request, 'richText'),
|
richText: $this->stringInput($request, 'richText'),
|
||||||
shortPdfPath: $this->stringInput($request, 'shortPdfPath'),
|
pdfPath: $this->stringInput($request, 'pdfPath'),
|
||||||
longPdfPath: $this->stringInput($request, 'longPdfPath'),
|
|
||||||
youtubeUrl: $this->stringInput($request, 'youtubeUrl'),
|
youtubeUrl: $this->stringInput($request, 'youtubeUrl'),
|
||||||
fileType: $this->stringInput($request, 'fileType'),
|
iconImageContents: $iconImage['contents'],
|
||||||
fileContents: $file['contents'],
|
iconImageOriginalName: $iconImage['originalName'],
|
||||||
fileOriginalName: $file['originalName'],
|
iconImageMimeType: $iconImage['mimeType'],
|
||||||
fileMimeType: $file['mimeType'],
|
iconImageSizeBytes: $iconImage['sizeBytes'],
|
||||||
fileSizeBytes: $file['sizeBytes'],
|
pdfContents: $pdf['contents'],
|
||||||
|
pdfOriginalName: $pdf['originalName'],
|
||||||
|
pdfMimeType: $pdf['mimeType'],
|
||||||
|
pdfSizeBytes: $pdf['sizeBytes'],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} catch (BadRequestException $exception) {
|
} catch (BadRequestException $exception) {
|
||||||
|
|
@ -173,8 +176,7 @@ class ElementController
|
||||||
* description: string,
|
* description: string,
|
||||||
* iconImageUrl: string|null,
|
* iconImageUrl: string|null,
|
||||||
* richText: string,
|
* richText: string,
|
||||||
* shortPdfPath: string|null,
|
* pdfPath: string|null,
|
||||||
* longPdfPath: string|null,
|
|
||||||
* youtubeUrl: string|null,
|
* youtubeUrl: string|null,
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
@ -189,12 +191,8 @@ class ElementController
|
||||||
'element-icons/',
|
'element-icons/',
|
||||||
),
|
),
|
||||||
'richText' => $element->getRichText(),
|
'richText' => $element->getRichText(),
|
||||||
'shortPdfPath' => $this->storageUrl(
|
'pdfPath' => $this->storageUrl(
|
||||||
$element->getShortPdfPath(),
|
$element->getPdfPath(),
|
||||||
'element-pdfs/',
|
|
||||||
),
|
|
||||||
'longPdfPath' => $this->storageUrl(
|
|
||||||
$element->getLongPdfPath(),
|
|
||||||
'element-pdfs/',
|
'element-pdfs/',
|
||||||
),
|
),
|
||||||
'youtubeUrl' => $element->getYoutubeUrl(),
|
'youtubeUrl' => $element->getYoutubeUrl(),
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ class CreateElementDto
|
||||||
public string $description,
|
public string $description,
|
||||||
public ?string $iconImageUrl,
|
public ?string $iconImageUrl,
|
||||||
public string $richText,
|
public string $richText,
|
||||||
public ?string $shortPdfPath,
|
public ?string $pdfPath,
|
||||||
public ?string $longPdfPath,
|
|
||||||
public ?string $youtubeUrl,
|
public ?string $youtubeUrl,
|
||||||
public ?Element $parentElement,
|
public ?Element $parentElement,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ class Element
|
||||||
private string $description,
|
private string $description,
|
||||||
private ?string $iconImageUrl,
|
private ?string $iconImageUrl,
|
||||||
private string $richText,
|
private string $richText,
|
||||||
private ?string $shortPdfPath,
|
private ?string $pdfPath,
|
||||||
private ?string $longPdfPath,
|
|
||||||
private ?string $youtubeUrl,
|
private ?string $youtubeUrl,
|
||||||
private Set $set,
|
private Set $set,
|
||||||
private ?Element $parentElement,
|
private ?Element $parentElement,
|
||||||
|
|
@ -65,24 +64,14 @@ class Element
|
||||||
$this->richText = $richText;
|
$this->richText = $richText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getShortPdfPath(): ?string
|
public function getPdfPath(): ?string
|
||||||
{
|
{
|
||||||
return $this->shortPdfPath;
|
return $this->pdfPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setShortPdfPath(?string $shortPdfPath): void
|
public function setPdfPath(?string $pdfPath): void
|
||||||
{
|
{
|
||||||
$this->shortPdfPath = $shortPdfPath;
|
$this->pdfPath = $pdfPath;
|
||||||
}
|
|
||||||
|
|
||||||
public function getLongPdfPath(): ?string
|
|
||||||
{
|
|
||||||
return $this->longPdfPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setLongPdfPath(?string $longPdfPath): void
|
|
||||||
{
|
|
||||||
$this->longPdfPath = $longPdfPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getYoutubeUrl(): ?string
|
public function getYoutubeUrl(): ?string
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @property string $description
|
* @property string $description
|
||||||
* @property string|null $icon_image_url
|
* @property string|null $icon_image_url
|
||||||
* @property string $rich_text
|
* @property string $rich_text
|
||||||
* @property string|null $short_pdf_path
|
* @property string|null $pdf_path
|
||||||
* @property string|null $long_pdf_path
|
|
||||||
* @property string|null $youtube_url
|
* @property string|null $youtube_url
|
||||||
* @property int|null $parent_element_id
|
* @property int|null $parent_element_id
|
||||||
*
|
*
|
||||||
|
|
@ -27,8 +26,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
* @method static Builder<static>|ElementModel whereDescription($value)
|
* @method static Builder<static>|ElementModel whereDescription($value)
|
||||||
* @method static Builder<static>|ElementModel whereIconImageUrl($value)
|
* @method static Builder<static>|ElementModel whereIconImageUrl($value)
|
||||||
* @method static Builder<static>|ElementModel whereRichText($value)
|
* @method static Builder<static>|ElementModel whereRichText($value)
|
||||||
* @method static Builder<static>|ElementModel whereShortPdfPath($value)
|
* @method static Builder<static>|ElementModel wherePdfPath($value)
|
||||||
* @method static Builder<static>|ElementModel whereLongPdfPath($value)
|
|
||||||
* @method static Builder<static>|ElementModel whereYoutubeUrl($value)
|
* @method static Builder<static>|ElementModel whereYoutubeUrl($value)
|
||||||
*
|
*
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
|
|
@ -45,8 +43,7 @@ class ElementModel extends Model
|
||||||
'description',
|
'description',
|
||||||
'icon_image_url',
|
'icon_image_url',
|
||||||
'rich_text',
|
'rich_text',
|
||||||
'short_pdf_path',
|
'pdf_path',
|
||||||
'long_pdf_path',
|
|
||||||
'youtube_url',
|
'youtube_url',
|
||||||
'parent_element_id',
|
'parent_element_id',
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@ class EloquentElementRepository implements ElementRepository
|
||||||
'description' => $dto->description,
|
'description' => $dto->description,
|
||||||
'icon_image_url' => $dto->iconImageUrl,
|
'icon_image_url' => $dto->iconImageUrl,
|
||||||
'rich_text' => $dto->richText,
|
'rich_text' => $dto->richText,
|
||||||
'short_pdf_path' => $dto->shortPdfPath,
|
'pdf_path' => $dto->pdfPath,
|
||||||
'long_pdf_path' => $dto->longPdfPath,
|
|
||||||
'youtube_url' => $dto->youtubeUrl,
|
'youtube_url' => $dto->youtubeUrl,
|
||||||
'parent_element_id' => $dto->parentElement?->getId(),
|
'parent_element_id' => $dto->parentElement?->getId(),
|
||||||
]);
|
]);
|
||||||
|
|
@ -32,8 +31,7 @@ class EloquentElementRepository implements ElementRepository
|
||||||
description: $dto->description,
|
description: $dto->description,
|
||||||
iconImageUrl: $dto->iconImageUrl,
|
iconImageUrl: $dto->iconImageUrl,
|
||||||
richText: $dto->richText,
|
richText: $dto->richText,
|
||||||
shortPdfPath: $dto->shortPdfPath,
|
pdfPath: $dto->pdfPath,
|
||||||
longPdfPath: $dto->longPdfPath,
|
|
||||||
youtubeUrl: $dto->youtubeUrl,
|
youtubeUrl: $dto->youtubeUrl,
|
||||||
set: $dto->set,
|
set: $dto->set,
|
||||||
parentElement: $dto->parentElement,
|
parentElement: $dto->parentElement,
|
||||||
|
|
@ -54,8 +52,7 @@ class EloquentElementRepository implements ElementRepository
|
||||||
$model->description = $element->getDescription();
|
$model->description = $element->getDescription();
|
||||||
$model->icon_image_url = $element->getIconImageUrl();
|
$model->icon_image_url = $element->getIconImageUrl();
|
||||||
$model->rich_text = $element->getRichText();
|
$model->rich_text = $element->getRichText();
|
||||||
$model->short_pdf_path = $element->getShortPdfPath();
|
$model->pdf_path = $element->getPdfPath();
|
||||||
$model->long_pdf_path = $element->getLongPdfPath();
|
|
||||||
$model->youtube_url = $element->getYoutubeUrl();
|
$model->youtube_url = $element->getYoutubeUrl();
|
||||||
$model->parent_element_id = $element->getParentElement()?->getId();
|
$model->parent_element_id = $element->getParentElement()?->getId();
|
||||||
$model->save();
|
$model->save();
|
||||||
|
|
@ -140,8 +137,7 @@ class EloquentElementRepository implements ElementRepository
|
||||||
description: $model->description,
|
description: $model->description,
|
||||||
iconImageUrl: $model->icon_image_url,
|
iconImageUrl: $model->icon_image_url,
|
||||||
richText: $model->rich_text,
|
richText: $model->rich_text,
|
||||||
shortPdfPath: $model->short_pdf_path,
|
pdfPath: $model->pdf_path,
|
||||||
longPdfPath: $model->long_pdf_path,
|
|
||||||
youtubeUrl: $model->youtube_url,
|
youtubeUrl: $model->youtube_url,
|
||||||
set: $set,
|
set: $set,
|
||||||
parentElement: $parentElement,
|
parentElement: $parentElement,
|
||||||
|
|
|
||||||
|
|
@ -35,12 +35,7 @@ class CreateElement
|
||||||
? null
|
? null
|
||||||
: $request->iconImageUrl;
|
: $request->iconImageUrl;
|
||||||
$richText = $request->richText ?? '';
|
$richText = $request->richText ?? '';
|
||||||
$shortPdfPath = $request->shortPdfPath === ''
|
$pdfPath = $request->pdfPath === '' ? null : $request->pdfPath;
|
||||||
? null
|
|
||||||
: $request->shortPdfPath;
|
|
||||||
$longPdfPath = $request->longPdfPath === ''
|
|
||||||
? null
|
|
||||||
: $request->longPdfPath;
|
|
||||||
$youtubeUrl = $request->youtubeUrl === ''
|
$youtubeUrl = $request->youtubeUrl === ''
|
||||||
? null
|
? null
|
||||||
: $request->youtubeUrl;
|
: $request->youtubeUrl;
|
||||||
|
|
@ -61,8 +56,7 @@ class CreateElement
|
||||||
description: $description,
|
description: $description,
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: $iconImageUrl,
|
||||||
richText: $richText,
|
richText: $richText,
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: $pdfPath,
|
||||||
longPdfPath: $longPdfPath,
|
|
||||||
youtubeUrl: $youtubeUrl,
|
youtubeUrl: $youtubeUrl,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
));
|
));
|
||||||
|
|
@ -88,8 +82,7 @@ class CreateElement
|
||||||
description: $description,
|
description: $description,
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: $iconImageUrl,
|
||||||
richText: $richText,
|
richText: $richText,
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: $pdfPath,
|
||||||
longPdfPath: $longPdfPath,
|
|
||||||
youtubeUrl: $youtubeUrl,
|
youtubeUrl: $youtubeUrl,
|
||||||
parentElement: $parentElement,
|
parentElement: $parentElement,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ class CreateElementRequest
|
||||||
public ?string $description,
|
public ?string $description,
|
||||||
public ?string $iconImageUrl,
|
public ?string $iconImageUrl,
|
||||||
public ?string $richText,
|
public ?string $richText,
|
||||||
public ?string $shortPdfPath,
|
public ?string $pdfPath,
|
||||||
public ?string $longPdfPath,
|
|
||||||
public ?string $youtubeUrl,
|
public ?string $youtubeUrl,
|
||||||
public ?int $parentElementId,
|
public ?int $parentElementId,
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,15 @@ use App\Exceptions\NotFoundException;
|
||||||
|
|
||||||
class UpdateElement
|
class UpdateElement
|
||||||
{
|
{
|
||||||
private const FILE_TYPE_ICON_IMAGE = 'iconImage';
|
|
||||||
|
|
||||||
private const FILE_TYPE_SHORT_PDF = 'shortPdf';
|
|
||||||
|
|
||||||
private const FILE_TYPE_LONG_PDF = 'longPdf';
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private UpdateTitle $updateTitle,
|
private UpdateTitle $updateTitle,
|
||||||
private UpdateDescription $updateDescription,
|
private UpdateDescription $updateDescription,
|
||||||
private UpdateIconImageUrl $updateIconImageUrl,
|
private UpdateIconImageUrl $updateIconImageUrl,
|
||||||
private UpdateRichText $updateRichText,
|
private UpdateRichText $updateRichText,
|
||||||
private UpdateShortPdfPath $updateShortPdfPath,
|
private UpdatePdfPath $updatePdfPath,
|
||||||
private UpdateLongPdfPath $updateLongPdfPath,
|
|
||||||
private UpdateYoutubeUrl $updateYoutubeUrl,
|
private UpdateYoutubeUrl $updateYoutubeUrl,
|
||||||
private UpdateIconImage $updateIconImage,
|
private UpdateIconImage $updateIconImage,
|
||||||
private UpdateShortPdf $updateShortPdf,
|
private UpdatePdf $updatePdf,
|
||||||
private UpdateLongPdf $updateLongPdf,
|
|
||||||
private ElementRepository $elementRepository,
|
private ElementRepository $elementRepository,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
@ -44,14 +36,10 @@ class UpdateElement
|
||||||
&& $request->description === null
|
&& $request->description === null
|
||||||
&& $request->iconImageUrl === null
|
&& $request->iconImageUrl === null
|
||||||
&& $request->richText === null
|
&& $request->richText === null
|
||||||
&& $request->shortPdfPath === null
|
&& $request->pdfPath === null
|
||||||
&& $request->longPdfPath === null
|
|
||||||
&& $request->youtubeUrl === null
|
&& $request->youtubeUrl === null
|
||||||
&& $request->fileType === null
|
&& $request->iconImageContents === null
|
||||||
&& $request->fileContents === null
|
&& $request->pdfContents === null;
|
||||||
&& $request->fileOriginalName === null
|
|
||||||
&& $request->fileMimeType === null
|
|
||||||
&& $request->fileSizeBytes === null;
|
|
||||||
if ($hasNoFields) {
|
if ($hasNoFields) {
|
||||||
throw new BadRequestException('nothing to update');
|
throw new BadRequestException('nothing to update');
|
||||||
}
|
}
|
||||||
|
|
@ -82,16 +70,10 @@ class UpdateElement
|
||||||
richText: $request->richText,
|
richText: $request->richText,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if ($request->shortPdfPath !== null) {
|
if ($request->pdfPath !== null) {
|
||||||
$this->updateShortPdfPath->execute(new UpdateShortPdfPathRequest(
|
$this->updatePdfPath->execute(new UpdatePdfPathRequest(
|
||||||
id: $request->id,
|
id: $request->id,
|
||||||
shortPdfPath: $request->shortPdfPath,
|
pdfPath: $request->pdfPath,
|
||||||
));
|
|
||||||
}
|
|
||||||
if ($request->longPdfPath !== null) {
|
|
||||||
$this->updateLongPdfPath->execute(new UpdateLongPdfPathRequest(
|
|
||||||
id: $request->id,
|
|
||||||
longPdfPath: $request->longPdfPath,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if ($request->youtubeUrl !== null) {
|
if ($request->youtubeUrl !== null) {
|
||||||
|
|
@ -100,8 +82,27 @@ class UpdateElement
|
||||||
youtubeUrl: $request->youtubeUrl,
|
youtubeUrl: $request->youtubeUrl,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if ($this->hasFileInput($request)) {
|
if ($request->iconImageContents !== null) {
|
||||||
$this->updateFile($request);
|
$this->updateIconImage->execute(
|
||||||
|
new UpdateIconImageRequest(
|
||||||
|
id: $request->id,
|
||||||
|
iconImageContents: $request->iconImageContents,
|
||||||
|
iconImageOriginalName: $request->iconImageOriginalName,
|
||||||
|
iconImageMimeType: $request->iconImageMimeType,
|
||||||
|
iconImageSizeBytes: $request->iconImageSizeBytes,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($request->pdfContents !== null) {
|
||||||
|
$this->updatePdf->execute(
|
||||||
|
new UpdatePdfRequest(
|
||||||
|
id: $request->id,
|
||||||
|
pdfContents: $request->pdfContents,
|
||||||
|
pdfOriginalName: $request->pdfOriginalName,
|
||||||
|
pdfMimeType: $request->pdfMimeType,
|
||||||
|
pdfSizeBytes: $request->pdfSizeBytes,
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$element = $this->elementRepository->find($request->id);
|
$element = $this->elementRepository->find($request->id);
|
||||||
|
|
@ -111,68 +112,4 @@ class UpdateElement
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws BadRequestException
|
|
||||||
* @throws NotFoundException
|
|
||||||
*/
|
|
||||||
private function updateFile(UpdateElementRequest $request): void
|
|
||||||
{
|
|
||||||
if ($request->fileType === null) {
|
|
||||||
throw new BadRequestException('fileType is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->fileType === self::FILE_TYPE_ICON_IMAGE) {
|
|
||||||
$this->updateIconImage->execute(
|
|
||||||
new UpdateIconImageRequest(
|
|
||||||
id: $request->id,
|
|
||||||
fileContents: $request->fileContents,
|
|
||||||
fileOriginalName: $request->fileOriginalName,
|
|
||||||
fileMimeType: $request->fileMimeType,
|
|
||||||
fileSizeBytes: $request->fileSizeBytes,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->fileType === self::FILE_TYPE_SHORT_PDF) {
|
|
||||||
$this->updateShortPdf->execute(
|
|
||||||
new UpdateShortPdfRequest(
|
|
||||||
id: $request->id,
|
|
||||||
fileContents: $request->fileContents,
|
|
||||||
fileOriginalName: $request->fileOriginalName,
|
|
||||||
fileMimeType: $request->fileMimeType,
|
|
||||||
fileSizeBytes: $request->fileSizeBytes,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->fileType === self::FILE_TYPE_LONG_PDF) {
|
|
||||||
$this->updateLongPdf->execute(
|
|
||||||
new UpdateLongPdfRequest(
|
|
||||||
id: $request->id,
|
|
||||||
fileContents: $request->fileContents,
|
|
||||||
fileOriginalName: $request->fileOriginalName,
|
|
||||||
fileMimeType: $request->fileMimeType,
|
|
||||||
fileSizeBytes: $request->fileSizeBytes,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new BadRequestException('fileType is invalid');
|
|
||||||
}
|
|
||||||
|
|
||||||
private function hasFileInput(UpdateElementRequest $request): bool
|
|
||||||
{
|
|
||||||
return $request->fileType !== null
|
|
||||||
|| $request->fileContents !== null
|
|
||||||
|| $request->fileOriginalName !== null
|
|
||||||
|| $request->fileMimeType !== null
|
|
||||||
|| $request->fileSizeBytes !== null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,16 @@ class UpdateElementRequest
|
||||||
public ?string $description,
|
public ?string $description,
|
||||||
public ?string $iconImageUrl,
|
public ?string $iconImageUrl,
|
||||||
public ?string $richText,
|
public ?string $richText,
|
||||||
public ?string $shortPdfPath,
|
public ?string $pdfPath,
|
||||||
public ?string $longPdfPath,
|
|
||||||
public ?string $youtubeUrl,
|
public ?string $youtubeUrl,
|
||||||
public ?string $fileType,
|
public ?string $iconImageContents,
|
||||||
public ?string $fileContents,
|
public ?string $iconImageOriginalName,
|
||||||
public ?string $fileOriginalName,
|
public ?string $iconImageMimeType,
|
||||||
public ?string $fileMimeType,
|
public ?int $iconImageSizeBytes,
|
||||||
public ?int $fileSizeBytes,
|
public ?string $pdfContents,
|
||||||
|
public ?string $pdfOriginalName,
|
||||||
|
public ?string $pdfMimeType,
|
||||||
|
public ?int $pdfSizeBytes,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,17 +36,17 @@ class UpdateIconImage
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$request->fileContents === null
|
$request->iconImageContents === null
|
||||||
|| $request->fileOriginalName === null
|
|| $request->iconImageOriginalName === null
|
||||||
|| $request->fileMimeType === null
|
|| $request->iconImageMimeType === null
|
||||||
|| $request->fileSizeBytes === null
|
|| $request->iconImageSizeBytes === null
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException('icon image is required');
|
throw new BadRequestException('icon image is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
! in_array(
|
! in_array(
|
||||||
$request->fileMimeType,
|
$request->iconImageMimeType,
|
||||||
self::ALLOWED_MIME_TYPES,
|
self::ALLOWED_MIME_TYPES,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
|
@ -56,7 +56,7 @@ class UpdateIconImage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->fileSizeBytes > self::MAX_SIZE_BYTES) {
|
if ($request->iconImageSizeBytes > self::MAX_SIZE_BYTES) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
'icon image must be 5MB or smaller',
|
'icon image must be 5MB or smaller',
|
||||||
);
|
);
|
||||||
|
|
@ -68,10 +68,10 @@ class UpdateIconImage
|
||||||
}
|
}
|
||||||
|
|
||||||
$iconImage = new FileToUpload(
|
$iconImage = new FileToUpload(
|
||||||
contents: $request->fileContents,
|
contents: $request->iconImageContents,
|
||||||
originalName: $request->fileOriginalName,
|
originalName: $request->iconImageOriginalName,
|
||||||
mimeType: $request->fileMimeType,
|
mimeType: $request->iconImageMimeType,
|
||||||
sizeBytes: $request->fileSizeBytes,
|
sizeBytes: $request->iconImageSizeBytes,
|
||||||
);
|
);
|
||||||
$path = $this->fileUploader->upload($iconImage, 'element-icons');
|
$path = $this->fileUploader->upload($iconImage, 'element-icons');
|
||||||
$element->setIconImageUrl($path);
|
$element->setIconImageUrl($path);
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ class UpdateIconImageRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public ?int $id,
|
public ?int $id,
|
||||||
public ?string $fileContents,
|
public ?string $iconImageContents,
|
||||||
public ?string $fileOriginalName,
|
public ?string $iconImageOriginalName,
|
||||||
public ?string $fileMimeType,
|
public ?string $iconImageMimeType,
|
||||||
public ?int $fileSizeBytes,
|
public ?int $iconImageSizeBytes,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Element\UseCases\UpdateElement;
|
|
||||||
|
|
||||||
class UpdateLongPdfRequest
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
public ?int $id,
|
|
||||||
public ?string $fileContents,
|
|
||||||
public ?string $fileOriginalName,
|
|
||||||
public ?string $fileMimeType,
|
|
||||||
public ?int $fileSizeBytes,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -9,7 +9,7 @@ use App\Exceptions\NotFoundException;
|
||||||
use App\Shared\Files\FileToUpload;
|
use App\Shared\Files\FileToUpload;
|
||||||
use App\Shared\Files\FileUploader;
|
use App\Shared\Files\FileUploader;
|
||||||
|
|
||||||
class UpdateLongPdf
|
class UpdatePdf
|
||||||
{
|
{
|
||||||
private const ALLOWED_MIME_TYPES = [
|
private const ALLOWED_MIME_TYPES = [
|
||||||
'application/pdf',
|
'application/pdf',
|
||||||
|
|
@ -27,24 +27,24 @@ class UpdateLongPdf
|
||||||
* @throws BadRequestException
|
* @throws BadRequestException
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function execute(UpdateLongPdfRequest $request): Element
|
public function execute(UpdatePdfRequest $request): Element
|
||||||
{
|
{
|
||||||
if ($request->id === null) {
|
if ($request->id === null) {
|
||||||
throw new BadRequestException('id is required');
|
throw new BadRequestException('id is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$request->fileContents === null
|
$request->pdfContents === null
|
||||||
|| $request->fileOriginalName === null
|
|| $request->pdfOriginalName === null
|
||||||
|| $request->fileMimeType === null
|
|| $request->pdfMimeType === null
|
||||||
|| $request->fileSizeBytes === null
|
|| $request->pdfSizeBytes === null
|
||||||
) {
|
) {
|
||||||
throw new BadRequestException('pdf is required');
|
throw new BadRequestException('pdf is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
! in_array(
|
! in_array(
|
||||||
$request->fileMimeType,
|
$request->pdfMimeType,
|
||||||
self::ALLOWED_MIME_TYPES,
|
self::ALLOWED_MIME_TYPES,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
|
@ -52,7 +52,7 @@ class UpdateLongPdf
|
||||||
throw new BadRequestException('pdf must be a pdf file');
|
throw new BadRequestException('pdf must be a pdf file');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->fileSizeBytes > self::MAX_SIZE_BYTES) {
|
if ($request->pdfSizeBytes > self::MAX_SIZE_BYTES) {
|
||||||
throw new BadRequestException('pdf must be 10MB or smaller');
|
throw new BadRequestException('pdf must be 10MB or smaller');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,13 +62,13 @@ class UpdateLongPdf
|
||||||
}
|
}
|
||||||
|
|
||||||
$pdf = new FileToUpload(
|
$pdf = new FileToUpload(
|
||||||
contents: $request->fileContents,
|
contents: $request->pdfContents,
|
||||||
originalName: $request->fileOriginalName,
|
originalName: $request->pdfOriginalName,
|
||||||
mimeType: $request->fileMimeType,
|
mimeType: $request->pdfMimeType,
|
||||||
sizeBytes: $request->fileSizeBytes,
|
sizeBytes: $request->pdfSizeBytes,
|
||||||
);
|
);
|
||||||
$path = $this->fileUploader->upload($pdf, 'element-pdfs/long');
|
$path = $this->fileUploader->upload($pdf, 'element-pdfs');
|
||||||
$element->setLongPdfPath($path);
|
$element->setPdfPath($path);
|
||||||
|
|
||||||
return $this->elementRepository->update($element);
|
return $this->elementRepository->update($element);
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ use App\Exceptions\BadRequestException;
|
||||||
use App\Exceptions\NotFoundException;
|
use App\Exceptions\NotFoundException;
|
||||||
use App\Shared\Files\FileUploader;
|
use App\Shared\Files\FileUploader;
|
||||||
|
|
||||||
class UpdateLongPdfPath
|
class UpdatePdfPath
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private ElementRepository $elementRepository,
|
private ElementRepository $elementRepository,
|
||||||
|
|
@ -20,14 +20,14 @@ class UpdateLongPdfPath
|
||||||
* @throws BadRequestException
|
* @throws BadRequestException
|
||||||
* @throws NotFoundException
|
* @throws NotFoundException
|
||||||
*/
|
*/
|
||||||
public function execute(UpdateLongPdfPathRequest $request): Element
|
public function execute(UpdatePdfPathRequest $request): Element
|
||||||
{
|
{
|
||||||
if ($request->id === null) {
|
if ($request->id === null) {
|
||||||
throw new BadRequestException('id is required');
|
throw new BadRequestException('id is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->longPdfPath === null) {
|
if ($request->pdfPath === null) {
|
||||||
throw new BadRequestException('longPdfPath is required');
|
throw new BadRequestException('pdfPath is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
$element = $this->elementRepository->find($request->id);
|
$element = $this->elementRepository->find($request->id);
|
||||||
|
|
@ -35,12 +35,12 @@ class UpdateLongPdfPath
|
||||||
throw new NotFoundException('Element not found');
|
throw new NotFoundException('Element not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$longPdfPath = $this->nullableString($request->longPdfPath);
|
$pdfPath = $this->nullableString($request->pdfPath);
|
||||||
if ($longPdfPath === null) {
|
if ($pdfPath === null) {
|
||||||
$this->deleteManagedFile($element->getLongPdfPath());
|
$this->deleteManagedFile($element->getPdfPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
$element->setLongPdfPath($longPdfPath);
|
$element->setPdfPath($pdfPath);
|
||||||
|
|
||||||
return $this->elementRepository->update($element);
|
return $this->elementRepository->update($element);
|
||||||
}
|
}
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
namespace App\Element\UseCases\UpdateElement;
|
namespace App\Element\UseCases\UpdateElement;
|
||||||
|
|
||||||
class UpdateLongPdfPathRequest
|
class UpdatePdfPathRequest
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public ?int $id,
|
public ?int $id,
|
||||||
public ?string $longPdfPath,
|
public ?string $pdfPath,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Element\UseCases\UpdateElement;
|
||||||
|
|
||||||
|
class UpdatePdfRequest
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public ?int $id,
|
||||||
|
public ?string $pdfContents,
|
||||||
|
public ?string $pdfOriginalName,
|
||||||
|
public ?string $pdfMimeType,
|
||||||
|
public ?int $pdfSizeBytes,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Element\UseCases\UpdateElement;
|
|
||||||
|
|
||||||
use App\Element\Element;
|
|
||||||
use App\Element\ElementRepository;
|
|
||||||
use App\Exceptions\BadRequestException;
|
|
||||||
use App\Exceptions\NotFoundException;
|
|
||||||
use App\Shared\Files\FileToUpload;
|
|
||||||
use App\Shared\Files\FileUploader;
|
|
||||||
|
|
||||||
class UpdateShortPdf
|
|
||||||
{
|
|
||||||
private const ALLOWED_MIME_TYPES = [
|
|
||||||
'application/pdf',
|
|
||||||
];
|
|
||||||
|
|
||||||
private const MAX_SIZE_BYTES = 10 * 1024 * 1024;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private ElementRepository $elementRepository,
|
|
||||||
private FileUploader $fileUploader,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws BadRequestException
|
|
||||||
* @throws NotFoundException
|
|
||||||
*/
|
|
||||||
public function execute(UpdateShortPdfRequest $request): Element
|
|
||||||
{
|
|
||||||
if ($request->id === null) {
|
|
||||||
throw new BadRequestException('id is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
$request->fileContents === null
|
|
||||||
|| $request->fileOriginalName === null
|
|
||||||
|| $request->fileMimeType === null
|
|
||||||
|| $request->fileSizeBytes === null
|
|
||||||
) {
|
|
||||||
throw new BadRequestException('pdf is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
! in_array(
|
|
||||||
$request->fileMimeType,
|
|
||||||
self::ALLOWED_MIME_TYPES,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new BadRequestException('pdf must be a pdf file');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->fileSizeBytes > self::MAX_SIZE_BYTES) {
|
|
||||||
throw new BadRequestException('pdf must be 10MB or smaller');
|
|
||||||
}
|
|
||||||
|
|
||||||
$element = $this->elementRepository->find($request->id);
|
|
||||||
if ($element === null) {
|
|
||||||
throw new NotFoundException('Element not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$pdf = new FileToUpload(
|
|
||||||
contents: $request->fileContents,
|
|
||||||
originalName: $request->fileOriginalName,
|
|
||||||
mimeType: $request->fileMimeType,
|
|
||||||
sizeBytes: $request->fileSizeBytes,
|
|
||||||
);
|
|
||||||
$path = $this->fileUploader->upload($pdf, 'element-pdfs/short');
|
|
||||||
$element->setShortPdfPath($path);
|
|
||||||
|
|
||||||
return $this->elementRepository->update($element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Element\UseCases\UpdateElement;
|
|
||||||
|
|
||||||
use App\Element\Element;
|
|
||||||
use App\Element\ElementRepository;
|
|
||||||
use App\Exceptions\BadRequestException;
|
|
||||||
use App\Exceptions\NotFoundException;
|
|
||||||
use App\Shared\Files\FileUploader;
|
|
||||||
|
|
||||||
class UpdateShortPdfPath
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private ElementRepository $elementRepository,
|
|
||||||
private FileUploader $fileUploader,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws BadRequestException
|
|
||||||
* @throws NotFoundException
|
|
||||||
*/
|
|
||||||
public function execute(UpdateShortPdfPathRequest $request): Element
|
|
||||||
{
|
|
||||||
if ($request->id === null) {
|
|
||||||
throw new BadRequestException('id is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->shortPdfPath === null) {
|
|
||||||
throw new BadRequestException('shortPdfPath is required');
|
|
||||||
}
|
|
||||||
|
|
||||||
$element = $this->elementRepository->find($request->id);
|
|
||||||
if ($element === null) {
|
|
||||||
throw new NotFoundException('Element not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
$shortPdfPath = $this->nullableString($request->shortPdfPath);
|
|
||||||
if ($shortPdfPath === null) {
|
|
||||||
$this->deleteManagedFile($element->getShortPdfPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
$element->setShortPdfPath($shortPdfPath);
|
|
||||||
|
|
||||||
return $this->elementRepository->update($element);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function nullableString(string $value): ?string
|
|
||||||
{
|
|
||||||
if ($value === '') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function deleteManagedFile(?string $path): void
|
|
||||||
{
|
|
||||||
if ($path === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fileUploader->delete($path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Element\UseCases\UpdateElement;
|
|
||||||
|
|
||||||
class UpdateShortPdfPathRequest
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
public ?int $id,
|
|
||||||
public ?string $shortPdfPath,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Element\UseCases\UpdateElement;
|
|
||||||
|
|
||||||
class UpdateShortPdfRequest
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
public ?int $id,
|
|
||||||
public ?string $fileContents,
|
|
||||||
public ?string $fileOriginalName,
|
|
||||||
public ?string $fileMimeType,
|
|
||||||
public ?int $fileSizeBytes,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,8 +15,7 @@ return new class extends Migration
|
||||||
$table->text('description')->default('');
|
$table->text('description')->default('');
|
||||||
$table->string('icon_image_url')->nullable();
|
$table->string('icon_image_url')->nullable();
|
||||||
$table->text('rich_text')->default('');
|
$table->text('rich_text')->default('');
|
||||||
$table->string('short_pdf_path')->nullable();
|
$table->string('pdf_path')->nullable();
|
||||||
$table->string('long_pdf_path')->nullable();
|
|
||||||
$table->string('youtube_url')->nullable();
|
$table->string('youtube_url')->nullable();
|
||||||
$table->foreignId('parent_element_id')
|
$table->foreignId('parent_element_id')
|
||||||
->nullable()
|
->nullable()
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class ElementSeeder extends Seeder
|
||||||
'element-icons/baderech-haavodah-icon.png',
|
'element-icons/baderech-haavodah-icon.png',
|
||||||
);
|
);
|
||||||
$introductionPdfPath = $this->seedStorageFile(
|
$introductionPdfPath = $this->seedStorageFile(
|
||||||
'element-pdfs/short/baderech.pdf',
|
'element-pdfs/baderech.pdf',
|
||||||
);
|
);
|
||||||
|
|
||||||
$rootElement = $elementRepository->create(new CreateElementDto(
|
$rootElement = $elementRepository->create(new CreateElementDto(
|
||||||
|
|
@ -29,8 +29,7 @@ class ElementSeeder extends Seeder
|
||||||
description: $baderechSet->getDescription(),
|
description: $baderechSet->getDescription(),
|
||||||
iconImageUrl: $rootIconImageUrl,
|
iconImageUrl: $rootIconImageUrl,
|
||||||
richText: '',
|
richText: '',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
));
|
));
|
||||||
|
|
@ -45,7 +44,7 @@ class ElementSeeder extends Seeder
|
||||||
. 'unlock the ability to live with strength, confidence, '
|
. 'unlock the ability to live with strength, confidence, '
|
||||||
. 'and hope.',
|
. 'and hope.',
|
||||||
'richText' => $this->introductionRichText(),
|
'richText' => $this->introductionRichText(),
|
||||||
'shortPdfPath' => $introductionPdfPath,
|
'pdfPath' => $introductionPdfPath,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => '2. Foundations',
|
'title' => '2. Foundations',
|
||||||
|
|
@ -55,7 +54,7 @@ class ElementSeeder extends Seeder
|
||||||
. 'ability to uplift the physical world with spiritual '
|
. 'ability to uplift the physical world with spiritual '
|
||||||
. 'intention.',
|
. 'intention.',
|
||||||
'richText' => '',
|
'richText' => '',
|
||||||
'shortPdfPath' => null,
|
'pdfPath' => null,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => '3. Divine Plan',
|
'title' => '3. Divine Plan',
|
||||||
|
|
@ -63,14 +62,14 @@ class ElementSeeder extends Seeder
|
||||||
. 'generation and the call to remain hopeful, '
|
. 'generation and the call to remain hopeful, '
|
||||||
. 'optimistic, and resilient.',
|
. 'optimistic, and resilient.',
|
||||||
'richText' => '',
|
'richText' => '',
|
||||||
'shortPdfPath' => null,
|
'pdfPath' => null,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => '4. Architecture of the Soul',
|
'title' => '4. Architecture of the Soul',
|
||||||
'description' => "Becoming a Baal Da'at - A Master of "
|
'description' => "Becoming a Baal Da'at - A Master of "
|
||||||
. 'Inner Awareness',
|
. 'Inner Awareness',
|
||||||
'richText' => '',
|
'richText' => '',
|
||||||
'shortPdfPath' => null,
|
'pdfPath' => null,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => '5. Arba Yesodot',
|
'title' => '5. Arba Yesodot',
|
||||||
|
|
@ -78,7 +77,7 @@ class ElementSeeder extends Seeder
|
||||||
. 'Physical & Financial Health, Relationships, Wisdom '
|
. 'Physical & Financial Health, Relationships, Wisdom '
|
||||||
. 'and Guidance.',
|
. 'and Guidance.',
|
||||||
'richText' => '',
|
'richText' => '',
|
||||||
'shortPdfPath' => null,
|
'pdfPath' => null,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => '6. Fluid Integration',
|
'title' => '6. Fluid Integration',
|
||||||
|
|
@ -86,7 +85,7 @@ class ElementSeeder extends Seeder
|
||||||
. 'engender a shift in mindset, embed healthy routines, '
|
. 'engender a shift in mindset, embed healthy routines, '
|
||||||
. 'positive life practices.',
|
. 'positive life practices.',
|
||||||
'richText' => '',
|
'richText' => '',
|
||||||
'shortPdfPath' => null,
|
'pdfPath' => null,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -98,8 +97,7 @@ class ElementSeeder extends Seeder
|
||||||
description: $baderechChildElement['description'],
|
description: $baderechChildElement['description'],
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: $baderechChildElement['richText'],
|
richText: $baderechChildElement['richText'],
|
||||||
shortPdfPath: $baderechChildElement['shortPdfPath'],
|
pdfPath: $baderechChildElement['pdfPath'],
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElement: $rootElement,
|
parentElement: $rootElement,
|
||||||
));
|
));
|
||||||
|
|
@ -119,8 +117,7 @@ class ElementSeeder extends Seeder
|
||||||
description: '',
|
description: '',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '',
|
richText: '',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v='
|
youtubeUrl: 'https://www.youtube.com/watch?v='
|
||||||
. 'yHx-r4p6hHU&t=1s',
|
. 'yHx-r4p6hHU&t=1s',
|
||||||
parentElement: $introductionElement,
|
parentElement: $introductionElement,
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,7 @@ class FakeElementRepository implements ElementRepository
|
||||||
description: $dto->description,
|
description: $dto->description,
|
||||||
iconImageUrl: $dto->iconImageUrl,
|
iconImageUrl: $dto->iconImageUrl,
|
||||||
richText: $dto->richText,
|
richText: $dto->richText,
|
||||||
shortPdfPath: $dto->shortPdfPath,
|
pdfPath: $dto->pdfPath,
|
||||||
longPdfPath: $dto->longPdfPath,
|
|
||||||
youtubeUrl: $dto->youtubeUrl,
|
youtubeUrl: $dto->youtubeUrl,
|
||||||
set: $dto->set,
|
set: $dto->set,
|
||||||
parentElement: $dto->parentElement,
|
parentElement: $dto->parentElement,
|
||||||
|
|
@ -112,8 +111,7 @@ class FakeElementRepository implements ElementRepository
|
||||||
description: $element->getDescription(),
|
description: $element->getDescription(),
|
||||||
iconImageUrl: $element->getIconImageUrl(),
|
iconImageUrl: $element->getIconImageUrl(),
|
||||||
richText: $element->getRichText(),
|
richText: $element->getRichText(),
|
||||||
shortPdfPath: $element->getShortPdfPath(),
|
pdfPath: $element->getPdfPath(),
|
||||||
longPdfPath: $element->getLongPdfPath(),
|
|
||||||
youtubeUrl: $element->getYoutubeUrl(),
|
youtubeUrl: $element->getYoutubeUrl(),
|
||||||
set: $element->getSet(),
|
set: $element->getSet(),
|
||||||
parentElement: $parentElement,
|
parentElement: $parentElement,
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,7 @@ class DemoSeedDataTest extends TestCase
|
||||||
Storage::disk('public')->assertExists(
|
Storage::disk('public')->assertExists(
|
||||||
'element-icons/baderech-haavodah-icon.png',
|
'element-icons/baderech-haavodah-icon.png',
|
||||||
);
|
);
|
||||||
$this->assertNull($rootElement->getShortPdfPath());
|
$this->assertNull($rootElement->getPdfPath());
|
||||||
$this->assertNull($rootElement->getLongPdfPath());
|
|
||||||
$this->assertNull($rootElement->getYoutubeUrl());
|
$this->assertNull($rootElement->getYoutubeUrl());
|
||||||
$this->assertCount(6, $childElements);
|
$this->assertCount(6, $childElements);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
|
|
@ -97,13 +96,10 @@ class DemoSeedDataTest extends TestCase
|
||||||
$childElements[0]->getRichText(),
|
$childElements[0]->getRichText(),
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/short/baderech.pdf',
|
'element-pdfs/baderech.pdf',
|
||||||
$childElements[0]->getShortPdfPath(),
|
$childElements[0]->getPdfPath(),
|
||||||
);
|
|
||||||
$this->assertNull($childElements[0]->getLongPdfPath());
|
|
||||||
Storage::disk('public')->assertExists(
|
|
||||||
'element-pdfs/short/baderech.pdf',
|
|
||||||
);
|
);
|
||||||
|
Storage::disk('public')->assertExists('element-pdfs/baderech.pdf');
|
||||||
|
|
||||||
$introductionChildElements = $elementRepository->findByParentElement(
|
$introductionChildElements = $elementRepository->findByParentElement(
|
||||||
$childElements[0],
|
$childElements[0],
|
||||||
|
|
@ -118,8 +114,7 @@ class DemoSeedDataTest extends TestCase
|
||||||
$this->assertSame('', $introductionAudioElement->getDescription());
|
$this->assertSame('', $introductionAudioElement->getDescription());
|
||||||
$this->assertNull($introductionAudioElement->getIconImageUrl());
|
$this->assertNull($introductionAudioElement->getIconImageUrl());
|
||||||
$this->assertSame('', $introductionAudioElement->getRichText());
|
$this->assertSame('', $introductionAudioElement->getRichText());
|
||||||
$this->assertNull($introductionAudioElement->getShortPdfPath());
|
$this->assertNull($introductionAudioElement->getPdfPath());
|
||||||
$this->assertNull($introductionAudioElement->getLongPdfPath());
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
$introductionAudioElement->getYoutubeUrl(),
|
$introductionAudioElement->getYoutubeUrl(),
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,8 @@ namespace Tests\Feature;
|
||||||
use App\Auth\CreateSessionDto;
|
use App\Auth\CreateSessionDto;
|
||||||
use App\Auth\SessionRepository;
|
use App\Auth\SessionRepository;
|
||||||
use App\Element\CreateElementDto;
|
use App\Element\CreateElementDto;
|
||||||
use App\Element\Element;
|
|
||||||
use App\Element\ElementRepository;
|
use App\Element\ElementRepository;
|
||||||
use App\Set\CreateSetDto;
|
use App\Set\CreateSetDto;
|
||||||
use App\Set\Set;
|
|
||||||
use App\Set\SetRepository;
|
use App\Set\SetRepository;
|
||||||
use App\Shared\ValueObject\EmailAddress;
|
use App\Shared\ValueObject\EmailAddress;
|
||||||
use App\User\CreateUserDto;
|
use App\User\CreateUserDto;
|
||||||
|
|
@ -30,43 +28,41 @@ class ElementsEndpointTest extends TestCase
|
||||||
. 'yHx-r4p6hHU&t=1s';
|
. 'yHx-r4p6hHU&t=1s';
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
'/assets/baderech-haavodah-icon.png',
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
'/assets/pdfs/baderech.pdf',
|
description: 'A structured path for growth',
|
||||||
'/assets/pdfs/baderech-long.pdf',
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
$sampleYoutubeUrl,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: '/assets/pdfs/baderech.pdf',
|
||||||
);
|
youtubeUrl: $sampleYoutubeUrl,
|
||||||
$firstChildElement = $this->createElement(
|
parentElement: null,
|
||||||
$elementRepository,
|
));
|
||||||
$set,
|
$firstChildElement = $elementRepository->create(new CreateElementDto(
|
||||||
'Avodah Foundations',
|
set: $set,
|
||||||
'Foundations for steady avodah',
|
title: 'Avodah Foundations',
|
||||||
null,
|
description: 'Foundations for steady avodah',
|
||||||
'<p>Foundations rich text</p>',
|
iconImageUrl: null,
|
||||||
'/assets/pdfs/foundations.pdf',
|
richText: '<p>Foundations rich text</p>',
|
||||||
null,
|
pdfPath: '/assets/pdfs/foundations.pdf',
|
||||||
null,
|
youtubeUrl: null,
|
||||||
$element,
|
parentElement: $element,
|
||||||
);
|
));
|
||||||
$secondChildElement = $this->createElement(
|
$secondChildElement = $elementRepository->create(new CreateElementDto(
|
||||||
$elementRepository,
|
set: $set,
|
||||||
$set,
|
title: 'Daily Practice',
|
||||||
'Daily Practice',
|
description: 'Daily practices for growth',
|
||||||
'Daily practices for growth',
|
iconImageUrl: null,
|
||||||
null,
|
richText: '<p>Daily practice rich text</p>',
|
||||||
'<p>Daily practice rich text</p>',
|
pdfPath: null,
|
||||||
null,
|
youtubeUrl: null,
|
||||||
null,
|
parentElement: $element,
|
||||||
null,
|
));
|
||||||
$element,
|
|
||||||
);
|
|
||||||
|
|
||||||
$response = $this->getJson("/api/elements/{$element->getId()}");
|
$response = $this->getJson("/api/elements/{$element->getId()}");
|
||||||
|
|
||||||
|
|
@ -90,8 +86,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
'description' => 'A structured path for growth',
|
'description' => 'A structured path for growth',
|
||||||
'iconImageUrl' => '/assets/baderech-haavodah-icon.png',
|
'iconImageUrl' => '/assets/baderech-haavodah-icon.png',
|
||||||
'richText' => '<p>A structured path for growth</p>',
|
'richText' => '<p>A structured path for growth</p>',
|
||||||
'shortPdfPath' => '/assets/pdfs/baderech.pdf',
|
'pdfPath' => '/assets/pdfs/baderech.pdf',
|
||||||
'longPdfPath' => '/assets/pdfs/baderech-long.pdf',
|
|
||||||
'youtubeUrl' => $sampleYoutubeUrl,
|
'youtubeUrl' => $sampleYoutubeUrl,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
@ -111,19 +106,21 @@ class ElementsEndpointTest extends TestCase
|
||||||
{
|
{
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
'/assets/baderech-haavodah-icon.png',
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
'/assets/pdfs/baderech.pdf',
|
description: 'A structured path for growth',
|
||||||
null,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
null,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: '/assets/pdfs/baderech.pdf',
|
||||||
);
|
youtubeUrl: null,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
|
|
||||||
$response = $this->postJson('/api/element/update', [
|
$response = $this->postJson('/api/element/update', [
|
||||||
'elementId' => $element->getId(),
|
'elementId' => $element->getId(),
|
||||||
|
|
@ -131,8 +128,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
'description' => 'Updated description',
|
'description' => 'Updated description',
|
||||||
'iconImageUrl' => '/assets/updated-icon.png',
|
'iconImageUrl' => '/assets/updated-icon.png',
|
||||||
'richText' => '<p>Updated rich text</p>',
|
'richText' => '<p>Updated rich text</p>',
|
||||||
'shortPdfPath' => '/assets/pdfs/updated.pdf',
|
'pdfPath' => '/assets/pdfs/updated.pdf',
|
||||||
'longPdfPath' => '/assets/pdfs/updated-long.pdf',
|
|
||||||
'youtubeUrl' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
'youtubeUrl' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -148,19 +144,21 @@ class ElementsEndpointTest extends TestCase
|
||||||
. 'dQw4w9WgXcQ';
|
. 'dQw4w9WgXcQ';
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
'/assets/baderech-haavodah-icon.png',
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
'/assets/pdfs/baderech.pdf',
|
description: 'A structured path for growth',
|
||||||
null,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
null,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: '/assets/pdfs/baderech.pdf',
|
||||||
);
|
youtubeUrl: null,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
$this->createSession('valid-token');
|
$this->createSession('valid-token');
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
$response = $this->withCredentials()
|
||||||
|
|
@ -171,8 +169,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
'description' => 'Updated description',
|
'description' => 'Updated description',
|
||||||
'iconImageUrl' => '/assets/updated-icon.png',
|
'iconImageUrl' => '/assets/updated-icon.png',
|
||||||
'richText' => '<p>Updated rich text</p>',
|
'richText' => '<p>Updated rich text</p>',
|
||||||
'shortPdfPath' => '/assets/pdfs/updated.pdf',
|
'pdfPath' => '/assets/pdfs/updated.pdf',
|
||||||
'longPdfPath' => '/assets/pdfs/updated-long.pdf',
|
|
||||||
'youtubeUrl' => $sampleYoutubeUrl,
|
'youtubeUrl' => $sampleYoutubeUrl,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -184,8 +181,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
'description' => 'Updated description',
|
'description' => 'Updated description',
|
||||||
'iconImageUrl' => '/assets/updated-icon.png',
|
'iconImageUrl' => '/assets/updated-icon.png',
|
||||||
'richText' => '<p>Updated rich text</p>',
|
'richText' => '<p>Updated rich text</p>',
|
||||||
'shortPdfPath' => '/assets/pdfs/updated.pdf',
|
'pdfPath' => '/assets/pdfs/updated.pdf',
|
||||||
'longPdfPath' => '/assets/pdfs/updated-long.pdf',
|
|
||||||
'youtubeUrl' => $sampleYoutubeUrl,
|
'youtubeUrl' => $sampleYoutubeUrl,
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
@ -195,42 +191,6 @@ class ElementsEndpointTest extends TestCase
|
||||||
'<p>Updated rich text</p>',
|
'<p>Updated rich text</p>',
|
||||||
$updatedElement->getRichText(),
|
$updatedElement->getRichText(),
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/updated-long.pdf',
|
|
||||||
$updatedElement->getLongPdfPath(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthenticatedUpdateRejectsLegacyPdfPath(): void
|
|
||||||
{
|
|
||||||
$setRepository = app(SetRepository::class);
|
|
||||||
$elementRepository = app(ElementRepository::class);
|
|
||||||
$set = $this->createSet($setRepository);
|
|
||||||
$element = $this->createElement(
|
|
||||||
$elementRepository,
|
|
||||||
$set,
|
|
||||||
'Baderech HaAvodah',
|
|
||||||
'A structured path for growth',
|
|
||||||
null,
|
|
||||||
'<p>A structured path for growth</p>',
|
|
||||||
'/assets/pdfs/baderech.pdf',
|
|
||||||
'/assets/pdfs/baderech-long.pdf',
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
$this->createSession('valid-token');
|
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
|
||||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
|
||||||
->postJson('/api/element/update', [
|
|
||||||
'elementId' => $element->getId(),
|
|
||||||
'pdfPath' => '/assets/pdfs/legacy-updated.pdf',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertBadRequest();
|
|
||||||
$response->assertExactJson([
|
|
||||||
'error' => 'nothing to update',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthenticatedUpdateClearsUploadedMedia(): void
|
public function testAuthenticatedUpdateClearsUploadedMedia(): void
|
||||||
|
|
@ -241,28 +201,26 @@ class ElementsEndpointTest extends TestCase
|
||||||
'icon bytes',
|
'icon bytes',
|
||||||
);
|
);
|
||||||
Storage::disk('public')->put(
|
Storage::disk('public')->put(
|
||||||
'element-pdfs/short/original.pdf',
|
'element-pdfs/original.pdf',
|
||||||
'short pdf bytes',
|
'pdf bytes',
|
||||||
);
|
|
||||||
Storage::disk('public')->put(
|
|
||||||
'element-pdfs/long/original-long.pdf',
|
|
||||||
'long pdf bytes',
|
|
||||||
);
|
);
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
'element-icons/original-icon.png',
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
'element-pdfs/short/original.pdf',
|
description: 'A structured path for growth',
|
||||||
'element-pdfs/long/original-long.pdf',
|
iconImageUrl: 'element-icons/original-icon.png',
|
||||||
null,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: 'element-pdfs/original.pdf',
|
||||||
);
|
youtubeUrl: null,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
$this->createSession('valid-token');
|
$this->createSession('valid-token');
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
$response = $this->withCredentials()
|
||||||
|
|
@ -270,29 +228,22 @@ class ElementsEndpointTest extends TestCase
|
||||||
->postJson('/api/element/update', [
|
->postJson('/api/element/update', [
|
||||||
'elementId' => $element->getId(),
|
'elementId' => $element->getId(),
|
||||||
'iconImageUrl' => '',
|
'iconImageUrl' => '',
|
||||||
'shortPdfPath' => '',
|
'pdfPath' => '',
|
||||||
'longPdfPath' => '',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertOk();
|
$response->assertOk();
|
||||||
$body = $response->json();
|
$body = $response->json();
|
||||||
$this->assertNull($body['element']['iconImageUrl']);
|
$this->assertNull($body['element']['iconImageUrl']);
|
||||||
$this->assertNull($body['element']['shortPdfPath']);
|
$this->assertNull($body['element']['pdfPath']);
|
||||||
$this->assertNull($body['element']['longPdfPath']);
|
|
||||||
$this->assertArrayNotHasKey('pdfPath', $body['element']);
|
|
||||||
$updatedElement = $elementRepository->find($element->getId());
|
$updatedElement = $elementRepository->find($element->getId());
|
||||||
$this->assertNotNull($updatedElement);
|
$this->assertNotNull($updatedElement);
|
||||||
$this->assertNull($updatedElement->getIconImageUrl());
|
$this->assertNull($updatedElement->getIconImageUrl());
|
||||||
$this->assertNull($updatedElement->getShortPdfPath());
|
$this->assertNull($updatedElement->getPdfPath());
|
||||||
$this->assertNull($updatedElement->getLongPdfPath());
|
|
||||||
Storage::disk('public')->assertMissing(
|
Storage::disk('public')->assertMissing(
|
||||||
'element-icons/original-icon.png',
|
'element-icons/original-icon.png',
|
||||||
);
|
);
|
||||||
Storage::disk('public')->assertMissing(
|
Storage::disk('public')->assertMissing(
|
||||||
'element-pdfs/short/original.pdf',
|
'element-pdfs/original.pdf',
|
||||||
);
|
|
||||||
Storage::disk('public')->assertMissing(
|
|
||||||
'element-pdfs/long/original-long.pdf',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -300,26 +251,27 @@ class ElementsEndpointTest extends TestCase
|
||||||
{
|
{
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
null,
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
null,
|
description: 'A structured path for growth',
|
||||||
null,
|
iconImageUrl: null,
|
||||||
null,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: null,
|
||||||
);
|
youtubeUrl: null,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
'/api/element/update',
|
'/api/element/update',
|
||||||
[
|
[
|
||||||
'elementId' => (string) $element->getId(),
|
'elementId' => (string) $element->getId(),
|
||||||
'fileType' => 'iconImage',
|
'iconImage' => $this->iconImageUpload(),
|
||||||
'file' => $this->iconImageUpload(),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -329,24 +281,26 @@ class ElementsEndpointTest extends TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthenticatedIconImageUploadReturnsPayload(): void
|
public function testAuthenticatedIconImageUploadReturnsElementPayload(): void
|
||||||
{
|
{
|
||||||
Storage::fake('public');
|
Storage::fake('public');
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
null,
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
null,
|
description: 'A structured path for growth',
|
||||||
null,
|
iconImageUrl: null,
|
||||||
null,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: null,
|
||||||
);
|
youtubeUrl: null,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
$this->createSession('valid-token');
|
$this->createSession('valid-token');
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
$response = $this->withCredentials()
|
||||||
|
|
@ -355,8 +309,7 @@ class ElementsEndpointTest extends TestCase
|
||||||
'/api/element/update',
|
'/api/element/update',
|
||||||
[
|
[
|
||||||
'elementId' => (string) $element->getId(),
|
'elementId' => (string) $element->getId(),
|
||||||
'fileType' => 'iconImage',
|
'iconImage' => $this->iconImageUpload(),
|
||||||
'file' => $this->iconImageUpload(),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -378,30 +331,31 @@ class ElementsEndpointTest extends TestCase
|
||||||
Storage::disk('public')->assertExists($updatedIconImageUrl);
|
Storage::disk('public')->assertExists($updatedIconImageUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testShortPdfUploadRequiresAuthentication(): void
|
public function testPdfUploadRequiresAuthentication(): void
|
||||||
{
|
{
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
name: 'Baderech HaAvodah',
|
||||||
$elementRepository,
|
description: 'A structured path for growth',
|
||||||
$set,
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
'Baderech HaAvodah',
|
));
|
||||||
'A structured path for growth',
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
null,
|
set: $set,
|
||||||
'<p>A structured path for growth</p>',
|
title: 'Baderech HaAvodah',
|
||||||
null,
|
description: 'A structured path for growth',
|
||||||
null,
|
iconImageUrl: null,
|
||||||
null,
|
richText: '<p>A structured path for growth</p>',
|
||||||
null,
|
pdfPath: null,
|
||||||
);
|
youtubeUrl: null,
|
||||||
|
parentElement: null,
|
||||||
|
));
|
||||||
|
|
||||||
$response = $this->post(
|
$response = $this->post(
|
||||||
'/api/element/update',
|
'/api/element/update',
|
||||||
[
|
[
|
||||||
'elementId' => (string) $element->getId(),
|
'elementId' => (string) $element->getId(),
|
||||||
'fileType' => 'shortPdf',
|
'pdf' => $this->pdfUpload(),
|
||||||
'file' => $this->pdfUpload(),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -411,137 +365,51 @@ class ElementsEndpointTest extends TestCase
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthenticatedShortPdfUploadReturnsElementPayload(): void
|
public function testAuthenticatedPdfUploadReturnsElementPayload(): void
|
||||||
{
|
{
|
||||||
Storage::fake('public');
|
Storage::fake('public');
|
||||||
$setRepository = app(SetRepository::class);
|
$setRepository = app(SetRepository::class);
|
||||||
$elementRepository = app(ElementRepository::class);
|
$elementRepository = app(ElementRepository::class);
|
||||||
$set = $this->createSet($setRepository);
|
$set = $setRepository->create(new CreateSetDto(
|
||||||
$element = $this->createElement(
|
|
||||||
$elementRepository,
|
|
||||||
$set,
|
|
||||||
'Baderech HaAvodah',
|
|
||||||
'A structured path for growth',
|
|
||||||
null,
|
|
||||||
'<p>A structured path for growth</p>',
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
$this->createSession('valid-token');
|
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
|
||||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
|
||||||
->post(
|
|
||||||
'/api/element/update',
|
|
||||||
[
|
|
||||||
'elementId' => (string) $element->getId(),
|
|
||||||
'fileType' => 'shortPdf',
|
|
||||||
'file' => $this->pdfUpload(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
$response->assertOk();
|
|
||||||
$body = $response->json();
|
|
||||||
$this->assertSame($element->getId(), $body['element']['id']);
|
|
||||||
$this->assertStringContainsString(
|
|
||||||
'/storage/element-pdfs/short/',
|
|
||||||
$body['element']['shortPdfPath'],
|
|
||||||
);
|
|
||||||
$this->assertArrayNotHasKey('pdfPath', $body['element']);
|
|
||||||
$updatedElement = $elementRepository->find($element->getId());
|
|
||||||
$this->assertNotNull($updatedElement);
|
|
||||||
$updatedPdfPath = $updatedElement->getShortPdfPath();
|
|
||||||
$this->assertIsString($updatedPdfPath);
|
|
||||||
$this->assertStringStartsWith(
|
|
||||||
'element-pdfs/short/',
|
|
||||||
$updatedPdfPath,
|
|
||||||
);
|
|
||||||
Storage::disk('public')->assertExists($updatedPdfPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testAuthenticatedLongPdfUploadReturnsElementPayload(): void
|
|
||||||
{
|
|
||||||
Storage::fake('public');
|
|
||||||
$setRepository = app(SetRepository::class);
|
|
||||||
$elementRepository = app(ElementRepository::class);
|
|
||||||
$set = $this->createSet($setRepository);
|
|
||||||
$element = $this->createElement(
|
|
||||||
$elementRepository,
|
|
||||||
$set,
|
|
||||||
'Baderech HaAvodah',
|
|
||||||
'A structured path for growth',
|
|
||||||
null,
|
|
||||||
'<p>A structured path for growth</p>',
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
$this->createSession('valid-token');
|
|
||||||
|
|
||||||
$response = $this->withCredentials()
|
|
||||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
|
||||||
->post(
|
|
||||||
'/api/element/update',
|
|
||||||
[
|
|
||||||
'elementId' => (string) $element->getId(),
|
|
||||||
'fileType' => 'longPdf',
|
|
||||||
'file' => $this->pdfUpload(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
$response->assertOk();
|
|
||||||
$body = $response->json();
|
|
||||||
$this->assertSame($element->getId(), $body['element']['id']);
|
|
||||||
$this->assertStringContainsString(
|
|
||||||
'/storage/element-pdfs/long/',
|
|
||||||
$body['element']['longPdfPath'],
|
|
||||||
);
|
|
||||||
$updatedElement = $elementRepository->find($element->getId());
|
|
||||||
$this->assertNotNull($updatedElement);
|
|
||||||
$updatedPdfPath = $updatedElement->getLongPdfPath();
|
|
||||||
$this->assertIsString($updatedPdfPath);
|
|
||||||
$this->assertStringStartsWith(
|
|
||||||
'element-pdfs/long/',
|
|
||||||
$updatedPdfPath,
|
|
||||||
);
|
|
||||||
Storage::disk('public')->assertExists($updatedPdfPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createSet(SetRepository $setRepository): Set
|
|
||||||
{
|
|
||||||
return $setRepository->create(new CreateSetDto(
|
|
||||||
name: 'Baderech HaAvodah',
|
name: 'Baderech HaAvodah',
|
||||||
description: 'A structured path for growth',
|
description: 'A structured path for growth',
|
||||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||||
));
|
));
|
||||||
}
|
$element = $elementRepository->create(new CreateElementDto(
|
||||||
|
|
||||||
private function createElement(
|
|
||||||
ElementRepository $elementRepository,
|
|
||||||
Set $set,
|
|
||||||
string $title,
|
|
||||||
string $description,
|
|
||||||
?string $iconImageUrl,
|
|
||||||
string $richText,
|
|
||||||
?string $shortPdfPath,
|
|
||||||
?string $longPdfPath,
|
|
||||||
?string $youtubeUrl,
|
|
||||||
?Element $parentElement,
|
|
||||||
): Element {
|
|
||||||
return $elementRepository->create(new CreateElementDto(
|
|
||||||
set: $set,
|
set: $set,
|
||||||
title: $title,
|
title: 'Baderech HaAvodah',
|
||||||
description: $description,
|
description: 'A structured path for growth',
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: null,
|
||||||
richText: $richText,
|
richText: '<p>A structured path for growth</p>',
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: null,
|
||||||
longPdfPath: $longPdfPath,
|
youtubeUrl: null,
|
||||||
youtubeUrl: $youtubeUrl,
|
parentElement: null,
|
||||||
parentElement: $parentElement,
|
|
||||||
));
|
));
|
||||||
|
$this->createSession('valid-token');
|
||||||
|
|
||||||
|
$response = $this->withCredentials()
|
||||||
|
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||||
|
->post(
|
||||||
|
'/api/element/update',
|
||||||
|
[
|
||||||
|
'elementId' => (string) $element->getId(),
|
||||||
|
'pdf' => $this->pdfUpload(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$body = $response->json();
|
||||||
|
$this->assertSame($element->getId(), $body['element']['id']);
|
||||||
|
$this->assertStringContainsString(
|
||||||
|
'/storage/element-pdfs/',
|
||||||
|
$body['element']['pdfPath'],
|
||||||
|
);
|
||||||
|
$updatedElement = $elementRepository->find($element->getId());
|
||||||
|
$this->assertNotNull($updatedElement);
|
||||||
|
$updatedPdfPath = $updatedElement->getPdfPath();
|
||||||
|
$this->assertIsString($updatedPdfPath);
|
||||||
|
$this->assertStringStartsWith('element-pdfs/', $updatedPdfPath);
|
||||||
|
Storage::disk('public')->assertExists($updatedPdfPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createSession(string $token): void
|
private function createSession(string $token): void
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,7 @@ class SetsEndpointTest extends TestCase
|
||||||
description: $baderechSet->getDescription(),
|
description: $baderechSet->getDescription(),
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '',
|
richText: '',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,9 @@ use App\Element\UseCases\UpdateElement\UpdateDescription;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateElement;
|
use App\Element\UseCases\UpdateElement\UpdateElement;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
||||||
use App\Set\Set as DomainSet;
|
use App\Set\Set as DomainSet;
|
||||||
|
|
@ -42,18 +40,13 @@ class ElementControllerTest extends TestCase
|
||||||
new UpdateDescription($this->elementRepo),
|
new UpdateDescription($this->elementRepo),
|
||||||
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
||||||
new UpdateRichText($this->elementRepo),
|
new UpdateRichText($this->elementRepo),
|
||||||
new UpdateShortPdfPath($this->elementRepo, $this->fileUploader),
|
new UpdatePdfPath($this->elementRepo, $this->fileUploader),
|
||||||
new UpdateLongPdfPath($this->elementRepo, $this->fileUploader),
|
|
||||||
new UpdateYoutubeUrl($this->elementRepo),
|
new UpdateYoutubeUrl($this->elementRepo),
|
||||||
new UpdateIconImage(
|
new UpdateIconImage(
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
),
|
),
|
||||||
new UpdateShortPdf(
|
new UpdatePdf(
|
||||||
$this->elementRepo,
|
|
||||||
$this->fileUploader,
|
|
||||||
),
|
|
||||||
new UpdateLongPdf(
|
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
),
|
),
|
||||||
|
|
@ -76,7 +69,6 @@ class ElementControllerTest extends TestCase
|
||||||
'/assets/baderech-icon.png',
|
'/assets/baderech-icon.png',
|
||||||
'<p>A structured path for growth</p>',
|
'<p>A structured path for growth</p>',
|
||||||
'/assets/pdfs/baderech.pdf',
|
'/assets/pdfs/baderech.pdf',
|
||||||
'/assets/pdfs/baderech-long.pdf',
|
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
@ -88,7 +80,6 @@ class ElementControllerTest extends TestCase
|
||||||
'<p>Foundations rich text</p>',
|
'<p>Foundations rich text</p>',
|
||||||
'/assets/pdfs/foundations.pdf',
|
'/assets/pdfs/foundations.pdf',
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
$element,
|
$element,
|
||||||
);
|
);
|
||||||
$secondChildElement = $this->createElement(
|
$secondChildElement = $this->createElement(
|
||||||
|
|
@ -99,7 +90,6 @@ class ElementControllerTest extends TestCase
|
||||||
'<p>Daily practice rich text</p>',
|
'<p>Daily practice rich text</p>',
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
$element,
|
$element,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -123,13 +113,8 @@ class ElementControllerTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'/assets/pdfs/baderech.pdf',
|
'/assets/pdfs/baderech.pdf',
|
||||||
$body['element']['shortPdfPath'],
|
$body['element']['pdfPath'],
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/baderech-long.pdf',
|
|
||||||
$body['element']['longPdfPath'],
|
|
||||||
);
|
|
||||||
$this->assertArrayNotHasKey('pdfPath', $body['element']);
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
$body['element']['youtubeUrl'],
|
$body['element']['youtubeUrl'],
|
||||||
|
|
@ -173,13 +158,21 @@ class ElementControllerTest extends TestCase
|
||||||
public function testUpdateWithIconImageReturnsElementPayload(): void
|
public function testUpdateWithIconImageReturnsElementPayload(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet(1, 'Baderech');
|
$set = $this->createSet(1, 'Baderech');
|
||||||
$element = $this->createEmptyElement($set);
|
$element = $this->createElement(
|
||||||
|
$set,
|
||||||
|
'Baderech HaAvodah',
|
||||||
|
'A structured path for growth',
|
||||||
|
null,
|
||||||
|
'<p>A structured path for growth</p>',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
);
|
||||||
$fixturePath = __DIR__ . '/../../fixtures/icon.png';
|
$fixturePath = __DIR__ . '/../../fixtures/icon.png';
|
||||||
$request = new Request([], [
|
$request = new Request([], [
|
||||||
'elementId' => (string) $element->getId(),
|
'elementId' => (string) $element->getId(),
|
||||||
'fileType' => 'iconImage',
|
|
||||||
], [], [], [
|
], [], [], [
|
||||||
'file' => new UploadedFile(
|
'iconImage' => new UploadedFile(
|
||||||
$fixturePath,
|
$fixturePath,
|
||||||
'icon.png',
|
'icon.png',
|
||||||
'image/png',
|
'image/png',
|
||||||
|
|
@ -203,16 +196,24 @@ class ElementControllerTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateWithShortPdfReturnsElementPayload(): void
|
public function testUpdateWithPdfReturnsElementPayload(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet(1, 'Baderech');
|
$set = $this->createSet(1, 'Baderech');
|
||||||
$element = $this->createEmptyElement($set);
|
$element = $this->createElement(
|
||||||
|
$set,
|
||||||
|
'Baderech HaAvodah',
|
||||||
|
'A structured path for growth',
|
||||||
|
null,
|
||||||
|
'<p>A structured path for growth</p>',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
);
|
||||||
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
||||||
$request = new Request([], [
|
$request = new Request([], [
|
||||||
'elementId' => (string) $element->getId(),
|
'elementId' => (string) $element->getId(),
|
||||||
'fileType' => 'shortPdf',
|
|
||||||
], [], [], [
|
], [], [], [
|
||||||
'file' => new UploadedFile(
|
'pdf' => new UploadedFile(
|
||||||
$fixturePath,
|
$fixturePath,
|
||||||
'baderech.pdf',
|
'baderech.pdf',
|
||||||
'application/pdf',
|
'application/pdf',
|
||||||
|
|
@ -227,45 +228,11 @@ class ElementControllerTest extends TestCase
|
||||||
$body = json_decode($response->getContent(), true);
|
$body = json_decode($response->getContent(), true);
|
||||||
$this->assertSame($element->getId(), $body['element']['id']);
|
$this->assertSame($element->getId(), $body['element']['id']);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://test.local/storage/element-pdfs/short/fake-baderech.pdf',
|
'https://test.local/storage/element-pdfs/fake-baderech.pdf',
|
||||||
$body['element']['shortPdfPath'],
|
$body['element']['pdfPath'],
|
||||||
);
|
|
||||||
$this->assertArrayNotHasKey('pdfPath', $body['element']);
|
|
||||||
$this->assertSame(
|
|
||||||
'element-pdfs/short',
|
|
||||||
$this->fileUploader->uploads[0]['folder'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateWithLongPdfReturnsElementPayload(): void
|
|
||||||
{
|
|
||||||
$set = $this->createSet(1, 'Baderech');
|
|
||||||
$element = $this->createEmptyElement($set);
|
|
||||||
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
|
||||||
$request = new Request([], [
|
|
||||||
'elementId' => (string) $element->getId(),
|
|
||||||
'fileType' => 'longPdf',
|
|
||||||
], [], [], [
|
|
||||||
'file' => new UploadedFile(
|
|
||||||
$fixturePath,
|
|
||||||
'baderech.pdf',
|
|
||||||
'application/pdf',
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
], ['REQUEST_METHOD' => 'POST']);
|
|
||||||
|
|
||||||
$response = $this->controller->update($request);
|
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
|
||||||
$body = json_decode($response->getContent(), true);
|
|
||||||
$this->assertSame($element->getId(), $body['element']['id']);
|
|
||||||
$this->assertSame(
|
|
||||||
'https://test.local/storage/element-pdfs/long/fake-baderech.pdf',
|
|
||||||
$body['element']['longPdfPath'],
|
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/long',
|
'element-pdfs',
|
||||||
$this->fileUploader->uploads[0]['folder'],
|
$this->fileUploader->uploads[0]['folder'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -280,29 +247,13 @@ class ElementControllerTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createEmptyElement(DomainSet $set): Element
|
|
||||||
{
|
|
||||||
return $this->createElement(
|
|
||||||
$set,
|
|
||||||
'Baderech HaAvodah',
|
|
||||||
'A structured path for growth',
|
|
||||||
null,
|
|
||||||
'<p>A structured path for growth</p>',
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createElement(
|
private function createElement(
|
||||||
DomainSet $set,
|
DomainSet $set,
|
||||||
string $title,
|
string $title,
|
||||||
string $description,
|
string $description,
|
||||||
?string $iconImageUrl,
|
?string $iconImageUrl,
|
||||||
string $richText,
|
string $richText,
|
||||||
?string $shortPdfPath,
|
?string $pdfPath,
|
||||||
?string $longPdfPath,
|
|
||||||
?string $youtubeUrl,
|
?string $youtubeUrl,
|
||||||
?Element $parentElement,
|
?Element $parentElement,
|
||||||
): Element {
|
): Element {
|
||||||
|
|
@ -312,8 +263,7 @@ class ElementControllerTest extends TestCase
|
||||||
description: $description,
|
description: $description,
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: $iconImageUrl,
|
||||||
richText: $richText,
|
richText: $richText,
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: $pdfPath,
|
||||||
longPdfPath: $longPdfPath,
|
|
||||||
youtubeUrl: $youtubeUrl,
|
youtubeUrl: $youtubeUrl,
|
||||||
parentElement: $parentElement,
|
parentElement: $parentElement,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,7 @@ class ElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
set: $set,
|
set: $set,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
|
|
@ -34,8 +33,7 @@ class ElementTest extends TestCase
|
||||||
description: 'Child description',
|
description: 'Child description',
|
||||||
iconImageUrl: '/assets/child-icon.svg',
|
iconImageUrl: '/assets/child-icon.svg',
|
||||||
richText: '<p>Child rich text</p>',
|
richText: '<p>Child rich text</p>',
|
||||||
shortPdfPath: '/assets/pdfs/child.pdf',
|
pdfPath: '/assets/pdfs/child.pdf',
|
||||||
longPdfPath: '/assets/pdfs/child-long.pdf',
|
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
set: $set,
|
set: $set,
|
||||||
parentElement: $rootElement,
|
parentElement: $rootElement,
|
||||||
|
|
@ -57,11 +55,7 @@ class ElementTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'/assets/pdfs/child.pdf',
|
'/assets/pdfs/child.pdf',
|
||||||
$childElement->getShortPdfPath(),
|
$childElement->getPdfPath(),
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/child-long.pdf',
|
|
||||||
$childElement->getLongPdfPath(),
|
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
|
|
@ -70,8 +64,7 @@ class ElementTest extends TestCase
|
||||||
$this->assertSame($set, $childElement->getSet());
|
$this->assertSame($set, $childElement->getSet());
|
||||||
$this->assertSame($rootElement, $childElement->getParentElement());
|
$this->assertSame($rootElement, $childElement->getParentElement());
|
||||||
$this->assertNull($rootElement->getIconImageUrl());
|
$this->assertNull($rootElement->getIconImageUrl());
|
||||||
$this->assertNull($rootElement->getShortPdfPath());
|
$this->assertNull($rootElement->getPdfPath());
|
||||||
$this->assertNull($rootElement->getLongPdfPath());
|
|
||||||
$this->assertNull($rootElement->getYoutubeUrl());
|
$this->assertNull($rootElement->getYoutubeUrl());
|
||||||
$this->assertNull($rootElement->getParentElement());
|
$this->assertNull($rootElement->getParentElement());
|
||||||
}
|
}
|
||||||
|
|
@ -90,8 +83,7 @@ class ElementTest extends TestCase
|
||||||
description: 'Original description',
|
description: 'Original description',
|
||||||
iconImageUrl: '/assets/original.svg',
|
iconImageUrl: '/assets/original.svg',
|
||||||
richText: '<p>Original</p>',
|
richText: '<p>Original</p>',
|
||||||
shortPdfPath: '/assets/pdfs/original.pdf',
|
pdfPath: '/assets/pdfs/original.pdf',
|
||||||
longPdfPath: '/assets/pdfs/original-long.pdf',
|
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
|
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
|
||||||
set: $set,
|
set: $set,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
|
|
@ -101,16 +93,14 @@ class ElementTest extends TestCase
|
||||||
$element->setDescription('Updated description');
|
$element->setDescription('Updated description');
|
||||||
$element->setIconImageUrl(null);
|
$element->setIconImageUrl(null);
|
||||||
$element->setRichText('<p>Updated</p>');
|
$element->setRichText('<p>Updated</p>');
|
||||||
$element->setShortPdfPath(null);
|
$element->setPdfPath(null);
|
||||||
$element->setLongPdfPath(null);
|
|
||||||
$element->setYoutubeUrl(null);
|
$element->setYoutubeUrl(null);
|
||||||
|
|
||||||
$this->assertSame('Updated', $element->getTitle());
|
$this->assertSame('Updated', $element->getTitle());
|
||||||
$this->assertSame('Updated description', $element->getDescription());
|
$this->assertSame('Updated description', $element->getDescription());
|
||||||
$this->assertNull($element->getIconImageUrl());
|
$this->assertNull($element->getIconImageUrl());
|
||||||
$this->assertSame('<p>Updated</p>', $element->getRichText());
|
$this->assertSame('<p>Updated</p>', $element->getRichText());
|
||||||
$this->assertNull($element->getShortPdfPath());
|
$this->assertNull($element->getPdfPath());
|
||||||
$this->assertNull($element->getLongPdfPath());
|
|
||||||
$this->assertNull($element->getYoutubeUrl());
|
$this->assertNull($element->getYoutubeUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: '/assets/root-icon.svg',
|
iconImageUrl: '/assets/root-icon.svg',
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: '/assets/pdfs/root.pdf',
|
pdfPath: '/assets/pdfs/root.pdf',
|
||||||
longPdfPath: '/assets/pdfs/root-long.pdf',
|
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -64,14 +63,7 @@ class CreateElementTest extends TestCase
|
||||||
$element->getIconImageUrl(),
|
$element->getIconImageUrl(),
|
||||||
);
|
);
|
||||||
$this->assertSame('<p>Root rich text</p>', $element->getRichText());
|
$this->assertSame('<p>Root rich text</p>', $element->getRichText());
|
||||||
$this->assertSame(
|
$this->assertSame('/assets/pdfs/root.pdf', $element->getPdfPath());
|
||||||
'/assets/pdfs/root.pdf',
|
|
||||||
$element->getShortPdfPath(),
|
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/root-long.pdf',
|
|
||||||
$element->getLongPdfPath(),
|
|
||||||
);
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
$element->getYoutubeUrl(),
|
$element->getYoutubeUrl(),
|
||||||
|
|
@ -90,8 +82,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
)
|
)
|
||||||
|
|
@ -104,8 +95,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Child description',
|
description: 'Child description',
|
||||||
iconImageUrl: '/assets/child-icon.svg',
|
iconImageUrl: '/assets/child-icon.svg',
|
||||||
richText: '<p>Child rich text</p>',
|
richText: '<p>Child rich text</p>',
|
||||||
shortPdfPath: '/assets/pdfs/child.pdf',
|
pdfPath: '/assets/pdfs/child.pdf',
|
||||||
longPdfPath: '/assets/pdfs/child-long.pdf',
|
|
||||||
youtubeUrl: 'https://youtu.be/yHx-r4p6hHU',
|
youtubeUrl: 'https://youtu.be/yHx-r4p6hHU',
|
||||||
parentElementId: $rootElement->getId(),
|
parentElementId: $rootElement->getId(),
|
||||||
)
|
)
|
||||||
|
|
@ -126,11 +116,7 @@ class CreateElementTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'/assets/pdfs/child.pdf',
|
'/assets/pdfs/child.pdf',
|
||||||
$childElement->getShortPdfPath(),
|
$childElement->getPdfPath(),
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/child-long.pdf',
|
|
||||||
$childElement->getLongPdfPath(),
|
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://youtu.be/yHx-r4p6hHU',
|
'https://youtu.be/yHx-r4p6hHU',
|
||||||
|
|
@ -152,8 +138,7 @@ class CreateElementTest extends TestCase
|
||||||
description: null,
|
description: null,
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: null,
|
richText: null,
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -161,8 +146,7 @@ class CreateElementTest extends TestCase
|
||||||
$this->assertSame('', $element->getDescription());
|
$this->assertSame('', $element->getDescription());
|
||||||
$this->assertNull($element->getIconImageUrl());
|
$this->assertNull($element->getIconImageUrl());
|
||||||
$this->assertSame('', $element->getRichText());
|
$this->assertSame('', $element->getRichText());
|
||||||
$this->assertNull($element->getShortPdfPath());
|
$this->assertNull($element->getPdfPath());
|
||||||
$this->assertNull($element->getLongPdfPath());
|
|
||||||
$this->assertNull($element->getYoutubeUrl());
|
$this->assertNull($element->getYoutubeUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,8 +160,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: '',
|
iconImageUrl: '',
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -185,7 +168,7 @@ class CreateElementTest extends TestCase
|
||||||
$this->assertNull($element->getIconImageUrl());
|
$this->assertNull($element->getIconImageUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreatesElementWithNullPdfPathsWhenBlank(): void
|
public function testCreatesElementWithNullPdfPathWhenBlank(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet('Daily learning');
|
$set = $this->createSet('Daily learning');
|
||||||
|
|
||||||
|
|
@ -195,14 +178,12 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: '',
|
pdfPath: '',
|
||||||
longPdfPath: '',
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertNull($element->getShortPdfPath());
|
$this->assertNull($element->getPdfPath());
|
||||||
$this->assertNull($element->getLongPdfPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreatesElementWithNullYoutubeUrlWhenBlank(): void
|
public function testCreatesElementWithNullYoutubeUrlWhenBlank(): void
|
||||||
|
|
@ -215,8 +196,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: '',
|
youtubeUrl: '',
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -235,8 +215,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -253,8 +232,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -271,8 +249,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -293,8 +270,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Child description',
|
description: 'Child description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Child rich text</p>',
|
richText: '<p>Child rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: 99,
|
parentElementId: 99,
|
||||||
));
|
));
|
||||||
|
|
@ -309,8 +285,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Root description',
|
description: 'Root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Root rich text</p>',
|
richText: '<p>Root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -326,8 +301,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Another root description',
|
description: 'Another root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Another root rich text</p>',
|
richText: '<p>Another root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
));
|
));
|
||||||
|
|
@ -344,8 +318,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Parent root description',
|
description: 'Parent root description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Parent root rich text</p>',
|
richText: '<p>Parent root rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: null,
|
parentElementId: null,
|
||||||
)
|
)
|
||||||
|
|
@ -362,8 +335,7 @@ class CreateElementTest extends TestCase
|
||||||
description: 'Invalid child description',
|
description: 'Invalid child description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Invalid child rich text</p>',
|
richText: '<p>Invalid child rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElementId: $parentElement->getId(),
|
parentElementId: $parentElement->getId(),
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class GetElementTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'/assets/pdfs/baderech.pdf',
|
'/assets/pdfs/baderech.pdf',
|
||||||
$foundElement->getShortPdfPath(),
|
$foundElement->getPdfPath(),
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
|
|
@ -191,7 +191,7 @@ class GetElementTest extends TestCase
|
||||||
string $description,
|
string $description,
|
||||||
?string $iconImageUrl,
|
?string $iconImageUrl,
|
||||||
string $richText,
|
string $richText,
|
||||||
?string $shortPdfPath,
|
?string $pdfPath,
|
||||||
?string $youtubeUrl,
|
?string $youtubeUrl,
|
||||||
?Element $parentElement,
|
?Element $parentElement,
|
||||||
): Element {
|
): Element {
|
||||||
|
|
@ -201,8 +201,7 @@ class GetElementTest extends TestCase
|
||||||
description: $description,
|
description: $description,
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: $iconImageUrl,
|
||||||
richText: $richText,
|
richText: $richText,
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: $pdfPath,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: $youtubeUrl,
|
youtubeUrl: $youtubeUrl,
|
||||||
parentElement: $parentElement,
|
parentElement: $parentElement,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,8 @@ use App\Element\UseCases\UpdateElement\UpdateDescription;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateDescriptionRequest;
|
use App\Element\UseCases\UpdateElement\UpdateDescriptionRequest;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrlRequest;
|
use App\Element\UseCases\UpdateElement\UpdateIconImageUrlRequest;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPathRequest;
|
use App\Element\UseCases\UpdateElement\UpdatePdfPathRequest;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPathRequest;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateRichTextRequest;
|
use App\Element\UseCases\UpdateElement\UpdateRichTextRequest;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||||
|
|
@ -136,26 +134,19 @@ class UpdateElementFieldsTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateShortPdfPathClearsEmptyString(): void
|
public function testUpdatePdfPathClearsEmptyString(): void
|
||||||
{
|
{
|
||||||
$element = $this->createFilledElement();
|
$element = $this->createFilledElement();
|
||||||
$updateShortPdfPath = new UpdateShortPdfPath(
|
$updatePdfPath = new UpdatePdfPath(
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
);
|
);
|
||||||
|
|
||||||
$updatedElement = $updateShortPdfPath->execute(
|
$updatedElement = $updatePdfPath->execute(
|
||||||
new UpdateShortPdfPathRequest(
|
new UpdatePdfPathRequest(id: $element->getId(), pdfPath: '')
|
||||||
id: $element->getId(),
|
|
||||||
shortPdfPath: '',
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertNull($updatedElement->getShortPdfPath());
|
$this->assertNull($updatedElement->getPdfPath());
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/original-long.pdf',
|
|
||||||
$updatedElement->getLongPdfPath(),
|
|
||||||
);
|
|
||||||
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
|
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
['/assets/pdfs/original.pdf'],
|
['/assets/pdfs/original.pdf'],
|
||||||
|
|
@ -163,33 +154,6 @@ class UpdateElementFieldsTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateLongPdfPathClearsEmptyString(): void
|
|
||||||
{
|
|
||||||
$element = $this->createFilledElement();
|
|
||||||
$updateLongPdfPath = new UpdateLongPdfPath(
|
|
||||||
$this->elementRepo,
|
|
||||||
$this->fileUploader,
|
|
||||||
);
|
|
||||||
|
|
||||||
$updatedElement = $updateLongPdfPath->execute(
|
|
||||||
new UpdateLongPdfPathRequest(
|
|
||||||
id: $element->getId(),
|
|
||||||
longPdfPath: '',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/original.pdf',
|
|
||||||
$updatedElement->getShortPdfPath(),
|
|
||||||
);
|
|
||||||
$this->assertNull($updatedElement->getLongPdfPath());
|
|
||||||
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
|
|
||||||
$this->assertSame(
|
|
||||||
['/assets/pdfs/original-long.pdf'],
|
|
||||||
$this->fileUploader->deletedPaths,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateYoutubeUrlClearsEmptyString(): void
|
public function testUpdateYoutubeUrlClearsEmptyString(): void
|
||||||
{
|
{
|
||||||
$element = $this->createFilledElement();
|
$element = $this->createFilledElement();
|
||||||
|
|
@ -211,14 +175,12 @@ class UpdateElementFieldsTest extends TestCase
|
||||||
return $this->createElementWithMedia(
|
return $this->createElementWithMedia(
|
||||||
'/assets/original-icon.png',
|
'/assets/original-icon.png',
|
||||||
'/assets/pdfs/original.pdf',
|
'/assets/pdfs/original.pdf',
|
||||||
'/assets/pdfs/original-long.pdf',
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createElementWithMedia(
|
private function createElementWithMedia(
|
||||||
?string $iconImageUrl,
|
?string $iconImageUrl,
|
||||||
?string $shortPdfPath,
|
?string $pdfPath,
|
||||||
?string $longPdfPath,
|
|
||||||
): Element {
|
): Element {
|
||||||
$set = new DomainSet(
|
$set = new DomainSet(
|
||||||
id: 1,
|
id: 1,
|
||||||
|
|
@ -233,8 +195,7 @@ class UpdateElementFieldsTest extends TestCase
|
||||||
description: 'Original description',
|
description: 'Original description',
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: $iconImageUrl,
|
||||||
richText: '<p>Original rich text</p>',
|
richText: '<p>Original rich text</p>',
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: $pdfPath,
|
||||||
longPdfPath: $longPdfPath,
|
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
|
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,9 @@ use App\Element\UseCases\UpdateElement\UpdateElement;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
|
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
||||||
use App\Exceptions\BadRequestException;
|
use App\Exceptions\BadRequestException;
|
||||||
|
|
@ -40,18 +38,13 @@ class UpdateElementTest extends TestCase
|
||||||
new UpdateDescription($this->elementRepo),
|
new UpdateDescription($this->elementRepo),
|
||||||
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
||||||
new UpdateRichText($this->elementRepo),
|
new UpdateRichText($this->elementRepo),
|
||||||
new UpdateShortPdfPath($this->elementRepo, $this->fileUploader),
|
new UpdatePdfPath($this->elementRepo, $this->fileUploader),
|
||||||
new UpdateLongPdfPath($this->elementRepo, $this->fileUploader),
|
|
||||||
new UpdateYoutubeUrl($this->elementRepo),
|
new UpdateYoutubeUrl($this->elementRepo),
|
||||||
new UpdateIconImage(
|
new UpdateIconImage(
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
),
|
),
|
||||||
new UpdateShortPdf(
|
new UpdatePdf(
|
||||||
$this->elementRepo,
|
|
||||||
$this->fileUploader,
|
|
||||||
),
|
|
||||||
new UpdateLongPdf(
|
|
||||||
$this->elementRepo,
|
$this->elementRepo,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
),
|
),
|
||||||
|
|
@ -69,7 +62,6 @@ class UpdateElementTest extends TestCase
|
||||||
'/assets/original-icon.png',
|
'/assets/original-icon.png',
|
||||||
'<p>Original rich text</p>',
|
'<p>Original rich text</p>',
|
||||||
'/assets/pdfs/original.pdf',
|
'/assets/pdfs/original.pdf',
|
||||||
'/assets/pdfs/original-long.pdf',
|
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
@ -81,14 +73,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
iconImageUrl: '/assets/updated-icon.png',
|
iconImageUrl: '/assets/updated-icon.png',
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
shortPdfPath: '/assets/pdfs/updated.pdf',
|
pdfPath: '/assets/pdfs/updated.pdf',
|
||||||
longPdfPath: '/assets/pdfs/updated-long.pdf',
|
|
||||||
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -108,11 +102,7 @@ class UpdateElementTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'/assets/pdfs/updated.pdf',
|
'/assets/pdfs/updated.pdf',
|
||||||
$updatedElement->getShortPdfPath(),
|
$updatedElement->getPdfPath(),
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/updated-long.pdf',
|
|
||||||
$updatedElement->getLongPdfPath(),
|
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||||
|
|
@ -134,7 +124,6 @@ class UpdateElementTest extends TestCase
|
||||||
'/assets/original-icon.png',
|
'/assets/original-icon.png',
|
||||||
'<p>Original rich text</p>',
|
'<p>Original rich text</p>',
|
||||||
'/assets/pdfs/original.pdf',
|
'/assets/pdfs/original.pdf',
|
||||||
'/assets/pdfs/original-long.pdf',
|
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
@ -146,20 +135,21 @@ class UpdateElementTest extends TestCase
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
iconImageUrl: '',
|
iconImageUrl: '',
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
shortPdfPath: '',
|
pdfPath: '',
|
||||||
longPdfPath: '',
|
|
||||||
youtubeUrl: '',
|
youtubeUrl: '',
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertNull($updatedElement->getIconImageUrl());
|
$this->assertNull($updatedElement->getIconImageUrl());
|
||||||
$this->assertNull($updatedElement->getShortPdfPath());
|
$this->assertNull($updatedElement->getPdfPath());
|
||||||
$this->assertNull($updatedElement->getLongPdfPath());
|
|
||||||
$this->assertNull($updatedElement->getYoutubeUrl());
|
$this->assertNull($updatedElement->getYoutubeUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +163,6 @@ class UpdateElementTest extends TestCase
|
||||||
'/assets/original-icon.png',
|
'/assets/original-icon.png',
|
||||||
'<p>Original rich text</p>',
|
'<p>Original rich text</p>',
|
||||||
'/assets/pdfs/original.pdf',
|
'/assets/pdfs/original.pdf',
|
||||||
'/assets/pdfs/original-long.pdf',
|
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
@ -185,14 +174,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: null,
|
description: null,
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: null,
|
richText: null,
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -211,11 +202,7 @@ class UpdateElementTest extends TestCase
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'/assets/pdfs/original.pdf',
|
'/assets/pdfs/original.pdf',
|
||||||
$updatedElement->getShortPdfPath(),
|
$updatedElement->getPdfPath(),
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'/assets/pdfs/original-long.pdf',
|
|
||||||
$updatedElement->getLongPdfPath(),
|
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||||
|
|
@ -223,7 +210,7 @@ class UpdateElementTest extends TestCase
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRoutesUploadedFilesByFileType(): void
|
public function testUpdatesUploadedFiles(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet(1, 'Baderech');
|
$set = $this->createSet(1, 'Baderech');
|
||||||
$element = $this->createElement(
|
$element = $this->createElement(
|
||||||
|
|
@ -235,39 +222,8 @@ class UpdateElementTest extends TestCase
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->updateElement->execute(new UpdateElementRequest(
|
|
||||||
id: $element->getId(),
|
|
||||||
title: null,
|
|
||||||
description: null,
|
|
||||||
iconImageUrl: null,
|
|
||||||
richText: null,
|
|
||||||
shortPdfPath: null,
|
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
|
||||||
fileType: 'iconImage',
|
|
||||||
fileContents: 'binary-image-bytes',
|
|
||||||
fileOriginalName: 'icon.png',
|
|
||||||
fileMimeType: 'image/png',
|
|
||||||
fileSizeBytes: 1024,
|
|
||||||
));
|
|
||||||
$this->updateElement->execute(new UpdateElementRequest(
|
|
||||||
id: $element->getId(),
|
|
||||||
title: null,
|
|
||||||
description: null,
|
|
||||||
iconImageUrl: null,
|
|
||||||
richText: null,
|
|
||||||
shortPdfPath: null,
|
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
|
||||||
fileType: 'shortPdf',
|
|
||||||
fileContents: 'binary-short-pdf-bytes',
|
|
||||||
fileOriginalName: 'baderech.pdf',
|
|
||||||
fileMimeType: 'application/pdf',
|
|
||||||
fileSizeBytes: 1024,
|
|
||||||
));
|
|
||||||
$updatedElement = $this->updateElement->execute(
|
$updatedElement = $this->updateElement->execute(
|
||||||
new UpdateElementRequest(
|
new UpdateElementRequest(
|
||||||
id: $element->getId(),
|
id: $element->getId(),
|
||||||
|
|
@ -275,14 +231,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: null,
|
description: null,
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: null,
|
richText: null,
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
fileType: 'longPdf',
|
iconImageContents: 'binary-image-bytes',
|
||||||
fileContents: 'binary-long-pdf-bytes',
|
iconImageOriginalName: 'icon.png',
|
||||||
fileOriginalName: 'baderech-long.pdf',
|
iconImageMimeType: 'image/png',
|
||||||
fileMimeType: 'application/pdf',
|
iconImageSizeBytes: 1024,
|
||||||
fileSizeBytes: 1024,
|
pdfContents: 'binary-pdf-bytes',
|
||||||
|
pdfOriginalName: 'baderech.pdf',
|
||||||
|
pdfMimeType: 'application/pdf',
|
||||||
|
pdfSizeBytes: 1024,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -291,69 +249,17 @@ class UpdateElementTest extends TestCase
|
||||||
$updatedElement->getIconImageUrl(),
|
$updatedElement->getIconImageUrl(),
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/short/fake-baderech.pdf',
|
'element-pdfs/fake-baderech.pdf',
|
||||||
$updatedElement->getShortPdfPath(),
|
$updatedElement->getPdfPath(),
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'element-pdfs/long/fake-baderech-long.pdf',
|
|
||||||
$updatedElement->getLongPdfPath(),
|
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-icons',
|
'element-icons',
|
||||||
$this->fileUploader->uploads[0]['folder'],
|
$this->fileUploader->uploads[0]['folder'],
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/short',
|
'element-pdfs',
|
||||||
$this->fileUploader->uploads[1]['folder'],
|
$this->fileUploader->uploads[1]['folder'],
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
|
||||||
'element-pdfs/long',
|
|
||||||
$this->fileUploader->uploads[2]['folder'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThrowsWhenFileTypeMissingForUpload(): void
|
|
||||||
{
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('fileType is required');
|
|
||||||
|
|
||||||
$this->updateElement->execute(new UpdateElementRequest(
|
|
||||||
id: 1,
|
|
||||||
title: null,
|
|
||||||
description: null,
|
|
||||||
iconImageUrl: null,
|
|
||||||
richText: null,
|
|
||||||
shortPdfPath: null,
|
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
|
||||||
fileType: null,
|
|
||||||
fileContents: 'binary-image-bytes',
|
|
||||||
fileOriginalName: 'icon.png',
|
|
||||||
fileMimeType: 'image/png',
|
|
||||||
fileSizeBytes: 1024,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testThrowsWhenFileTypeInvalid(): void
|
|
||||||
{
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('fileType is invalid');
|
|
||||||
|
|
||||||
$this->updateElement->execute(new UpdateElementRequest(
|
|
||||||
id: 1,
|
|
||||||
title: null,
|
|
||||||
description: null,
|
|
||||||
iconImageUrl: null,
|
|
||||||
richText: null,
|
|
||||||
shortPdfPath: null,
|
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
|
||||||
fileType: 'audio',
|
|
||||||
fileContents: 'binary-audio-bytes',
|
|
||||||
fileOriginalName: 'shiur.mp3',
|
|
||||||
fileMimeType: 'audio/mpeg',
|
|
||||||
fileSizeBytes: 1024,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testThrowsWhenIdMissing(): void
|
public function testThrowsWhenIdMissing(): void
|
||||||
|
|
@ -367,14 +273,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,14 +297,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: null,
|
description: null,
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: null,
|
richText: null,
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -411,14 +321,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -433,14 +345,16 @@ class UpdateElementTest extends TestCase
|
||||||
description: 'Updated description',
|
description: 'Updated description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '<p>Updated rich text</p>',
|
richText: '<p>Updated rich text</p>',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
fileType: null,
|
iconImageContents: null,
|
||||||
fileContents: null,
|
iconImageOriginalName: null,
|
||||||
fileOriginalName: null,
|
iconImageMimeType: null,
|
||||||
fileMimeType: null,
|
iconImageSizeBytes: null,
|
||||||
fileSizeBytes: null,
|
pdfContents: null,
|
||||||
|
pdfOriginalName: null,
|
||||||
|
pdfMimeType: null,
|
||||||
|
pdfSizeBytes: null,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -460,8 +374,7 @@ class UpdateElementTest extends TestCase
|
||||||
string $description,
|
string $description,
|
||||||
?string $iconImageUrl,
|
?string $iconImageUrl,
|
||||||
string $richText,
|
string $richText,
|
||||||
?string $shortPdfPath,
|
?string $pdfPath,
|
||||||
?string $longPdfPath,
|
|
||||||
?string $youtubeUrl,
|
?string $youtubeUrl,
|
||||||
?Element $parentElement,
|
?Element $parentElement,
|
||||||
): Element {
|
): Element {
|
||||||
|
|
@ -471,8 +384,7 @@ class UpdateElementTest extends TestCase
|
||||||
description: $description,
|
description: $description,
|
||||||
iconImageUrl: $iconImageUrl,
|
iconImageUrl: $iconImageUrl,
|
||||||
richText: $richText,
|
richText: $richText,
|
||||||
shortPdfPath: $shortPdfPath,
|
pdfPath: $pdfPath,
|
||||||
longPdfPath: $longPdfPath,
|
|
||||||
youtubeUrl: $youtubeUrl,
|
youtubeUrl: $youtubeUrl,
|
||||||
parentElement: $parentElement,
|
parentElement: $parentElement,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -33,19 +33,19 @@ class UpdateIconImageTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{
|
* @return array{
|
||||||
* fileContents: string,
|
* iconImageContents: string,
|
||||||
* fileOriginalName: string,
|
* iconImageOriginalName: string,
|
||||||
* fileMimeType: string,
|
* iconImageMimeType: string,
|
||||||
* fileSizeBytes: int
|
* iconImageSizeBytes: int
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
private function imageArgs(): array
|
private function imageArgs(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'fileContents' => 'binary-image-bytes',
|
'iconImageContents' => 'binary-image-bytes',
|
||||||
'fileOriginalName' => 'icon.png',
|
'iconImageOriginalName' => 'icon.png',
|
||||||
'fileMimeType' => 'image/png',
|
'iconImageMimeType' => 'image/png',
|
||||||
'fileSizeBytes' => 1024,
|
'iconImageSizeBytes' => 1024,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -97,10 +97,10 @@ class UpdateIconImageTest extends TestCase
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateIconImageRequest(
|
new UpdateIconImageRequest(
|
||||||
id: 1,
|
id: 1,
|
||||||
fileContents: null,
|
iconImageContents: null,
|
||||||
fileOriginalName: null,
|
iconImageOriginalName: null,
|
||||||
fileMimeType: null,
|
iconImageMimeType: null,
|
||||||
fileSizeBytes: null,
|
iconImageSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -115,10 +115,10 @@ class UpdateIconImageTest extends TestCase
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateIconImageRequest(
|
new UpdateIconImageRequest(
|
||||||
id: 1,
|
id: 1,
|
||||||
fileContents: 'not-an-image',
|
iconImageContents: 'not-an-image',
|
||||||
fileOriginalName: 'icon.pdf',
|
iconImageOriginalName: 'icon.pdf',
|
||||||
fileMimeType: 'application/pdf',
|
iconImageMimeType: 'application/pdf',
|
||||||
fileSizeBytes: 1024,
|
iconImageSizeBytes: 1024,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -131,10 +131,10 @@ class UpdateIconImageTest extends TestCase
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateIconImageRequest(
|
new UpdateIconImageRequest(
|
||||||
id: 1,
|
id: 1,
|
||||||
fileContents: 'big',
|
iconImageContents: 'big',
|
||||||
fileOriginalName: 'icon.png',
|
iconImageOriginalName: 'icon.png',
|
||||||
fileMimeType: 'image/png',
|
iconImageMimeType: 'image/png',
|
||||||
fileSizeBytes: 6 * 1024 * 1024,
|
iconImageSizeBytes: 6 * 1024 * 1024,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -167,8 +167,7 @@ class UpdateIconImageTest extends TestCase
|
||||||
description: 'Original description',
|
description: 'Original description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '',
|
richText: '',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
));
|
));
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Unit\Element\UseCases;
|
|
||||||
|
|
||||||
use App\Element\CreateElementDto;
|
|
||||||
use App\Element\Element;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
|
||||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfRequest;
|
|
||||||
use App\Exceptions\BadRequestException;
|
|
||||||
use App\Set\Set as DomainSet;
|
|
||||||
use Tests\Fakes\FakeElementRepository;
|
|
||||||
use Tests\Fakes\FakeFileUploader;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class UpdateLongPdfTest extends TestCase
|
|
||||||
{
|
|
||||||
private FakeElementRepository $elementRepository;
|
|
||||||
|
|
||||||
private FakeFileUploader $fileUploader;
|
|
||||||
|
|
||||||
private UpdateLongPdf $useCase;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
$this->elementRepository = new FakeElementRepository();
|
|
||||||
$this->fileUploader = new FakeFileUploader();
|
|
||||||
$this->useCase = new UpdateLongPdf(
|
|
||||||
$this->elementRepository,
|
|
||||||
$this->fileUploader,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUploadsLongPdfAndStoresPath(): void
|
|
||||||
{
|
|
||||||
$element = $this->createElement();
|
|
||||||
|
|
||||||
$updatedElement = $this->useCase->execute(
|
|
||||||
new UpdateLongPdfRequest(
|
|
||||||
id: $element->getId(),
|
|
||||||
fileContents: 'binary-pdf-bytes',
|
|
||||||
fileOriginalName: 'baderech-long.pdf',
|
|
||||||
fileMimeType: 'application/pdf',
|
|
||||||
fileSizeBytes: 1024,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertNull($updatedElement->getShortPdfPath());
|
|
||||||
$this->assertSame(
|
|
||||||
'element-pdfs/long/fake-baderech-long.pdf',
|
|
||||||
$updatedElement->getLongPdfPath(),
|
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
'element-pdfs/long',
|
|
||||||
$this->fileUploader->uploads[0]['folder'],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDisallowedMimeThrowsBadRequest(): void
|
|
||||||
{
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('pdf must be a pdf file');
|
|
||||||
|
|
||||||
$this->useCase->execute(
|
|
||||||
new UpdateLongPdfRequest(
|
|
||||||
id: 1,
|
|
||||||
fileContents: 'not-a-pdf',
|
|
||||||
fileOriginalName: 'icon.png',
|
|
||||||
fileMimeType: 'image/png',
|
|
||||||
fileSizeBytes: 1024,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function createElement(): Element
|
|
||||||
{
|
|
||||||
$set = new DomainSet(
|
|
||||||
id: 1,
|
|
||||||
name: 'Baderech',
|
|
||||||
description: 'Baderech description',
|
|
||||||
iconImageUrl: '/assets/baderech-icon.png',
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->elementRepository->create(new CreateElementDto(
|
|
||||||
set: $set,
|
|
||||||
title: 'Original title',
|
|
||||||
description: 'Original description',
|
|
||||||
iconImageUrl: null,
|
|
||||||
richText: '',
|
|
||||||
shortPdfPath: null,
|
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
|
||||||
parentElement: null,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -4,8 +4,8 @@ namespace Tests\Unit\Element\UseCases;
|
||||||
|
|
||||||
use App\Element\CreateElementDto;
|
use App\Element\CreateElementDto;
|
||||||
use App\Element\Element;
|
use App\Element\Element;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfRequest;
|
use App\Element\UseCases\UpdateElement\UpdatePdfRequest;
|
||||||
use App\Exceptions\BadRequestException;
|
use App\Exceptions\BadRequestException;
|
||||||
use App\Exceptions\NotFoundException;
|
use App\Exceptions\NotFoundException;
|
||||||
use App\Set\Set as DomainSet;
|
use App\Set\Set as DomainSet;
|
||||||
|
|
@ -13,19 +13,19 @@ use Tests\Fakes\FakeElementRepository;
|
||||||
use Tests\Fakes\FakeFileUploader;
|
use Tests\Fakes\FakeFileUploader;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UpdateShortPdfTest extends TestCase
|
class UpdatePdfTest extends TestCase
|
||||||
{
|
{
|
||||||
private FakeElementRepository $elementRepository;
|
private FakeElementRepository $elementRepository;
|
||||||
|
|
||||||
private FakeFileUploader $fileUploader;
|
private FakeFileUploader $fileUploader;
|
||||||
|
|
||||||
private UpdateShortPdf $useCase;
|
private UpdatePdf $useCase;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->elementRepository = new FakeElementRepository();
|
$this->elementRepository = new FakeElementRepository();
|
||||||
$this->fileUploader = new FakeFileUploader();
|
$this->fileUploader = new FakeFileUploader();
|
||||||
$this->useCase = new UpdateShortPdf(
|
$this->useCase = new UpdatePdf(
|
||||||
$this->elementRepository,
|
$this->elementRepository,
|
||||||
$this->fileUploader,
|
$this->fileUploader,
|
||||||
);
|
);
|
||||||
|
|
@ -33,46 +33,45 @@ class UpdateShortPdfTest extends TestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array{
|
* @return array{
|
||||||
* fileContents: string,
|
* pdfContents: string,
|
||||||
* fileOriginalName: string,
|
* pdfOriginalName: string,
|
||||||
* fileMimeType: string,
|
* pdfMimeType: string,
|
||||||
* fileSizeBytes: int
|
* pdfSizeBytes: int
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
private function pdfArgs(): array
|
private function pdfArgs(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'fileContents' => 'binary-pdf-bytes',
|
'pdfContents' => 'binary-pdf-bytes',
|
||||||
'fileOriginalName' => 'baderech.pdf',
|
'pdfOriginalName' => 'baderech.pdf',
|
||||||
'fileMimeType' => 'application/pdf',
|
'pdfMimeType' => 'application/pdf',
|
||||||
'fileSizeBytes' => 1024,
|
'pdfSizeBytes' => 1024,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUploadsShortPdfAndStoresPath(): void
|
public function testUploadsPdfAndStoresPath(): void
|
||||||
{
|
{
|
||||||
$element = $this->createElement();
|
$element = $this->createElement();
|
||||||
|
|
||||||
$updatedElement = $this->useCase->execute(
|
$updatedElement = $this->useCase->execute(
|
||||||
new UpdateShortPdfRequest(
|
new UpdatePdfRequest(
|
||||||
...$this->pdfArgs(),
|
...$this->pdfArgs(),
|
||||||
id: $element->getId(),
|
id: $element->getId(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/short/fake-baderech.pdf',
|
'element-pdfs/fake-baderech.pdf',
|
||||||
$updatedElement->getShortPdfPath(),
|
$updatedElement->getPdfPath(),
|
||||||
);
|
);
|
||||||
$this->assertNull($updatedElement->getLongPdfPath());
|
|
||||||
$storedElement = $this->elementRepository->find($element->getId());
|
$storedElement = $this->elementRepository->find($element->getId());
|
||||||
$this->assertNotNull($storedElement);
|
$this->assertNotNull($storedElement);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/short/fake-baderech.pdf',
|
'element-pdfs/fake-baderech.pdf',
|
||||||
$storedElement->getShortPdfPath(),
|
$storedElement->getPdfPath(),
|
||||||
);
|
);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'element-pdfs/short',
|
'element-pdfs',
|
||||||
$this->fileUploader->uploads[0]['folder'],
|
$this->fileUploader->uploads[0]['folder'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -83,7 +82,7 @@ class UpdateShortPdfTest extends TestCase
|
||||||
$this->expectExceptionMessage('id is required');
|
$this->expectExceptionMessage('id is required');
|
||||||
|
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateShortPdfRequest(
|
new UpdatePdfRequest(
|
||||||
...$this->pdfArgs(),
|
...$this->pdfArgs(),
|
||||||
id: null,
|
id: null,
|
||||||
)
|
)
|
||||||
|
|
@ -96,12 +95,12 @@ class UpdateShortPdfTest extends TestCase
|
||||||
$this->expectExceptionMessage('pdf is required');
|
$this->expectExceptionMessage('pdf is required');
|
||||||
|
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateShortPdfRequest(
|
new UpdatePdfRequest(
|
||||||
id: 1,
|
id: 1,
|
||||||
fileContents: null,
|
pdfContents: null,
|
||||||
fileOriginalName: null,
|
pdfOriginalName: null,
|
||||||
fileMimeType: null,
|
pdfMimeType: null,
|
||||||
fileSizeBytes: null,
|
pdfSizeBytes: null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -112,12 +111,12 @@ class UpdateShortPdfTest extends TestCase
|
||||||
$this->expectExceptionMessage('pdf must be a pdf file');
|
$this->expectExceptionMessage('pdf must be a pdf file');
|
||||||
|
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateShortPdfRequest(
|
new UpdatePdfRequest(
|
||||||
id: 1,
|
id: 1,
|
||||||
fileContents: 'not-a-pdf',
|
pdfContents: 'not-a-pdf',
|
||||||
fileOriginalName: 'icon.png',
|
pdfOriginalName: 'icon.png',
|
||||||
fileMimeType: 'image/png',
|
pdfMimeType: 'image/png',
|
||||||
fileSizeBytes: 1024,
|
pdfSizeBytes: 1024,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -128,12 +127,12 @@ class UpdateShortPdfTest extends TestCase
|
||||||
$this->expectExceptionMessage('pdf must be 10MB or smaller');
|
$this->expectExceptionMessage('pdf must be 10MB or smaller');
|
||||||
|
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateShortPdfRequest(
|
new UpdatePdfRequest(
|
||||||
id: 1,
|
id: 1,
|
||||||
fileContents: 'big',
|
pdfContents: 'big',
|
||||||
fileOriginalName: 'baderech.pdf',
|
pdfOriginalName: 'baderech.pdf',
|
||||||
fileMimeType: 'application/pdf',
|
pdfMimeType: 'application/pdf',
|
||||||
fileSizeBytes: 11 * 1024 * 1024,
|
pdfSizeBytes: 11 * 1024 * 1024,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +143,7 @@ class UpdateShortPdfTest extends TestCase
|
||||||
$this->expectExceptionMessage('Element not found');
|
$this->expectExceptionMessage('Element not found');
|
||||||
|
|
||||||
$this->useCase->execute(
|
$this->useCase->execute(
|
||||||
new UpdateShortPdfRequest(
|
new UpdatePdfRequest(
|
||||||
...$this->pdfArgs(),
|
...$this->pdfArgs(),
|
||||||
id: 999,
|
id: 999,
|
||||||
)
|
)
|
||||||
|
|
@ -166,8 +165,7 @@ class UpdateShortPdfTest extends TestCase
|
||||||
description: 'Original description',
|
description: 'Original description',
|
||||||
iconImageUrl: null,
|
iconImageUrl: null,
|
||||||
richText: '',
|
richText: '',
|
||||||
shortPdfPath: null,
|
pdfPath: null,
|
||||||
longPdfPath: null,
|
|
||||||
youtubeUrl: null,
|
youtubeUrl: null,
|
||||||
parentElement: null,
|
parentElement: null,
|
||||||
));
|
));
|
||||||
|
|
@ -126,45 +126,28 @@ describe('admin element editing', () => {
|
||||||
.and('have.attr', 'src')
|
.and('have.attr', 'src')
|
||||||
.and('include', '/storage/element-icons/')
|
.and('include', '/storage/element-icons/')
|
||||||
|
|
||||||
cy.get('[data-cy="admin-element-short-pdf-input"]').selectFile(
|
cy.get('[data-cy="admin-element-pdf-input"]').selectFile(
|
||||||
'public/assets/pdfs/baderech.pdf',
|
'public/assets/pdfs/baderech.pdf',
|
||||||
{ force: true },
|
{ force: true },
|
||||||
)
|
)
|
||||||
cy.wait('@updateElement')
|
cy.wait('@updateElement')
|
||||||
cy.get('[data-cy="admin-element-short-pdf-status"]')
|
cy.get('[data-cy="admin-element-pdf-status"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('contain.text', 'Short PDF updated')
|
.and('contain.text', 'PDF updated')
|
||||||
cy.get('[data-cy="admin-element-current-short-pdf"]')
|
cy.get('[data-cy="admin-element-current-pdf"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('have.attr', 'href')
|
.and('have.attr', 'href')
|
||||||
.and('include', '/storage/element-pdfs/short/')
|
.and('include', '/storage/element-pdfs/')
|
||||||
|
|
||||||
cy.get('[data-cy="admin-element-long-pdf-input"]').selectFile(
|
|
||||||
'public/assets/pdfs/baderech.pdf',
|
|
||||||
{ force: true },
|
|
||||||
)
|
|
||||||
cy.wait('@updateElement')
|
|
||||||
cy.get('[data-cy="admin-element-long-pdf-status"]')
|
|
||||||
.should('be.visible')
|
|
||||||
.and('contain.text', 'Long PDF updated')
|
|
||||||
cy.get('[data-cy="admin-element-current-long-pdf"]')
|
|
||||||
.should('be.visible')
|
|
||||||
.and('have.attr', 'href')
|
|
||||||
.and('include', '/storage/element-pdfs/long/')
|
|
||||||
|
|
||||||
cy.contains('header.site-header a', 'View Element').click()
|
cy.contains('header.site-header a', 'View Element').click()
|
||||||
cy.get('[data-cy="element-icon"]')
|
cy.get('[data-cy="element-icon"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('have.attr', 'src')
|
.and('have.attr', 'src')
|
||||||
.and('include', '/storage/element-icons/')
|
.and('include', '/storage/element-icons/')
|
||||||
cy.get('[data-cy="element-short-pdf-link"]')
|
cy.get('[data-cy="element-pdf-link"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('have.attr', 'href')
|
.and('have.attr', 'href')
|
||||||
.and('include', '/storage/element-pdfs/short/')
|
.and('include', '/storage/element-pdfs/')
|
||||||
cy.get('[data-cy="element-long-pdf-link"]')
|
|
||||||
.should('be.visible')
|
|
||||||
.and('have.attr', 'href')
|
|
||||||
.and('include', '/storage/element-pdfs/long/')
|
|
||||||
|
|
||||||
cy.resetDb()
|
cy.resetDb()
|
||||||
})
|
})
|
||||||
|
|
@ -180,12 +163,7 @@ describe('admin element editing', () => {
|
||||||
{ force: true },
|
{ force: true },
|
||||||
)
|
)
|
||||||
cy.wait('@updateElement')
|
cy.wait('@updateElement')
|
||||||
cy.get('[data-cy="admin-element-short-pdf-input"]').selectFile(
|
cy.get('[data-cy="admin-element-pdf-input"]').selectFile(
|
||||||
'public/assets/pdfs/baderech.pdf',
|
|
||||||
{ force: true },
|
|
||||||
)
|
|
||||||
cy.wait('@updateElement')
|
|
||||||
cy.get('[data-cy="admin-element-long-pdf-input"]').selectFile(
|
|
||||||
'public/assets/pdfs/baderech.pdf',
|
'public/assets/pdfs/baderech.pdf',
|
||||||
{ force: true },
|
{ force: true },
|
||||||
)
|
)
|
||||||
|
|
@ -199,26 +177,17 @@ describe('admin element editing', () => {
|
||||||
cy.get('[data-cy="admin-element-current-icon"]').should('not.exist')
|
cy.get('[data-cy="admin-element-current-icon"]').should('not.exist')
|
||||||
cy.contains('No icon image').should('be.visible')
|
cy.contains('No icon image').should('be.visible')
|
||||||
|
|
||||||
cy.contains('button', 'Remove short PDF').click()
|
cy.contains('button', 'Remove PDF').click()
|
||||||
cy.wait('@updateElement')
|
cy.wait('@updateElement')
|
||||||
cy.get('[data-cy="admin-element-short-pdf-status"]')
|
cy.get('[data-cy="admin-element-pdf-status"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('contain.text', 'Short PDF removed')
|
.and('contain.text', 'PDF removed')
|
||||||
cy.get('[data-cy="admin-element-current-short-pdf"]').should('not.exist')
|
cy.get('[data-cy="admin-element-current-pdf"]').should('not.exist')
|
||||||
cy.contains('No short PDF').should('be.visible')
|
cy.contains('No PDF').should('be.visible')
|
||||||
|
|
||||||
cy.contains('button', 'Remove long PDF').click()
|
|
||||||
cy.wait('@updateElement')
|
|
||||||
cy.get('[data-cy="admin-element-long-pdf-status"]')
|
|
||||||
.should('be.visible')
|
|
||||||
.and('contain.text', 'Long PDF removed')
|
|
||||||
cy.get('[data-cy="admin-element-current-long-pdf"]').should('not.exist')
|
|
||||||
cy.contains('No long PDF').should('be.visible')
|
|
||||||
|
|
||||||
cy.contains('header.site-header a', 'View Element').click()
|
cy.contains('header.site-header a', 'View Element').click()
|
||||||
cy.get('[data-cy="element-icon"]').should('not.exist')
|
cy.get('[data-cy="element-icon"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-short-pdf-link"]').should('not.exist')
|
cy.get('[data-cy="element-pdf-link"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-long-pdf-link"]').should('not.exist')
|
|
||||||
|
|
||||||
cy.resetDb()
|
cy.resetDb()
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,7 @@ describe('media page sets', () => {
|
||||||
cy.get('[data-cy="element-rich-text"]').should('not.exist')
|
cy.get('[data-cy="element-rich-text"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-youtube-embed"]')
|
cy.get('[data-cy="element-youtube-embed"]')
|
||||||
.should('not.exist')
|
.should('not.exist')
|
||||||
cy.get('[data-cy="element-short-pdf-link"]').should('not.exist')
|
cy.get('[data-cy="element-pdf-link"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-long-pdf-link"]').should('not.exist')
|
|
||||||
cy.get('[data-cy="child-element-list"]').should('be.visible')
|
cy.get('[data-cy="child-element-list"]').should('be.visible')
|
||||||
cy.get('[data-cy="child-element-list"]')
|
cy.get('[data-cy="child-element-list"]')
|
||||||
.should(
|
.should(
|
||||||
|
|
@ -117,14 +116,13 @@ describe('media page sets', () => {
|
||||||
)
|
)
|
||||||
.should('have.css', 'text-align', 'center')
|
.should('have.css', 'text-align', 'center')
|
||||||
cy.get('[data-cy="element-youtube-embed"]').should('not.exist')
|
cy.get('[data-cy="element-youtube-embed"]').should('not.exist')
|
||||||
cy.contains('[data-cy="element-short-pdf-link"]', 'View Short PDF')
|
cy.contains('[data-cy="element-pdf-link"]', 'View PDF')
|
||||||
.as('shortPdfLink')
|
.as('pdfLink')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
.and('have.attr', 'target', '_blank')
|
.and('have.attr', 'target', '_blank')
|
||||||
cy.get('@shortPdfLink')
|
cy.get('@pdfLink')
|
||||||
.and('have.attr', 'href')
|
.and('have.attr', 'href')
|
||||||
.and('include', '/storage/element-pdfs/short/baderech.pdf')
|
.and('include', '/storage/element-pdfs/baderech.pdf')
|
||||||
cy.get('[data-cy="element-long-pdf-link"]').should('not.exist')
|
|
||||||
cy.contains('[data-cy="child-element-link"]', introductionAudioTitle)
|
cy.contains('[data-cy="child-element-link"]', introductionAudioTitle)
|
||||||
.as('introductionAudioLink')
|
.as('introductionAudioLink')
|
||||||
.should('have.attr', 'href', '/element/8')
|
.should('have.attr', 'href', '/element/8')
|
||||||
|
|
@ -134,8 +132,7 @@ describe('media page sets', () => {
|
||||||
cy.contains('h1', introductionAudioTitle).should('be.visible')
|
cy.contains('h1', introductionAudioTitle).should('be.visible')
|
||||||
cy.get('[data-cy="element-icon"]').should('not.exist')
|
cy.get('[data-cy="element-icon"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-rich-text"]').should('not.exist')
|
cy.get('[data-cy="element-rich-text"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-short-pdf-link"]').should('not.exist')
|
cy.get('[data-cy="element-pdf-link"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-long-pdf-link"]').should('not.exist')
|
|
||||||
cy.get('[data-cy="child-element-list"]').should('not.exist')
|
cy.get('[data-cy="child-element-list"]').should('not.exist')
|
||||||
cy.get('[data-cy="element-youtube-embed"]')
|
cy.get('[data-cy="element-youtube-embed"]')
|
||||||
.should('be.visible')
|
.should('be.visible')
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { ref, type Ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
export interface ChildElement {
|
export interface ChildElement {
|
||||||
|
|
@ -10,13 +10,10 @@ export interface ChildElement {
|
||||||
export interface Element extends ChildElement {
|
export interface Element extends ChildElement {
|
||||||
iconImageUrl: string | null
|
iconImageUrl: string | null
|
||||||
richText: string
|
richText: string
|
||||||
shortPdfPath: string | null
|
pdfPath: string | null
|
||||||
longPdfPath: string | null
|
|
||||||
youtubeUrl: string | null
|
youtubeUrl: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type ElementFileType = 'iconImage' | 'shortPdf' | 'longPdf'
|
|
||||||
|
|
||||||
interface ElementResponse {
|
interface ElementResponse {
|
||||||
element: Element
|
element: Element
|
||||||
childElements: ChildElement[]
|
childElements: ChildElement[]
|
||||||
|
|
@ -38,8 +35,7 @@ interface ElementPatchInput {
|
||||||
description?: string
|
description?: string
|
||||||
iconImageUrl?: string
|
iconImageUrl?: string
|
||||||
richText?: string
|
richText?: string
|
||||||
shortPdfPath?: string
|
pdfPath?: string
|
||||||
longPdfPath?: string
|
|
||||||
youtubeUrl?: string
|
youtubeUrl?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,8 +53,7 @@ export const useElementsStore = defineStore('elements', () => {
|
||||||
const error = ref<string | null>(null)
|
const error = ref<string | null>(null)
|
||||||
const isSaving = ref(false)
|
const isSaving = ref(false)
|
||||||
const isUploadingIconImage = ref(false)
|
const isUploadingIconImage = ref(false)
|
||||||
const isUploadingShortPdf = ref(false)
|
const isUploadingPdf = ref(false)
|
||||||
const isUploadingLongPdf = ref(false)
|
|
||||||
const saveError = ref<string | null>(null)
|
const saveError = ref<string | null>(null)
|
||||||
|
|
||||||
async function fetchElement(elementId: string): Promise<void> {
|
async function fetchElement(elementId: string): Promise<void> {
|
||||||
|
|
@ -94,35 +89,16 @@ export const useElementsStore = defineStore('elements', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateElement(
|
async function updateElement(elementId: string, input: UpdateElementInput): Promise<boolean> {
|
||||||
elementId: string,
|
|
||||||
input: UpdateElementInput,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await saveElementPatch(elementId, input, 'Could not save element')
|
return await saveElementPatch(elementId, input, 'Could not save element')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clearElementIconImage(elementId: string): Promise<boolean> {
|
async function clearElementIconImage(elementId: string): Promise<boolean> {
|
||||||
return await saveElementPatch(
|
return await saveElementPatch(elementId, { iconImageUrl: '' }, 'Could not remove icon image')
|
||||||
elementId,
|
|
||||||
{ iconImageUrl: '' },
|
|
||||||
'Could not remove icon image',
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clearElementShortPdf(elementId: string): Promise<boolean> {
|
async function clearElementPdf(elementId: string): Promise<boolean> {
|
||||||
return await saveElementPatch(
|
return await saveElementPatch(elementId, { pdfPath: '' }, 'Could not remove PDF')
|
||||||
elementId,
|
|
||||||
{ shortPdfPath: '' },
|
|
||||||
'Could not remove short PDF',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function clearElementLongPdf(elementId: string): Promise<boolean> {
|
|
||||||
return await saveElementPatch(
|
|
||||||
elementId,
|
|
||||||
{ longPdfPath: '' },
|
|
||||||
'Could not remove long PDF',
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveElementPatch(
|
async function saveElementPatch(
|
||||||
|
|
@ -150,64 +126,14 @@ export const useElementsStore = defineStore('elements', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadElementIconImage(
|
async function uploadElementIconImage(elementId: string, file: File): Promise<boolean> {
|
||||||
elementId: string,
|
|
||||||
file: File,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await uploadElementFile(
|
|
||||||
elementId,
|
|
||||||
file,
|
|
||||||
'iconImage',
|
|
||||||
isUploadingIconImage,
|
|
||||||
'Could not upload icon image',
|
|
||||||
'Network error - could not upload icon image',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function uploadElementShortPdf(
|
|
||||||
elementId: string,
|
|
||||||
file: File,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await uploadElementFile(
|
|
||||||
elementId,
|
|
||||||
file,
|
|
||||||
'shortPdf',
|
|
||||||
isUploadingShortPdf,
|
|
||||||
'Could not upload short PDF',
|
|
||||||
'Network error - could not upload short PDF',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function uploadElementLongPdf(
|
|
||||||
elementId: string,
|
|
||||||
file: File,
|
|
||||||
): Promise<boolean> {
|
|
||||||
return await uploadElementFile(
|
|
||||||
elementId,
|
|
||||||
file,
|
|
||||||
'longPdf',
|
|
||||||
isUploadingLongPdf,
|
|
||||||
'Could not upload long PDF',
|
|
||||||
'Network error - could not upload long PDF',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function uploadElementFile(
|
|
||||||
elementId: string,
|
|
||||||
file: File,
|
|
||||||
fileType: ElementFileType,
|
|
||||||
isUploadingFile: Ref<boolean>,
|
|
||||||
failureMessage: string,
|
|
||||||
networkErrorMessage: string,
|
|
||||||
): Promise<boolean> {
|
|
||||||
saveError.value = null
|
saveError.value = null
|
||||||
isUploadingFile.value = true
|
isUploadingIconImage.value = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('elementId', elementId)
|
formData.append('elementId', elementId)
|
||||||
formData.append('fileType', fileType)
|
formData.append('iconImage', file)
|
||||||
formData.append('file', file)
|
|
||||||
const response = await fetch(ELEMENT_UPDATE_URL, {
|
const response = await fetch(ELEMENT_UPDATE_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { Accept: 'application/json' },
|
headers: { Accept: 'application/json' },
|
||||||
|
|
@ -215,12 +141,36 @@ export const useElementsStore = defineStore('elements', () => {
|
||||||
body: formData,
|
body: formData,
|
||||||
})
|
})
|
||||||
|
|
||||||
return await handleElementResponse(response, failureMessage)
|
return await handleElementResponse(response, 'Could not upload icon image')
|
||||||
} catch {
|
} catch {
|
||||||
saveError.value = networkErrorMessage
|
saveError.value = 'Network error - could not upload icon image'
|
||||||
return false
|
return false
|
||||||
} finally {
|
} finally {
|
||||||
isUploadingFile.value = false
|
isUploadingIconImage.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadElementPdf(elementId: string, file: File): Promise<boolean> {
|
||||||
|
saveError.value = null
|
||||||
|
isUploadingPdf.value = true
|
||||||
|
|
||||||
|
try {
|
||||||
|
const formData = new FormData()
|
||||||
|
formData.append('elementId', elementId)
|
||||||
|
formData.append('pdf', file)
|
||||||
|
const response = await fetch(ELEMENT_UPDATE_URL, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { Accept: 'application/json' },
|
||||||
|
credentials: 'include',
|
||||||
|
body: formData,
|
||||||
|
})
|
||||||
|
|
||||||
|
return await handleElementResponse(response, 'Could not upload PDF')
|
||||||
|
} catch {
|
||||||
|
saveError.value = 'Network error - could not upload PDF'
|
||||||
|
return false
|
||||||
|
} finally {
|
||||||
|
isUploadingPdf.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -253,10 +203,7 @@ export const useElementsStore = defineStore('elements', () => {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function errorMessage(
|
async function errorMessage(response: Response, fallbackMessage: string): Promise<string> {
|
||||||
response: Response,
|
|
||||||
fallbackMessage: string,
|
|
||||||
): Promise<string> {
|
|
||||||
try {
|
try {
|
||||||
const data: ErrorResponse = await response.json()
|
const data: ErrorResponse = await response.json()
|
||||||
return data.error ?? fallbackMessage
|
return data.error ?? fallbackMessage
|
||||||
|
|
@ -272,16 +219,13 @@ export const useElementsStore = defineStore('elements', () => {
|
||||||
error,
|
error,
|
||||||
isSaving,
|
isSaving,
|
||||||
isUploadingIconImage,
|
isUploadingIconImage,
|
||||||
isUploadingShortPdf,
|
isUploadingPdf,
|
||||||
isUploadingLongPdf,
|
|
||||||
saveError,
|
saveError,
|
||||||
fetchElement,
|
fetchElement,
|
||||||
updateElement,
|
updateElement,
|
||||||
uploadElementIconImage,
|
uploadElementIconImage,
|
||||||
uploadElementShortPdf,
|
uploadElementPdf,
|
||||||
uploadElementLongPdf,
|
|
||||||
clearElementIconImage,
|
clearElementIconImage,
|
||||||
clearElementShortPdf,
|
clearElementPdf,
|
||||||
clearElementLongPdf,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -14,23 +14,13 @@ interface ElementForm {
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const elementsStore = useElementsStore()
|
const elementsStore = useElementsStore()
|
||||||
const {
|
const { element, isLoading, error, isSaving, isUploadingIconImage, isUploadingPdf, saveError } =
|
||||||
element,
|
storeToRefs(elementsStore)
|
||||||
isLoading,
|
|
||||||
error,
|
|
||||||
isSaving,
|
|
||||||
isUploadingIconImage,
|
|
||||||
isUploadingShortPdf,
|
|
||||||
isUploadingLongPdf,
|
|
||||||
saveError,
|
|
||||||
} = storeToRefs(elementsStore)
|
|
||||||
const savedMessage = ref<string | null>(null)
|
const savedMessage = ref<string | null>(null)
|
||||||
const iconImageStatus = ref<string | null>(null)
|
const iconImageStatus = ref<string | null>(null)
|
||||||
const shortPdfStatus = ref<string | null>(null)
|
const pdfStatus = ref<string | null>(null)
|
||||||
const longPdfStatus = ref<string | null>(null)
|
|
||||||
const iconImageInput = ref<HTMLInputElement | null>(null)
|
const iconImageInput = ref<HTMLInputElement | null>(null)
|
||||||
const shortPdfInput = ref<HTMLInputElement | null>(null)
|
const pdfInput = ref<HTMLInputElement | null>(null)
|
||||||
const longPdfInput = ref<HTMLInputElement | null>(null)
|
|
||||||
|
|
||||||
const form = reactive<ElementForm>({
|
const form = reactive<ElementForm>({
|
||||||
title: '',
|
title: '',
|
||||||
|
|
@ -66,8 +56,7 @@ watch(
|
||||||
|
|
||||||
savedMessage.value = null
|
savedMessage.value = null
|
||||||
iconImageStatus.value = null
|
iconImageStatus.value = null
|
||||||
shortPdfStatus.value = null
|
pdfStatus.value = null
|
||||||
longPdfStatus.value = null
|
|
||||||
void elementsStore.fetchElement(currentElementId)
|
void elementsStore.fetchElement(currentElementId)
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
|
|
@ -106,12 +95,8 @@ function chooseIconImage(): void {
|
||||||
iconImageInput.value?.click()
|
iconImageInput.value?.click()
|
||||||
}
|
}
|
||||||
|
|
||||||
function chooseShortPdf(): void {
|
function choosePdf(): void {
|
||||||
shortPdfInput.value?.click()
|
pdfInput.value?.click()
|
||||||
}
|
|
||||||
|
|
||||||
function chooseLongPdf(): void {
|
|
||||||
longPdfInput.value?.click()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleIconImageChange(changeEvent: Event): Promise<void> {
|
async function handleIconImageChange(changeEvent: Event): Promise<void> {
|
||||||
|
|
@ -122,10 +107,7 @@ async function handleIconImageChange(changeEvent: Event): Promise<void> {
|
||||||
|
|
||||||
savedMessage.value = null
|
savedMessage.value = null
|
||||||
iconImageStatus.value = null
|
iconImageStatus.value = null
|
||||||
const uploaded = await elementsStore.uploadElementIconImage(
|
const uploaded = await elementsStore.uploadElementIconImage(elementId.value, selectedFile)
|
||||||
elementId.value,
|
|
||||||
selectedFile,
|
|
||||||
)
|
|
||||||
resetInput(changeEvent)
|
resetInput(changeEvent)
|
||||||
|
|
||||||
if (uploaded) {
|
if (uploaded) {
|
||||||
|
|
@ -133,41 +115,19 @@ async function handleIconImageChange(changeEvent: Event): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleShortPdfChange(changeEvent: Event): Promise<void> {
|
async function handlePdfChange(changeEvent: Event): Promise<void> {
|
||||||
const selectedFile = selectedInputFile(changeEvent)
|
const selectedFile = selectedInputFile(changeEvent)
|
||||||
if (selectedFile === null || elementId.value === '') {
|
if (selectedFile === null || elementId.value === '') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
savedMessage.value = null
|
savedMessage.value = null
|
||||||
shortPdfStatus.value = null
|
pdfStatus.value = null
|
||||||
const uploaded = await elementsStore.uploadElementShortPdf(
|
const uploaded = await elementsStore.uploadElementPdf(elementId.value, selectedFile)
|
||||||
elementId.value,
|
|
||||||
selectedFile,
|
|
||||||
)
|
|
||||||
resetInput(changeEvent)
|
resetInput(changeEvent)
|
||||||
|
|
||||||
if (uploaded) {
|
if (uploaded) {
|
||||||
shortPdfStatus.value = 'Short PDF updated'
|
pdfStatus.value = 'PDF updated'
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleLongPdfChange(changeEvent: Event): Promise<void> {
|
|
||||||
const selectedFile = selectedInputFile(changeEvent)
|
|
||||||
if (selectedFile === null || elementId.value === '') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
savedMessage.value = null
|
|
||||||
longPdfStatus.value = null
|
|
||||||
const uploaded = await elementsStore.uploadElementLongPdf(
|
|
||||||
elementId.value,
|
|
||||||
selectedFile,
|
|
||||||
)
|
|
||||||
resetInput(changeEvent)
|
|
||||||
|
|
||||||
if (uploaded) {
|
|
||||||
longPdfStatus.value = 'Long PDF updated'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,29 +144,16 @@ async function handleRemoveIconImage(): Promise<void> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleRemoveShortPdf(): Promise<void> {
|
async function handleRemovePdf(): Promise<void> {
|
||||||
if (elementId.value === '') {
|
if (elementId.value === '') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
savedMessage.value = null
|
savedMessage.value = null
|
||||||
shortPdfStatus.value = null
|
pdfStatus.value = null
|
||||||
const removed = await elementsStore.clearElementShortPdf(elementId.value)
|
const removed = await elementsStore.clearElementPdf(elementId.value)
|
||||||
if (removed) {
|
if (removed) {
|
||||||
shortPdfStatus.value = 'Short PDF removed'
|
pdfStatus.value = 'PDF removed'
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleRemoveLongPdf(): Promise<void> {
|
|
||||||
if (elementId.value === '') {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
savedMessage.value = null
|
|
||||||
longPdfStatus.value = null
|
|
||||||
const removed = await elementsStore.clearElementLongPdf(elementId.value)
|
|
||||||
if (removed) {
|
|
||||||
longPdfStatus.value = 'Long PDF removed'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,9 +186,7 @@ function resetInput(changeEvent: Event): void {
|
||||||
<h1 class="admin-element-page__heading">Edit Element</h1>
|
<h1 class="admin-element-page__heading">Edit Element</h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<p v-if="isLoading" class="admin-element-page__status">
|
<p v-if="isLoading" class="admin-element-page__status">Loading element...</p>
|
||||||
Loading element...
|
|
||||||
</p>
|
|
||||||
<p
|
<p
|
||||||
v-else-if="error"
|
v-else-if="error"
|
||||||
class="admin-element-page__status admin-element-page__status--error"
|
class="admin-element-page__status admin-element-page__status--error"
|
||||||
|
|
@ -249,11 +194,7 @@ function resetInput(changeEvent: Event): void {
|
||||||
>
|
>
|
||||||
{{ error }}
|
{{ error }}
|
||||||
</p>
|
</p>
|
||||||
<form
|
<form v-else-if="element" class="admin-element-page__form" @submit.prevent="handleSubmit">
|
||||||
v-else-if="element"
|
|
||||||
class="admin-element-page__form"
|
|
||||||
@submit.prevent="handleSubmit"
|
|
||||||
>
|
|
||||||
<label class="admin-element-page__field">
|
<label class="admin-element-page__field">
|
||||||
<span class="admin-element-page__label">Title</span>
|
<span class="admin-element-page__label">Title</span>
|
||||||
<input
|
<input
|
||||||
|
|
@ -314,10 +255,7 @@ function resetInput(changeEvent: Event): void {
|
||||||
</div>
|
</div>
|
||||||
<p
|
<p
|
||||||
v-if="iconImageStatus !== null"
|
v-if="iconImageStatus !== null"
|
||||||
:class="[
|
class="admin-element-page__status admin-element-page__status--inline"
|
||||||
'admin-element-page__status',
|
|
||||||
'admin-element-page__status--inline',
|
|
||||||
]"
|
|
||||||
data-cy="admin-element-icon-image-status"
|
data-cy="admin-element-icon-image-status"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
>
|
>
|
||||||
|
|
@ -336,110 +274,53 @@ function resetInput(changeEvent: Event): void {
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<section class="admin-element-page__media-field">
|
<section class="admin-element-page__media-field">
|
||||||
<span class="admin-element-page__label">Short PDF</span>
|
<span class="admin-element-page__label">PDF</span>
|
||||||
<a
|
<a
|
||||||
v-if="element.shortPdfPath !== null"
|
v-if="element.pdfPath !== null"
|
||||||
:href="element.shortPdfPath"
|
:href="element.pdfPath"
|
||||||
class="admin-element-page__pdf-link"
|
class="admin-element-page__pdf-link"
|
||||||
data-cy="admin-element-current-short-pdf"
|
data-cy="admin-element-current-pdf"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
View current short PDF
|
View current PDF
|
||||||
</a>
|
</a>
|
||||||
<p v-else class="admin-element-page__empty-media">No short PDF</p>
|
<p v-else class="admin-element-page__empty-media">No PDF</p>
|
||||||
<div class="admin-element-page__media-actions">
|
<div class="admin-element-page__media-actions">
|
||||||
<input
|
<input
|
||||||
ref="shortPdfInput"
|
ref="pdfInput"
|
||||||
class="admin-element-page__file-input"
|
class="admin-element-page__file-input"
|
||||||
data-cy="admin-element-short-pdf-input"
|
data-cy="admin-element-pdf-input"
|
||||||
type="file"
|
type="file"
|
||||||
accept="application/pdf"
|
accept="application/pdf"
|
||||||
:disabled="isUploadingShortPdf"
|
:disabled="isUploadingPdf"
|
||||||
@change="handleShortPdfChange"
|
@change="handlePdfChange"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="admin-element-page__secondary-button"
|
class="admin-element-page__secondary-button"
|
||||||
type="button"
|
type="button"
|
||||||
:disabled="isUploadingShortPdf"
|
:disabled="isUploadingPdf"
|
||||||
@click="chooseShortPdf"
|
@click="choosePdf"
|
||||||
>
|
>
|
||||||
{{ isUploadingShortPdf ? 'Uploading...' : 'Choose short PDF' }}
|
{{ isUploadingPdf ? 'Uploading...' : 'Choose PDF' }}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="element.shortPdfPath !== null"
|
v-if="element.pdfPath !== null"
|
||||||
class="admin-element-page__secondary-button"
|
class="admin-element-page__secondary-button"
|
||||||
type="button"
|
type="button"
|
||||||
:disabled="isSaving || isUploadingShortPdf"
|
:disabled="isSaving || isUploadingPdf"
|
||||||
@click="handleRemoveShortPdf"
|
@click="handleRemovePdf"
|
||||||
>
|
>
|
||||||
Remove short PDF
|
Remove PDF
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<p
|
<p
|
||||||
v-if="shortPdfStatus !== null"
|
v-if="pdfStatus !== null"
|
||||||
:class="[
|
class="admin-element-page__status admin-element-page__status--inline"
|
||||||
'admin-element-page__status',
|
data-cy="admin-element-pdf-status"
|
||||||
'admin-element-page__status--inline',
|
|
||||||
]"
|
|
||||||
data-cy="admin-element-short-pdf-status"
|
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
>
|
>
|
||||||
{{ shortPdfStatus }}
|
{{ pdfStatus }}
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="admin-element-page__media-field">
|
|
||||||
<span class="admin-element-page__label">Long PDF</span>
|
|
||||||
<a
|
|
||||||
v-if="element.longPdfPath !== null"
|
|
||||||
:href="element.longPdfPath"
|
|
||||||
class="admin-element-page__pdf-link"
|
|
||||||
data-cy="admin-element-current-long-pdf"
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
View current long PDF
|
|
||||||
</a>
|
|
||||||
<p v-else class="admin-element-page__empty-media">No long PDF</p>
|
|
||||||
<div class="admin-element-page__media-actions">
|
|
||||||
<input
|
|
||||||
ref="longPdfInput"
|
|
||||||
class="admin-element-page__file-input"
|
|
||||||
data-cy="admin-element-long-pdf-input"
|
|
||||||
type="file"
|
|
||||||
accept="application/pdf"
|
|
||||||
:disabled="isUploadingLongPdf"
|
|
||||||
@change="handleLongPdfChange"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="admin-element-page__secondary-button"
|
|
||||||
type="button"
|
|
||||||
:disabled="isUploadingLongPdf"
|
|
||||||
@click="chooseLongPdf"
|
|
||||||
>
|
|
||||||
{{ isUploadingLongPdf ? 'Uploading...' : 'Choose long PDF' }}
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
v-if="element.longPdfPath !== null"
|
|
||||||
class="admin-element-page__secondary-button"
|
|
||||||
type="button"
|
|
||||||
:disabled="isSaving || isUploadingLongPdf"
|
|
||||||
@click="handleRemoveLongPdf"
|
|
||||||
>
|
|
||||||
Remove long PDF
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<p
|
|
||||||
v-if="longPdfStatus !== null"
|
|
||||||
:class="[
|
|
||||||
'admin-element-page__status',
|
|
||||||
'admin-element-page__status--inline',
|
|
||||||
]"
|
|
||||||
data-cy="admin-element-long-pdf-status"
|
|
||||||
aria-live="polite"
|
|
||||||
>
|
|
||||||
{{ longPdfStatus }}
|
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
@ -464,10 +345,7 @@ function resetInput(changeEvent: Event): void {
|
||||||
</button>
|
</button>
|
||||||
<p
|
<p
|
||||||
v-if="statusMessage !== null"
|
v-if="statusMessage !== null"
|
||||||
:class="[
|
:class="['admin-element-page__status', 'admin-element-page__status--inline']"
|
||||||
'admin-element-page__status',
|
|
||||||
'admin-element-page__status--inline',
|
|
||||||
]"
|
|
||||||
data-cy="admin-element-status"
|
data-cy="admin-element-status"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -242,29 +242,15 @@ function isShortYoutubeHost(hostname: string): boolean {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div v-if="element.pdfPath !== null" class="element-page__actions">
|
||||||
v-if="element.shortPdfPath !== null || element.longPdfPath !== null"
|
|
||||||
class="element-page__actions"
|
|
||||||
>
|
|
||||||
<a
|
<a
|
||||||
v-if="element.shortPdfPath !== null"
|
:href="element.pdfPath"
|
||||||
:href="element.shortPdfPath"
|
|
||||||
class="element-page__pdf-link"
|
class="element-page__pdf-link"
|
||||||
data-cy="element-short-pdf-link"
|
data-cy="element-pdf-link"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noreferrer"
|
rel="noreferrer"
|
||||||
>
|
>
|
||||||
View Short PDF
|
View PDF
|
||||||
</a>
|
|
||||||
<a
|
|
||||||
v-if="element.longPdfPath !== null"
|
|
||||||
:href="element.longPdfPath"
|
|
||||||
class="element-page__pdf-link"
|
|
||||||
data-cy="element-long-pdf-link"
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
View Long PDF
|
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -374,9 +360,7 @@ function isShortYoutubeHost(hostname: string): boolean {
|
||||||
|
|
||||||
.element-page__actions {
|
.element-page__actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 0.75rem;
|
|
||||||
margin-top: 1.75rem;
|
margin-top: 1.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue