diff --git a/specs/entity/post.e2e.spec.ts b/specs/entity/post.e2e.spec.ts index 12e2efb..dc6d215 100644 --- a/specs/entity/post.e2e.spec.ts +++ b/specs/entity/post.e2e.spec.ts @@ -30,21 +30,4 @@ describe('POST /entity', () => { .send({}) .expect(400) }) - test('should reject entity with invalid properties', async () => { - await request(app) - .post('/entity') - .send({ - "title": 1, - "properties": "invalid", - "description": "Lorem lorem lorem", - "author": "John Doe", - "image": { - "src": "url", - "alt": "alt" - }, - "sections": "markdown content", - "type": "item" - }) - .expect(400) - }) }) diff --git a/src/schemas/entity.schema.ts b/src/schemas/entity.schema.ts index e99ea0c..ea84a37 100644 --- a/src/schemas/entity.schema.ts +++ b/src/schemas/entity.schema.ts @@ -5,7 +5,7 @@ const entitySchema = { title: Yup.string() .required() .typeError('Title must be a string.'), - properties: Yup.object() + properties: Yup.mixed() .required() .default({}) .typeError('Properties must be an object.'), @@ -16,7 +16,10 @@ const entitySchema = { author: Yup.string().nullable() .max(30) .typeError('Author must be a string.'), - image: Yup.object().nullable() + image: Yup.object().default(null).shape({ + src: Yup.string(), + alt: Yup.string() + }).nullable() .test('is-image', 'Image must be a valid image.', (value) => { if (!value) return true @@ -24,7 +27,9 @@ const entitySchema = { if (keys.length !== 2) return false - if (!keys.includes('src') || !keys.includes('alt')) return false + if (!keys.includes('src') || !keys.includes('alt')) { + return false + } return true })