206 lines
4.9 KiB
TypeScript
Raw Normal View History

import { rest } from 'msw';
chore: migrate media-library pages to Typescript (#21896) * chore: migrate to TS AudoPreview component * chore: migrate to TS PaginationContext component * chore: migrate to TS Pagination component * chore: migrate to TS PaginationFolder components * chore: migrate to TS PaginationFooter index component * chore: migrate to TS isSelectable util * chore: migrate to TS PageSize component * chore: migrate to TS DialogFooter component * chore: migrate to TS Draggable component * chore: migrate to TS ContextInfo component * chore: migrate to TS ContextInfo test and index component * chore: migrate to TS PreviewBox components file * chore: migrate to TS DialogHeader component * chore: migrate to TS RemoveFolderDialog * chore: migrate to TS EmptyAssetGrid * chore: migrate to TS EmptyAssets index file * chore: migrate to TS AssetCardBase * chore: migrate to TS AudioAssetCard component * chore: migrate to TS DocAssetCard component * chore: migrate to TS ImageAssetCard component * chore: migrate to TS AssetCard unit tests * chore: migrate to TS SearchAsset component * chore: migrate to TS UploadProgress component * chore: migrate to TS FromComputerForm component * chore: migrate to TS FromUrlForm component * chore: migrate to TS AddAssetStep component * chore: migrate to TS VideoPreview component * chore: migrate to TS VideoAssetCard component * chore: migrate to TS UploadingAssetCard component * chore: migrate to TS PreviewCell component * chore: migrate to TS CellContent component * chore: migrate to TS TableRows component * chore: migrate to TS TableList component * chore: migrate to TS SortPicker component * chore: migrate to TS Option component with utils * chore: migrate to TS EmptyStateAsset and CarouselAsset * chore: migrate to TS CopyLinkButton component * chore: migrate to TS CarouselAssetActions component * chore: migrate to TS FolderGridList component * chore: migrate to TS FolderCardContext * chore: migrate to TS FolderCard component * chore: migrate to TS FolderCardBody component * chore: migrate to TS FolderCardBodyAction component * chore: migrate to TS FolderCardCheckbox component * chore: migrate to TS FolderCard unit test * chore: migrate to TS getFilterList * chore: migrate to TS FilterValueInput component * chore: migrate to TS FilterTag * chore: migrate to TS FilterList * chore: migrate to TS EditFolderModalHeader component * chore: migrate to TS AssetPreview component * chore: migrate to TS CroppingActions component * chore: migrate to TS RemoveAssetDialog component * chore: migrate to TS ReplaceMediaButton component * chore: migrate to TS AssetCard component * chore: migrate to TS AssetGridList * chore: migrate to TS PendingAssetStep component * chore: migrate to TS SelectedStep component * chore: migrate to TS PreviewBox component * chore: migrate to TS SelectTree * chore: migrate to TS SelectTree unit test * chore: migrate to TS BulkMoveDialog * chore: migrate to TS EditFolderContent component * chore: migrate to TS FilterValueInput * chore: migrato to TS CrumbSimpleMenuAsync * chore: migrate to TS Breadcrumbs * chore: migrate to TS Filters component * chore: migrate to TS EditAssetDialog * chore: migrate to TS CarouselAssets * chore: migrate to TS UploadAssetDialog and BrowseStep * chore: migrate to TS BrowseStep test * chore: migrate to TS AssetDialog component * chore: migrate to TS MediaLibraryDialog component * chore: migrate to TS MediaLibraryDialog component * chore: remove a useless type guard * chore: fix small stuff * chore: fix BulkMoveDialog unit test * chore: fix some types * chore: fix prettier problems * chore: migrate to TS EmptyOrNoPermissions component * chore: migrate to TS BulkDeleteButton component * chore: migrate to TS BulkMoveButton component * chore: fix prettier errors * chore: migrate to TS reducer settings page * chore: migrate to TS init in the settings page * chore: fix review's comments * chore: migrate to TS SettingsPage * chore: migrate to TS init ConfigureTheView * chore: migrate to TS the ConfigureTheView redux definition * chore: migrate to TS ConfigureTheView Settings page * chore: fix review comments * chore: migrate to TS ConfigureTheView page * chore: migrate to TS BulkDeleteButton and BulkMoveButton * chore: migrate to TS EmptyOrNoPermissions * chore: migrate to TS Header in MediaLibrary page * chore: migrate to TS Header * chore: migrate to TS BulkActions in App page * chore: migrate to TS BulkActions * chore: migrate to TS Filters component * chore: migrate to TS MediaLibrary page * chore: migrate to TS App page * chore: migrate to TS index entry point * chore: replace newConstants with constants and fix some configuration files * chore: fix lint errors * chore: fix build errors * chore: fix review comments * chore: remove tag from Header component * chore: fix remaining eslint error, add todo to the ex index files * chore: fix breadcrumbs error
2024-11-08 17:22:43 +01:00
import * as qs from 'qs';
// Define the expected structure of your query parameters
interface CustomQuery extends qs.ParsedQs {
filters?: {
$and?: Array<{ parent: { id: string } }>;
};
}
const handlers = [
rest.get('/upload/configuration', async (req, res, ctx) => {
return res(
ctx.json({
data: {
/**
* we send the pageSize slightly different to defaults because
* in tests we can track that the async functions have finished.
*/
pageSize: 20,
sort: 'updatedAt:DESC',
},
})
);
}),
rest.put('/upload/configuration', async (req, res, ctx) => {
return res(ctx.status(200));
}),
rest.get('/upload/folders/:id', async (req, res, ctx) => {
return res(
ctx.json({
data: {
id: 1,
name: 'test',
pathId: 1,
path: '/1',
createdAt: '2023-06-26T12:48:54.054Z',
updatedAt: '2023-06-26T12:48:54.054Z',
parent: null,
children: {
count: 2,
},
files: {
count: 0,
},
},
})
);
}),
rest.delete('/upload/:type/:id', async (req, res, ctx) => {
return res(
ctx.json({
id: 1,
})
);
}),
rest.get('/upload/folders', async (req, res, ctx) => {
const query: CustomQuery = qs.parse(req.url.search.slice(1));
if (query._q) {
return res(
ctx.json({
data: [
{
createdAt: '2023-06-26T12:48:54.054Z',
id: 1,
name: query._q,
pathId: 1,
path: '/1',
updatedAt: '2023-06-26T12:48:54.054Z',
children: {
count: 2,
},
files: {
count: 0,
},
},
],
})
);
}
if (Array.isArray(query.filters?.$and)) {
const [{ parent }] = query.filters.$and;
if (parent.id === '1') {
return res(
ctx.json({
data: [
{
createdAt: '2023-06-26T12:49:31.354Z',
id: 3,
name: '2022',
pathId: 3,
path: '/1/3',
updatedAt: '2023-06-26T12:49:31.354Z',
children: {
count: 0,
},
files: {
count: 3,
},
},
{
createdAt: '2023-06-26T12:49:08.466Z',
id: 2,
name: '2023',
pathId: 2,
path: '/1/2',
updatedAt: '2023-06-26T12:49:08.466Z',
children: {
count: 0,
},
files: {
count: 3,
},
},
],
})
);
}
}
return res(
ctx.json({
data: [
{
createdAt: '2023-06-26T12:48:54.054Z',
id: 1,
name: 'test',
pathId: 1,
path: '/1',
updatedAt: '2023-06-26T12:48:54.054Z',
children: {
count: 2,
},
files: {
count: 0,
},
},
],
})
);
}),
rest.get('*/some/file', async (req, res, ctx) => {
const file = new File([new Blob(['1'.repeat(1024 * 1024 + 1)])], 'image.png', {
type: 'image/png',
});
const buffer = await new Response(file).arrayBuffer();
return res(ctx.set('Content-Type', 'image/png'), ctx.body(buffer));
}),
rest.get('/upload/settings', async (req, res, ctx) => {
return res(
ctx.json({
data: {
sizeOptimization: true,
responsiveDimensions: true,
autoOrientation: true,
},
})
);
}),
rest.get('/upload/folder-structure', (req, res, ctx) => {
return res(
ctx.json({
data: [
{
id: 1,
name: 'test',
children: [
{
id: 3,
name: '2022',
children: [],
},
{
id: 2,
name: '2023',
children: [],
},
],
},
],
})
);
}),
rest.get('*/an-image.png', (req, res, ctx) =>
res(ctx.set('Content-Type', 'image/png'), ctx.body('Successful response'))
),
rest.get('*/a-pdf.pdf', (req, res, ctx) =>
res(ctx.set('Content-Type', 'application/pdf'), ctx.body('Successful response'))
),
rest.get('*/a-video.mp4', (req, res, ctx) =>
res(ctx.set('Content-Type', 'video/mp4'), ctx.body('Successful response'))
),
rest.get('*/not-working-like-cors.lutin', (req, res, ctx) => res(ctx.json({}))),
rest.get('*/some-where-not-existing.jpg', (req, res) => res.networkError('Failed to fetch')),
];
export { handlers };