chore: adds schema path to useFieldPath provider, more passing tests
This commit is contained in:
@@ -7,13 +7,17 @@ import removeFiles from '../helpers/removeFiles'
|
||||
import { Uploads1 } from './collections/Upload1'
|
||||
import Uploads2 from './collections/Upload2'
|
||||
import AdminThumbnailCol from './collections/admin-thumbnail'
|
||||
import { audioSlug, enlargeSlug, mediaSlug, reduceSlug, relationSlug } from './shared'
|
||||
import {
|
||||
audioSlug,
|
||||
enlargeSlug,
|
||||
mediaSlug,
|
||||
reduceSlug,
|
||||
relationSlug,
|
||||
unstoredMediaSlug,
|
||||
} from './shared'
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
serverURL: undefined,
|
||||
paths: {
|
||||
configDir: __dirname,
|
||||
},
|
||||
collections: [
|
||||
{
|
||||
slug: relationSlug,
|
||||
@@ -44,7 +48,7 @@ export default buildConfigWithDefaults({
|
||||
slug: 'gif-resize',
|
||||
upload: {
|
||||
staticURL: '/media-gif',
|
||||
staticDir: './media-gif',
|
||||
staticDir: path.resolve(__dirname, './media-gif'),
|
||||
mimeTypes: ['image/gif'],
|
||||
resizeOptions: {
|
||||
position: 'center',
|
||||
@@ -75,7 +79,7 @@ export default buildConfigWithDefaults({
|
||||
slug: 'no-image-sizes',
|
||||
upload: {
|
||||
staticURL: '/no-image-sizes',
|
||||
staticDir: './no-image-sizes',
|
||||
staticDir: path.resolve(__dirname, './no-image-sizes'),
|
||||
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
|
||||
resizeOptions: {
|
||||
position: 'center',
|
||||
@@ -89,7 +93,7 @@ export default buildConfigWithDefaults({
|
||||
slug: 'object-fit',
|
||||
upload: {
|
||||
staticURL: '/object-fit',
|
||||
staticDir: './object-fit',
|
||||
staticDir: path.resolve(__dirname, './object-fit'),
|
||||
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
|
||||
imageSizes: [
|
||||
{
|
||||
@@ -125,7 +129,7 @@ export default buildConfigWithDefaults({
|
||||
upload: {
|
||||
focalPoint: false,
|
||||
staticURL: '/crop-only',
|
||||
staticDir: './crop-only',
|
||||
staticDir: path.resolve(__dirname, './crop-only'),
|
||||
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
|
||||
imageSizes: [
|
||||
{
|
||||
@@ -152,7 +156,7 @@ export default buildConfigWithDefaults({
|
||||
upload: {
|
||||
crop: false,
|
||||
staticURL: '/focal-only',
|
||||
staticDir: './focal-only',
|
||||
staticDir: path.resolve(__dirname, './focal-only'),
|
||||
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
|
||||
imageSizes: [
|
||||
{
|
||||
@@ -178,7 +182,7 @@ export default buildConfigWithDefaults({
|
||||
slug: mediaSlug,
|
||||
upload: {
|
||||
staticURL: '/media',
|
||||
staticDir: './media',
|
||||
staticDir: path.resolve(__dirname, './media'),
|
||||
// crop: false,
|
||||
// focalPoint: false,
|
||||
mimeTypes: [
|
||||
@@ -284,7 +288,7 @@ export default buildConfigWithDefaults({
|
||||
slug: enlargeSlug,
|
||||
upload: {
|
||||
staticURL: '/enlarge',
|
||||
staticDir: './media/enlarge',
|
||||
staticDir: path.resolve(__dirname, './media/enlarge'),
|
||||
mimeTypes: [
|
||||
'image/png',
|
||||
'image/jpg',
|
||||
@@ -332,7 +336,7 @@ export default buildConfigWithDefaults({
|
||||
slug: reduceSlug,
|
||||
upload: {
|
||||
staticURL: '/reduce',
|
||||
staticDir: './media/reduce',
|
||||
staticDir: path.resolve(__dirname, './media/reduce'),
|
||||
mimeTypes: [
|
||||
'image/png',
|
||||
'image/jpg',
|
||||
@@ -374,7 +378,7 @@ export default buildConfigWithDefaults({
|
||||
slug: 'media-trim',
|
||||
upload: {
|
||||
staticURL: '/media-trim',
|
||||
staticDir: './media-trim',
|
||||
staticDir: path.resolve(__dirname, './media-trim'),
|
||||
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg'],
|
||||
trimOptions: 0,
|
||||
imageSizes: [
|
||||
@@ -404,7 +408,7 @@ export default buildConfigWithDefaults({
|
||||
fields: [],
|
||||
},
|
||||
{
|
||||
slug: 'unstored-media',
|
||||
slug: unstoredMediaSlug,
|
||||
upload: {
|
||||
staticURL: '/media',
|
||||
disableLocalStorage: true,
|
||||
@@ -416,7 +420,7 @@ export default buildConfigWithDefaults({
|
||||
upload: {
|
||||
// Either use another web server like `npx serve -l 4000` (http://localhost:4000) or use the static server from the previous collection to serve the media folder (http://localhost:3000/media)
|
||||
staticURL: 'http://localhost:3000/media',
|
||||
staticDir: './media',
|
||||
staticDir: path.resolve(__dirname, './media'),
|
||||
},
|
||||
fields: [],
|
||||
},
|
||||
@@ -427,7 +431,7 @@ export default buildConfigWithDefaults({
|
||||
slug: 'optional-file',
|
||||
upload: {
|
||||
staticURL: '/optional',
|
||||
staticDir: './optional',
|
||||
staticDir: path.resolve(__dirname, './optional'),
|
||||
filesRequiredOnCreate: false,
|
||||
},
|
||||
fields: [],
|
||||
@@ -436,7 +440,7 @@ export default buildConfigWithDefaults({
|
||||
slug: 'required-file',
|
||||
upload: {
|
||||
staticURL: '/required',
|
||||
staticDir: './required',
|
||||
staticDir: path.resolve(__dirname, './required'),
|
||||
filesRequiredOnCreate: true,
|
||||
},
|
||||
fields: [],
|
||||
|
||||
@@ -12,7 +12,14 @@ import getFileByPath from '../../packages/payload/src/uploads/getFileByPath'
|
||||
import { NextRESTClient } from '../helpers/NextRESTClient'
|
||||
import { startMemoryDB } from '../startMemoryDB'
|
||||
import configPromise from './config'
|
||||
import { enlargeSlug, mediaSlug, reduceSlug, relationSlug, usersSlug } from './shared'
|
||||
import {
|
||||
enlargeSlug,
|
||||
mediaSlug,
|
||||
reduceSlug,
|
||||
relationSlug,
|
||||
unstoredMediaSlug,
|
||||
usersSlug,
|
||||
} from './shared'
|
||||
|
||||
const getMimeType = (
|
||||
filePath: string,
|
||||
@@ -214,7 +221,7 @@ describe('Collections - Uploads', () => {
|
||||
formData.append('file', fileBlob)
|
||||
|
||||
// unstored media
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
const response = await restClient.POST(`/${unstoredMediaSlug}`, {
|
||||
body: formData,
|
||||
file: true,
|
||||
})
|
||||
@@ -368,8 +375,8 @@ describe('Collections - Uploads', () => {
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
|
||||
// Check that previously existing files were removed
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(true)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.sizes.icon.filename))).toBe(true)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(false)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.sizes.icon.filename))).toBe(false)
|
||||
})
|
||||
|
||||
it('update - update many', async () => {
|
||||
@@ -404,8 +411,8 @@ describe('Collections - Uploads', () => {
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
|
||||
// Check that previously existing files were removed
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(true)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.sizes.icon.filename))).toBe(true)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(false)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.sizes.icon.filename))).toBe(false)
|
||||
})
|
||||
|
||||
it('should remove existing media on re-upload', async () => {
|
||||
@@ -462,7 +469,7 @@ describe('Collections - Uploads', () => {
|
||||
// Replace the temp file with a new one
|
||||
const newFilePath = path.resolve(__dirname, './temp-renamed.png')
|
||||
const newFile = await getFileByPath(newFilePath)
|
||||
newFile.name = 'temp-renamed.png'
|
||||
newFile.name = 'temp-renamed-second.png'
|
||||
|
||||
const updatedMediaDoc = (await payload.update({
|
||||
collection: mediaSlug,
|
||||
@@ -474,6 +481,7 @@ describe('Collections - Uploads', () => {
|
||||
})) as unknown as { docs: Media[] }
|
||||
|
||||
// Check that the replacement file was created and the old one was removed
|
||||
expect(updatedMediaDoc.docs[0].filename).toEqual(newFile.name)
|
||||
expect(await fileExists(path.join(expectedPath, updatedMediaDoc.docs[0].filename))).toBe(true)
|
||||
expect(await fileExists(path.join(expectedPath, mediaDoc.filename))).toBe(false)
|
||||
})
|
||||
@@ -588,13 +596,13 @@ describe('Collections - Uploads', () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', await bufferToFileBlob(path.join(__dirname, './image.png')))
|
||||
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
body: formData,
|
||||
file: true,
|
||||
})
|
||||
expect(response.status).toBe(200)
|
||||
const { doc } = await restClient
|
||||
.POST(`/${mediaSlug}`, {
|
||||
body: formData,
|
||||
file: true,
|
||||
})
|
||||
.then((res) => res.json())
|
||||
|
||||
const { doc } = await response.json()
|
||||
const response2 = await restClient.DELETE(`/${mediaSlug}/${doc.id}`)
|
||||
expect(response2.status).toBe(200)
|
||||
|
||||
@@ -605,12 +613,12 @@ describe('Collections - Uploads', () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', await bufferToFileBlob(path.join(__dirname, './image.png')))
|
||||
|
||||
const response = await restClient.POST(`/${mediaSlug}`, {
|
||||
body: formData,
|
||||
file: true,
|
||||
})
|
||||
expect(response.status).toBe(200)
|
||||
const { doc } = await response.json()
|
||||
const { doc } = await restClient
|
||||
.POST(`/${mediaSlug}`, {
|
||||
body: formData,
|
||||
file: true,
|
||||
})
|
||||
.then((res) => res.json())
|
||||
|
||||
const { errors } = await restClient
|
||||
.DELETE(`/${mediaSlug}`, {
|
||||
|
||||
@@ -11,3 +11,5 @@ export const enlargeSlug = 'enlarge'
|
||||
export const reduceSlug = 'reduce'
|
||||
|
||||
export const adminThumbnailSlug = 'admin-thumbnail'
|
||||
|
||||
export const unstoredMediaSlug = 'unstored-media'
|
||||
|
||||
Reference in New Issue
Block a user