| 
									
										
										
										
											2020-08-21 16:19:11 +02:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | const { isEmpty } = require('lodash/fp'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 10:32:20 +02:00
										 |  |  | const { createTestBuilder } = require('api-tests/builder'); | 
					
						
							|  |  |  | const { createStrapiInstance } = require('api-tests/strapi'); | 
					
						
							|  |  |  | const form = require('api-tests/generators'); | 
					
						
							|  |  |  | const { createAuthRequest } = require('api-tests/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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | const getRelations = async (modelName, field, id) => { | 
					
						
							|  |  |  |   const res = await rq({ | 
					
						
							|  |  |  |     method: 'GET', | 
					
						
							| 
									
										
										
										
											2022-10-04 16:25:36 +02:00
										 |  |  |     url: `/content-manager/relations/api::${modelName}.${modelName}/${id}/${field}`, | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return res.body; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-26 11:28:35 +02:00
										 |  |  | describe('Relations', () => { | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |   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(); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         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(); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         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(); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         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', | 
					
						
							| 
									
										
										
										
											2022-09-01 11:05:18 +02:00
										 |  |  |         date: '2019-08-13', | 
					
						
							| 
									
										
										
										
											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(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(0); | 
					
						
							| 
									
										
										
										
											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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(tags[0].id).toBe(data.tags[0].id); | 
					
						
							| 
									
										
										
										
											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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(tags[0].id).toBe(data.tags[1].id); | 
					
						
							| 
									
										
										
										
											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 { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           tags: [data.tags[0].id, data.tags[1].id, data.tags[2].id], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.title).toBe(data.articles[0].title); | 
					
						
							|  |  |  |       expect(body.content).toBe(data.articles[0].content); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(3); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article1 remove one tag', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           tags: [data.tags[1].id, data.tags[2].id], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.title).toBe(data.articles[0].title); | 
					
						
							|  |  |  |       expect(body.content).toBe(data.articles[0].content); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(2); | 
					
						
							| 
									
										
										
										
											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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(0); | 
					
						
							| 
									
										
										
										
											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
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-26 10:41:31 +02:00
										 |  |  |       expect(foundTag.articles.count).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-09-07 15:40:35 +02:00
										 |  |  |           ids: [article12.id, article13.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', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-26 10:41:31 +02:00
										 |  |  |       expect(foundTag2.articles.count).toBe(0); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-07-12 17:15:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     test('Bulk delete of unknown or already deleted entries should succeed', async () => { | 
					
						
							|  |  |  |       const res = await rq({ | 
					
						
							|  |  |  |         url: '/content-manager/collection-types/api::article.article/actions/bulkDelete', | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body: { | 
					
						
							|  |  |  |           ids: [9999999], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.body).toEqual({ | 
					
						
							|  |  |  |         count: 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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('articlewithtag', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(1); | 
					
						
							|  |  |  |       expect(tags[0].id).toBe(data.tags[0].id); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const articles = (await getRelations('category', 'articles', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(articles.length).toBe(0); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-22 12:14:41 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const articles = (await getRelations('category', 'articles', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(articles.length).toBe(0); | 
					
						
							| 
									
										
										
										
											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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.publishedAt).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const category = (await getRelations('article', 'category', body.id)).data; | 
					
						
							|  |  |  |       expect(category.name).toBe(data.categories[0].name); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Update article1 with cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           category: data.categories[1].id, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.title).toBe(data.articles[0].title); | 
					
						
							|  |  |  |       expect(body.content).toBe(data.articles[0].content); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const category = (await getRelations('article', 'category', body.id)).data; | 
					
						
							|  |  |  |       expect(category.name).toBe(data.categories[1].name); | 
					
						
							| 
									
										
										
										
											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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update article2 with cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[1].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           category: data.categories[1].id, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[1] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.title).toBe(data.articles[1].title); | 
					
						
							|  |  |  |       expect(body.content).toBe(data.articles[1].content); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tags = (await getRelations('article', 'tags', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(tags.length).toBe(0); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const category = (await getRelations('article', 'category', body.id)).data; | 
					
						
							|  |  |  |       expect(category.name).toBe(data.categories[1].name); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Update cat1 with article1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::category.category/${data.categories[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           articles: [data.articles[0].id], | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.categories[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.name).toBe(data.categories[0].name); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const articles = (await getRelations('category', 'articles', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(articles.length).toBe(1); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const articles = (await getRelations('category', 'articles', body.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(articles.length).toBe(1); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Get article1 with cat3', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-10-04 16:25:36 +02:00
										 |  |  |         url: `/content-manager/relations/api::article.article/${data.articles[0].id}/category`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       expect(body).toMatchObject({ data: { name: 'cat3' } }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Get article2 with cat2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-10-04 16:25:36 +02:00
										 |  |  |         url: `/content-manager/relations/api::article.article/${data.articles[1].id}/category`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       expect(body).toMatchObject({ data: { name: 'cat2' } }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Get cat1 without relations', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-10-04 16:25:36 +02:00
										 |  |  |         url: `/content-manager/relations/api::category.category/${data.categories[0].id}/articles`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-01 11:05:18 +02:00
										 |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         results: [], | 
					
						
							|  |  |  |         pagination: { | 
					
						
							|  |  |  |           total: 0, | 
					
						
							|  |  |  |           pageSize: 10, | 
					
						
							|  |  |  |           page: 1, | 
					
						
							|  |  |  |           pageCount: 0, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Get cat2 with article2', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-10-04 16:25:36 +02:00
										 |  |  |         url: `/content-manager/relations/api::category.category/${data.categories[1].id}/articles`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-01 11:05:18 +02:00
										 |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         pagination: { page: 1, pageCount: 1, pageSize: 10, total: 1 }, | 
					
						
							|  |  |  |         results: [{ title: 'Article 2' }], | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |     test('Get cat3 with article1', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       const { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-10-04 16:25:36 +02:00
										 |  |  |         url: `/content-manager/relations/api::category.category/${data.categories[2].id}/articles`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-01 11:05:18 +02:00
										 |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         pagination: { page: 1, pageCount: 1, pageSize: 10, total: 1 }, | 
					
						
							|  |  |  |         results: [{ title: 'Article 1' }], | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         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({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         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 { body } = await rq({ | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         url: `/content-manager/collection-types/api::article.article/${data.articles[0].id}`, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |         method: 'PUT', | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |         body: { | 
					
						
							|  |  |  |           reference: data.references[0].id, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.articles[0] = body; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-05 23:31:23 +02:00
										 |  |  |       expect(body.id).toBeDefined(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(body.title).toBe(data.articles[0].title); | 
					
						
							|  |  |  |       expect(body.content).toBe(data.articles[0].content); | 
					
						
							| 
									
										
										
										
											2021-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const reference = (await getRelations('article', 'reference', body.id)).data; | 
					
						
							|  |  |  |       expect(reference.id).toBe(data.references[0].id); | 
					
						
							| 
									
										
										
										
											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-11-24 16:20:57 +01:00
										 |  |  |       expect(body.createdBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       expect(body.updatedBy).toMatchObject({ | 
					
						
							|  |  |  |         id: 1, | 
					
						
							|  |  |  |         username: null, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const reference = (await getRelations('article', 'reference', body.id)).data; | 
					
						
							|  |  |  |       expect(reference.id).toBe(data.references[0].id); | 
					
						
							| 
									
										
										
										
											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(); | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       const tag = (await getRelations('reference', 'tag', createdReference.id)).data; | 
					
						
							|  |  |  |       expect(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
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       let tag = (await getRelations('reference', 'tag', createdReference.id)).data; | 
					
						
							|  |  |  |       expect(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, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-13 14:42:53 +02:00
										 |  |  |       tag = (await getRelations('reference', 'tag', referenceToUpdate.id)).results; | 
					
						
							| 
									
										
										
										
											2022-09-07 15:40:35 +02:00
										 |  |  |       expect(isEmpty(tag)).toBe(true); | 
					
						
							| 
									
										
										
										
											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', | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-17 18:55:21 +02:00
										 |  |  |       expect(foundReference.tag.count).toBe(0); | 
					
						
							| 
									
										
										
										
											2019-03-09 01:06:39 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |