| 
									
										
										
										
											2020-10-27 11:27:17 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 10:32:20 +02:00
										 |  |  | const { createTestBuilder } = require('api-tests/builder'); | 
					
						
							|  |  |  | const { createStrapiInstance } = require('api-tests/strapi'); | 
					
						
							|  |  |  | const { createAuthRequest } = require('api-tests/request'); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  | let strapi; | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | let rq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  | const component = { | 
					
						
							| 
									
										
										
										
											2021-11-02 18:27:49 +01:00
										 |  |  |   displayName: 'somecomponent', | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'string', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const ct = { | 
					
						
							|  |  |  |   name: 'withcomponent', | 
					
						
							| 
									
										
										
										
											2021-09-13 16:57:04 +02:00
										 |  |  |   displayName: 'withcomponent', | 
					
						
							|  |  |  |   singularName: 'withcomponent', | 
					
						
							|  |  |  |   pluralName: 'withcomponents', | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |   attributes: { | 
					
						
							|  |  |  |     field: { | 
					
						
							|  |  |  |       type: 'component', | 
					
						
							|  |  |  |       component: 'default.somecomponent', | 
					
						
							|  |  |  |       repeatable: false, | 
					
						
							|  |  |  |       required: false, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-10 18:58:18 +02:00
										 |  |  | describe('Non repeatable and Not required component', () => { | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |   const builder = createTestBuilder(); | 
					
						
							| 
									
										
										
										
											2020-11-03 13:42:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |   beforeAll(async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     await builder.addComponent(component).addContentType(ct).build(); | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 20:20:36 +01:00
										 |  |  |     strapi = await createStrapiInstance(); | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |     rq = await createAuthRequest({ strapi }); | 
					
						
							| 
									
										
										
										
											2021-08-13 15:43:04 +02:00
										 |  |  |     rq.setURLPrefix('/content-manager/collection-types/api::withcomponent.withcomponent'); | 
					
						
							| 
									
										
										
										
											2021-03-26 20:15:38 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   afterAll(async () => { | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |     await strapi.destroy(); | 
					
						
							|  |  |  |     await builder.cleanup(); | 
					
						
							| 
									
										
										
										
											2021-03-26 20:15:38 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('POST new entry', () => { | 
					
						
							|  |  |  |     test('Creating entry with JSON works', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body.field).toEqual( | 
					
						
							|  |  |  |         expect.objectContaining({ | 
					
						
							|  |  |  |           id: expect.anything(), | 
					
						
							|  |  |  |           name: 'someString', | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-03 13:42:01 +01:00
										 |  |  |     test('Creating second entry ', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2020-11-03 13:42:01 +01:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someValue', | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body.field).toEqual( | 
					
						
							|  |  |  |         expect.objectContaining({ | 
					
						
							|  |  |  |           id: expect.anything(), | 
					
						
							|  |  |  |           name: 'someValue', | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test.each([[], 'someString', 128219, false])( | 
					
						
							|  |  |  |       'Throws if the field is not an object %p', | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |       async (value) => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |         const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |           body: { | 
					
						
							|  |  |  |             field: value, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(res.statusCode).toBe(400); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Can send a null value', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: null, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body.field).toBe(null); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Can send input without the component field', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: {}, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body.field).toBe(null); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('GET entries', () => { | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Should return entries with their nested components', async () => { | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const res = await rq.get('/', { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2020-11-03 13:42:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-10 18:58:18 +02:00
										 |  |  |       expect(res.body.pagination).toBeDefined(); | 
					
						
							|  |  |  |       expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |       res.body.results.forEach((entry) => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         if (entry.field === null) return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(entry.field).toMatchObject({ | 
					
						
							|  |  |  |           name: expect.any(String), | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('PUT entry', () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 10:44:24 +02:00
										 |  |  |     test.each([[], 'someString', 128219, false])( | 
					
						
							|  |  |  |       'Throws when sending invalid updated field %p', | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |       async (value) => { | 
					
						
							| 
									
										
										
										
											2019-08-09 10:44:24 +02:00
										 |  |  |         const res = await rq.post('/', { | 
					
						
							|  |  |  |           body: { | 
					
						
							|  |  |  |             field: { | 
					
						
							|  |  |  |               name: 'someString', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |           qs: { | 
					
						
							|  |  |  |             populate: ['field'], | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-08-09 10:44:24 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const updateRes = await rq.put(`/${res.body.id}`, { | 
					
						
							|  |  |  |           body: { | 
					
						
							|  |  |  |             field: value, | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |           qs: { | 
					
						
							|  |  |  |             populate: ['field'], | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-08-09 10:44:24 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(updateRes.statusCode).toBe(400); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // shouldn't have been updated
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         const getRes = await rq.get(`/${res.body.id}`, { | 
					
						
							|  |  |  |           qs: { | 
					
						
							|  |  |  |             populate: ['field'], | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-08-09 10:44:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         expect(getRes.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2019-08-09 11:45:31 +02:00
										 |  |  |         expect(getRes.body).toMatchObject({ | 
					
						
							|  |  |  |           id: res.body.id, | 
					
						
							|  |  |  |           field: res.body.field, | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-08-09 10:44:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Keeps the previous value if component not sent', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const updateRes = await rq.put(`/${res.body.id}`, { | 
					
						
							|  |  |  |         body: {}, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(updateRes.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2019-08-09 11:45:31 +02:00
										 |  |  |       expect(updateRes.body).toMatchObject({ | 
					
						
							|  |  |  |         id: res.body.id, | 
					
						
							|  |  |  |         field: res.body.field, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const getRes = await rq.get(`/${res.body.id}`, { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(getRes.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2019-08-09 11:45:31 +02:00
										 |  |  |       expect(getRes.body).toMatchObject({ | 
					
						
							|  |  |  |         id: res.body.id, | 
					
						
							|  |  |  |         field: res.body.field, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Removes previous component if null sent', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const updateRes = await rq.put(`/${res.body.id}`, { | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           field: null, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const expectResult = { | 
					
						
							|  |  |  |         id: res.body.id, | 
					
						
							|  |  |  |         field: null, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(updateRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(updateRes.body).toMatchObject(expectResult); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const getRes = await rq.get(`/${res.body.id}`, { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(getRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(getRes.body).toMatchObject(expectResult); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Replaces the previous component if sent without id', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const updateRes = await rq.put(`/${res.body.id}`, { | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'new String', | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(updateRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(updateRes.body.field.id).not.toBe(res.body.field.id); | 
					
						
							|  |  |  |       expect(updateRes.body).toMatchObject({ | 
					
						
							|  |  |  |         id: res.body.id, | 
					
						
							|  |  |  |         field: { | 
					
						
							|  |  |  |           name: 'new String', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const getRes = await rq.get(`/${res.body.id}`, { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(getRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(getRes.body).toMatchObject({ | 
					
						
							|  |  |  |         id: res.body.id, | 
					
						
							|  |  |  |         field: { | 
					
						
							|  |  |  |           name: 'new String', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Throws on invalid id in component', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const updateRes = await rq.put(`/${res.body.id}`, { | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             id: 'invalid_id', | 
					
						
							|  |  |  |             name: 'new String', | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(updateRes.statusCode).toBe(400); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Updates component if previsous component id is sent', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const updateRes = await rq.put(`/${res.body.id}`, { | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |             id: res.body.field.id, // send old id to update the previous component
 | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |             name: 'new String', | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const expectedResult = { | 
					
						
							|  |  |  |         id: res.body.id, | 
					
						
							|  |  |  |         field: { | 
					
						
							|  |  |  |           id: res.body.field.id, | 
					
						
							|  |  |  |           name: 'new String', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(updateRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(updateRes.body).toMatchObject(expectedResult); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const getRes = await rq.get(`/${res.body.id}`, { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(getRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(getRes.body).toMatchObject(expectedResult); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('DELETE entry', () => { | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     test('Returns entry with components', async () => { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:53:08 +02:00
										 |  |  |       const res = await rq.post('/', { | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           field: { | 
					
						
							|  |  |  |             name: 'someString', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const deleteRes = await rq.delete(`/${res.body.id}`, { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(deleteRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(deleteRes.body).toMatchObject(res.body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-19 21:17:34 +02:00
										 |  |  |       const getRes = await rq.get(`/${res.body.id}`, { | 
					
						
							|  |  |  |         qs: { | 
					
						
							|  |  |  |           populate: ['field'], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-08-09 09:42:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect(getRes.statusCode).toBe(404); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |