Skip to content

Commit

Permalink
TASK: Adjust tests to collection removal protection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Oct 28, 2024
1 parent ad23803 commit 6ea5720
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Resources/Private/JavaScript/dev-server/src/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const assetCollections: AssetCollection[] = range(3).map((index) => ({
: null,
// TODO: Recalculate assetCount of assetCollections after generation of assets
assetCount: 0,
canDelete: true,
}));

const getUsageDetailsForAsset = (assetId: string): UsageDetailsGroup[] => {
Expand Down Expand Up @@ -154,6 +155,17 @@ const assets = range(150).map((index) => {
const isCloud = index > 120;
const filename = getExampleFilename(index);

const collectionsForAsset = range(index % 2).map(
(i) => assetCollections[(i * 2 + index) % assetCollections.length]
);

collectionsForAsset.forEach((collection) => {
collection.assetCount++;
collection.canDelete = false;
});

const tagsForAsset = range(index % 3).map((i) => tags[(i * 3 + index) % tags.length]);

return {
__typename: 'Asset',
id: index.toString(),
Expand All @@ -163,8 +175,8 @@ const assets = range(150).map((index) => {
label: `Example asset ${index + 1}`,
caption: `The caption for example asset ${index + 1}`,
filename: 'example1.jpg',
tags: range(index % 3).map((i) => tags[(i * 3 + index) % tags.length]),
collections: range(index % 2).map((i) => assetCollections[(i * 2 + index) % assetCollections.length]),
tags: tagsForAsset,
collections: collectionsForAsset,
copyrightNotice: 'The Neos team',
lastModified: new Date(`2020-06-16 15:${Math.floor((150 - index) / 60)}:${(150 - index) % 60}`),
iptcProperties: index % 5 === 0 ? getIptcProperties(index) : [],
Expand Down
2 changes: 2 additions & 0 deletions Resources/Private/JavaScript/dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
deleteAssetCollection: ($_, { id }: { id: string }): boolean => {
const assetCollection = assetCollections.find((assetCollection) => assetCollection.id === id);
if (!assetCollection) return false;
if (assetCollection.assetCount > 0) return false;
assetCollections = assetCollections.filter((assetCollection) => assetCollection.id !== id);
return true;
},
Expand All @@ -236,6 +237,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
: null,
tags: [],
assetCount: 0,
canDelete: true,
};
assetCollections.push(newCollection);
return newCollection;
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ parameters:
- Classes
ignoreErrors:
- '#Call to an undefined method [a-zA-Z0-9\\_]+Repository::findBy[a-zA-Z]+\(\)#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+Repository::findOneBy[a-zA-Z]+\(\)#'

0 comments on commit 6ea5720

Please sign in to comment.