| 
									
										
										
										
											2020-08-21 16:19:11 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | // Helpers.
 | 
					
						
							| 
									
										
										
										
											2021-09-24 09:04:44 +02:00
										 |  |  | const { createTestBuilder } = require('../../../../../test/helpers/builder'); | 
					
						
							|  |  |  | const { createStrapiInstance } = require('../../../../../test/helpers/strapi'); | 
					
						
							|  |  |  | const form = require('../../../../../test/helpers/generators'); | 
					
						
							|  |  |  | const { createAuthRequest } = require('../../../../../test/helpers/request'); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | const cleanDate = (entry) => { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |   delete entry.updatedAt; | 
					
						
							|  |  |  |   delete entry.createdAt; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  | const builder = createTestBuilder(); | 
					
						
							|  |  |  | let strapi; | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | let data; | 
					
						
							|  |  |  | let rq; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  | const deleteFixtures = async () => { | 
					
						
							|  |  |  |   for (const [name, modelName] of [ | 
					
						
							|  |  |  |     ['references', 'reference'], | 
					
						
							|  |  |  |     ['tags', 'tag'], | 
					
						
							|  |  |  |     ['categories', 'category'], | 
					
						
							|  |  |  |     ['articles', 'article'], | 
					
						
							|  |  |  |     ['articlesWithTag', 'articlewithtag'], | 
					
						
							|  |  |  |   ]) { | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |     const uid = `api::${modelName}.${modelName}`; | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |     if (data[name] && data[name].length > 0) { | 
					
						
							|  |  |  |       await rq({ | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         url: `/content-manager/collection-types/${uid}/actions/bulkDelete`, | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           ids: (data[name] || []).map(({ id }) => id), | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | describe('Content Manager End to End', () => { | 
					
						
							|  |  |  |   beforeAll(async () => { | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |     await builder | 
					
						
							|  |  |  |       .addContentTypes( | 
					
						
							|  |  |  |         [form.article, form.tag, form.category, form.reference, form.articlewithtag], | 
					
						
							|  |  |  |         { batch: true } | 
					
						
							|  |  |  |       ) | 
					
						
							|  |  |  |       .build(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 20:20:36 +01:00
										 |  |  |     strapi = await createStrapiInstance(); | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |     rq = await createAuthRequest({ strapi }); | 
					
						
							| 
									
										
										
										
											2021-03-26 20:15:38 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |   afterAll(async () => { | 
					
						
							|  |  |  |     await strapi.destroy(); | 
					
						
							|  |  |  |     await builder.cleanup(); | 
					
						
							| 
									
										
										
										
											2021-03-26 20:15:38 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('Test manyToMany relation (article - tag) with Content Manager', () => { | 
					
						
							|  |  |  |     beforeAll(async () => { | 
					
						
							|  |  |  |       data = { | 
					
						
							|  |  |  |         articles: [], | 
					
						
							|  |  |  |         tags: [], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |     afterAll(async () => { | 
					
						
							|  |  |  |       await deleteFixtures(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     test('Create tag1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag1', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.tags.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe('tag1'); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create tag2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag2', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.tags.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe('tag2'); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create tag3', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag3', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.tags.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe('tag3'); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create article1 without relation', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         title: 'Article 1', | 
					
						
							|  |  |  |         content: 'My super content 1', | 
					
						
							| 
									
										
										
										
											2019-08-05 15:22:39 +02:00
										 |  |  |         date: '2019-08-13T00:00:00.000Z', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-11-25 09:09:13 +01:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(0); | 
					
						
							|  |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create article2 with tag1', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         title: 'Article 2', | 
					
						
							|  |  |  |         content: 'Content 2', | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |         tags: [data.tags[0].id], | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(body.tags[0].id).toBe(data.tags[0].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 add tag2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[0], tags: [data.tags[1].id] }; | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(body.tags[0].id).toBe(data.tags[1].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 add tag1 and tag3', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[0] }; | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |       entry.tags = entry.tags.map((tag) => tag.id); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       entry.tags.push(data.tags[0].id); | 
					
						
							|  |  |  |       entry.tags.push(data.tags[2].id); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(3); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 remove one tag', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[0] }; | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |       entry.tags = entry.tags.slice(1).map((tag) => tag.id); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 remove all tag', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[0], tags: [] }; | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2020-08-21 19:13:02 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     test('Delete all articles should remove the association in each tags related to them', async () => { | 
					
						
							| 
									
										
										
										
											2019-03-12 11:58:30 +01:00
										 |  |  |       const { body: createdTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag11', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body: article12 } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           title: 'article12', | 
					
						
							|  |  |  |           content: 'Content', | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |           tags: [createdTag.id], | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-12 11:58:30 +01:00
										 |  |  |       const { body: updatedTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::tag.tag/${createdTag.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-12 11:58:30 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       const { body: article13 } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           title: 'article13', | 
					
						
							|  |  |  |           content: 'Content', | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |           tags: [updatedTag.id], | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const articles = [article12, article13]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:40 +02:00
										 |  |  |       expect(Array.isArray(articles[0].tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(articles[0].tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(Array.isArray(articles[1].tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(articles[1].tags.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body: foundTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::tag.tag/${createdTag.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:40 +02:00
										 |  |  |       expect(Array.isArray(foundTag.articles)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(foundTag.articles.length).toBe(2); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article/actions/bulkDelete', | 
					
						
							| 
									
										
										
										
											2020-11-02 12:40:35 +01:00
										 |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |           ids: articles.map((article) => article.id), | 
					
						
							| 
									
										
										
										
											2020-11-02 12:40:35 +01:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body: foundTag2 } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::tag.tag/${createdTag.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:40 +02:00
										 |  |  |       expect(Array.isArray(foundTag2.articles)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(foundTag2.articles.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |   describe('Test manyWay articlesWithTags and tags', () => { | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |     beforeAll(() => { | 
					
						
							|  |  |  |       data = { | 
					
						
							|  |  |  |         tags: [], | 
					
						
							|  |  |  |         articlesWithTag: [], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     afterAll(async () => { | 
					
						
							|  |  |  |       await deleteFixtures(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |     test('Creating an article with some many way tags', async () => { | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |       const { body: createdTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           name: 'tag11', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.tags.push(createdTag); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |       const entry = { | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |         tags: [createdTag.id], | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::articlewithtag.articlewithtag', | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |       data.articlesWithTag.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(body.tags[0].id).toBe(data.tags[0].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-07-08 17:34:56 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |   describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => { | 
					
						
							|  |  |  |     beforeAll(() => { | 
					
						
							|  |  |  |       data = { | 
					
						
							|  |  |  |         articles: [], | 
					
						
							|  |  |  |         categories: [], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |     afterAll(async () => { | 
					
						
							|  |  |  |       await deleteFixtures(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     test('Create cat1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::category.category', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'cat1', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.categories.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe('cat1'); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::category.category', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'cat2', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.categories.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe('cat2'); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create article1 with cat1', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         title: 'Article 1', | 
					
						
							|  |  |  |         content: 'Content 1', | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |         category: data.categories[0].id, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.category.name).toBe(data.categories[0].name); | 
					
						
							|  |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 with cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[0], category: data.categories[1].id }; | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.category.name).toBe(data.categories[1].name); | 
					
						
							|  |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create article2', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         title: 'Article 2', | 
					
						
							|  |  |  |         content: 'Content 2', | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article2 with cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[1], category: data.categories[1].id }; | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[1] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.category.name).toBe(data.categories[1].name); | 
					
						
							|  |  |  |       expect(Array.isArray(body.tags)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update cat1 with article1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.categories[0] }; | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |       entry.articles = entry.articles.map((article) => article.id); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       entry.articles.push(data.articles[0].id); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::category.category/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.categories[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.articles.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe(entry.name); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create cat3 with article1', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         name: 'cat3', | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |         articles: [data.articles[0].id], | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::category.category', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.categories.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(Array.isArray(body.articles)).toBeTruthy(); | 
					
						
							|  |  |  |       expect(body.articles.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe(entry.name); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Get article1 with cat3', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.category.id).toBe(data.categories[2].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Get article2 with cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[1].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.category.id).toBe(data.categories[1].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Get cat1 without relations', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::category.category/${data.categories[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.articles.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Get cat2 with article2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::category.category/${data.categories[1].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.articles.length).toBe(1); | 
					
						
							|  |  |  |       expect(body.articles[0].id).toBe(data.articles[1].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Get cat3 with article1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::category.category/${data.categories[2].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.articles.length).toBe(1); | 
					
						
							|  |  |  |       expect(body.articles[0].id).toBe(data.articles[0].id); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('Test oneToOne relation (article - reference) with Content Manager', () => { | 
					
						
							|  |  |  |     beforeAll(() => { | 
					
						
							|  |  |  |       data = { | 
					
						
							|  |  |  |         articles: [], | 
					
						
							|  |  |  |         references: [], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-02 17:19:42 +01:00
										 |  |  |     afterAll(async () => { | 
					
						
							|  |  |  |       await deleteFixtures(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     test('Create ref1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::reference.reference', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'ref1', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.references.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.name).toBe('ref1'); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create article1', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         title: 'Article 1', | 
					
						
							|  |  |  |         content: 'Content 1', | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 with ref1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const entry = { ...data.articles[0], reference: data.references[0].id }; | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       cleanDate(entry); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${entry.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.reference.id).toBe(entry.reference); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create article2 with ref1', async () => { | 
					
						
							|  |  |  |       const entry = { | 
					
						
							|  |  |  |         title: 'Article 2', | 
					
						
							|  |  |  |         content: 'Content 2', | 
					
						
							|  |  |  |         reference: data.references[0].id, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::article.article', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: entry, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles.push(body); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       expect(body.title).toBe(entry.title); | 
					
						
							|  |  |  |       expect(body.content).toBe(entry.content); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(body.reference.id).toBe(entry.reference); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         firstname: 'admin', | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         lastname: 'admin', | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('Test oneWay relation (reference - tag) with Content Manager', () => { | 
					
						
							|  |  |  |     test('Attach Tag to a Reference', async () => { | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: createdTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag111', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: createdReference } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::reference.reference', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'cat111', | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |           tag: createdTag.id, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(createdReference.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |       expect(createdReference.tag.id).toBe(createdTag.id); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Detach Tag to a Reference', async () => { | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: createdTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag111', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: createdReference } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::reference.reference', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'cat111', | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:40 +02:00
										 |  |  |           tag: createdTag.id, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:40 +02:00
										 |  |  |       expect(createdReference.tag.id).toBe(createdTag.id); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const { body: referenceToUpdate } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::reference.reference/${createdReference.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           tag: null, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 19:39:40 +02:00
										 |  |  |       expect(referenceToUpdate.tag).toBe(null); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Delete Tag so the relation in the Reference side should be removed', async () => { | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: createdTag } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::tag.tag', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'tag111', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: createdReference } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: '/content-manager/collection-types/api::reference.reference', | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-07-30 16:37:15 +02:00
										 |  |  |         body: { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |           name: 'cat111', | 
					
						
							| 
									
										
										
										
											2021-08-11 09:34:55 +02:00
										 |  |  |           tag: createdTag.id, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::tag.tag/${createdTag.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'DELETE', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       const { body: foundReference } = await rq({ | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::reference.reference/${createdReference.id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       if (!foundReference.tag || Object.keys(foundReference.tag).length === 0) return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(foundReference.tag).toBe(null); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |