| 
									
										
										
										
											2020-10-27 11:27:17 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | // Helpers.
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | const { pick } = require('lodash/fp'); | 
					
						
							| 
									
										
										
										
											2023-04-05 10:32:20 +02:00
										 |  |  | const { createTestBuilder } = require('api-tests/builder'); | 
					
						
							|  |  |  | const { createStrapiInstance } = require('api-tests/strapi'); | 
					
						
							|  |  |  | const { createAuthRequest } = require('api-tests/request'); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  | const builder = createTestBuilder(); | 
					
						
							|  |  |  | let strapi; | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | let rq; | 
					
						
							|  |  |  | let graphqlQuery; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | // Utils
 | 
					
						
							|  |  |  | const selectFields = pick(['name', 'color']); | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const rgbColorComponent = { | 
					
						
							|  |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'text', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     red: { | 
					
						
							|  |  |  |       type: 'integer', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     green: { | 
					
						
							|  |  |  |       type: 'integer', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     blue: { | 
					
						
							|  |  |  |       type: 'integer', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-11-02 18:27:49 +01:00
										 |  |  |   displayName: 'rgbColor', | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const documentModel = { | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'richtext', | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |     content: { | 
					
						
							|  |  |  |       type: 'richtext', | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-22 11:59:03 +02:00
										 |  |  |   singularName: 'document', | 
					
						
							|  |  |  |   pluralName: 'documents', | 
					
						
							|  |  |  |   displayName: 'Document', | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |   description: '', | 
					
						
							|  |  |  |   collectionName: '', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const labelModel = { | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'richtext', | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |     documents: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'manyToMany', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::document.document', | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |       targetAttribute: 'labels', | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |     color: { | 
					
						
							|  |  |  |       type: 'component', | 
					
						
							|  |  |  |       component: 'default.rgb-color', | 
					
						
							|  |  |  |       repeatable: false, | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-22 11:59:03 +02:00
										 |  |  |   singularName: 'label', | 
					
						
							|  |  |  |   pluralName: 'labels', | 
					
						
							|  |  |  |   displayName: 'Label', | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |   description: '', | 
					
						
							|  |  |  |   collectionName: '', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  | const carModel = { | 
					
						
							|  |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'text', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-22 11:59:03 +02:00
										 |  |  |   singularName: 'car', | 
					
						
							|  |  |  |   pluralName: 'cars', | 
					
						
							|  |  |  |   displayName: 'Car', | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |   description: '', | 
					
						
							|  |  |  |   collectionName: '', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const personModel = { | 
					
						
							|  |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'text', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     privateName: { | 
					
						
							|  |  |  |       type: 'text', | 
					
						
							|  |  |  |       private: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     privateCars: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'oneToMany', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::car.car', | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |       targetAttribute: 'person', | 
					
						
							|  |  |  |       private: true, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-10-22 11:59:03 +02:00
										 |  |  |   displayName: 'Person', | 
					
						
							|  |  |  |   singularName: 'person', | 
					
						
							|  |  |  |   pluralName: 'people', | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |   description: '', | 
					
						
							|  |  |  |   collectionName: '', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | describe('Test Graphql Relations API End to End', () => { | 
					
						
							|  |  |  |   beforeAll(async () => { | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |     await builder | 
					
						
							|  |  |  |       .addComponent(rgbColorComponent) | 
					
						
							|  |  |  |       .addContentTypes([documentModel, labelModel, carModel, personModel]) | 
					
						
							|  |  |  |       .build(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 20:20:36 +01:00
										 |  |  |     strapi = await createStrapiInstance(); | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |     rq = await createAuthRequest({ strapi }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     graphqlQuery = (body) => { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |       return rq({ | 
					
						
							|  |  |  |         url: '/graphql', | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-03-26 20:15:38 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +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-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('Test relations features', () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |     const data = { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |       labels: [], | 
					
						
							|  |  |  |       documents: [], | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |       people: [], | 
					
						
							|  |  |  |       cars: [], | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |     const labelsPayload = [ | 
					
						
							|  |  |  |       { name: 'label 1', color: null }, | 
					
						
							|  |  |  |       { name: 'label 2', color: null }, | 
					
						
							|  |  |  |       { name: 'labelWithColor', color: { name: 'tomato', red: 255, green: 99, blue: 71 } }, | 
					
						
							|  |  |  |     ]; | 
					
						
							| 
									
										
										
										
											2019-03-28 15:08:00 +01:00
										 |  |  |     const documentsPayload = [{ name: 'document 1' }, { name: 'document 2' }]; | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     test.each(labelsPayload)('Create label %o', async (label) => { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           mutation createLabel($data: LabelInput!) { | 
					
						
							|  |  |  |             createLabel(data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   color { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     red | 
					
						
							|  |  |  |                     green | 
					
						
							|  |  |  |                     blue | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           data: label, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |       expect(res.body).toEqual({ | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         data: { | 
					
						
							|  |  |  |           createLabel: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             data: { | 
					
						
							|  |  |  |               attributes: label, | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('List labels', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             labels { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   name | 
					
						
							|  |  |  |                   color { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     red | 
					
						
							|  |  |  |                     green | 
					
						
							|  |  |  |                     blue | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           labels: { | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |             data: labelsPayload.map((label) => ({ id: expect.any(String), attributes: label })), | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // assign for later use
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |       data.labels = data.labels.concat(res.body.data.labels.data); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     test.each(documentsPayload)('Create document linked to every labels %o', async (document) => { | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           mutation createDocument($data: DocumentInput!) { | 
					
						
							|  |  |  |             createDocument(data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   labels { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                         color { | 
					
						
							|  |  |  |                           name | 
					
						
							|  |  |  |                           red | 
					
						
							|  |  |  |                           green | 
					
						
							|  |  |  |                           blue | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2019-04-09 18:35:49 +02:00
										 |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           data: { | 
					
						
							|  |  |  |             ...document, | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |             labels: data.labels.map((t) => t.id), | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |           }, | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |       const { body } = res; | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           createDocument: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             data: { | 
					
						
							|  |  |  |               id: expect.any(String), | 
					
						
							|  |  |  |               attributes: { | 
					
						
							|  |  |  |                 ...selectFields(document), | 
					
						
							|  |  |  |                 labels: { | 
					
						
							|  |  |  |                   data: expect.arrayContaining(data.labels), | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       data.documents.push(body.data.createDocument.data); | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     test('List documents with labels', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             documents { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   labels { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                         color { | 
					
						
							|  |  |  |                           name | 
					
						
							|  |  |  |                           red | 
					
						
							|  |  |  |                           green | 
					
						
							|  |  |  |                           blue | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							| 
									
										
										
										
											2019-04-09 18:35:49 +02:00
										 |  |  |         data: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           documents: { | 
					
						
							|  |  |  |             data: expect.arrayContaining(data.documents), | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-04-09 18:35:49 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // assign for later use
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |       data.documents = res.body.data.documents.data; | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('List Labels with documents', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             labels { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							|  |  |  |                   name | 
					
						
							|  |  |  |                   color { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     red | 
					
						
							|  |  |  |                     green | 
					
						
							|  |  |  |                     blue | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                   documents { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           labels: { | 
					
						
							|  |  |  |             data: expect.arrayContaining( | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |               data.labels.map((label) => ({ | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 id: label.id, | 
					
						
							|  |  |  |                 attributes: { | 
					
						
							|  |  |  |                   ...label.attributes, | 
					
						
							|  |  |  |                   documents: { | 
					
						
							|  |  |  |                     data: expect.arrayContaining( | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |                       data.documents.map((document) => ({ | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                         id: document.id, | 
					
						
							|  |  |  |                         attributes: selectFields(document.attributes), | 
					
						
							|  |  |  |                       })) | 
					
						
							|  |  |  |                     ), | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               })) | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // assign for later use
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |       data.labels = res.body.data.labels.data; | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-06 19:09:05 +01:00
										 |  |  |     test('List labels with documents paginated', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           query labels($pagination: PaginationArg!) { | 
					
						
							|  |  |  |             labels { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   name | 
					
						
							|  |  |  |                   color { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     red | 
					
						
							|  |  |  |                     green | 
					
						
							|  |  |  |                     blue | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                   documents(pagination: $pagination) { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           pagination: { | 
					
						
							|  |  |  |             page: 1, | 
					
						
							|  |  |  |             pageSize: 1, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           labels: { | 
					
						
							|  |  |  |             data: expect.arrayContaining( | 
					
						
							|  |  |  |               data.labels.map((label) => ({ | 
					
						
							|  |  |  |                 id: label.id, | 
					
						
							|  |  |  |                 attributes: { | 
					
						
							|  |  |  |                   ...label.attributes, | 
					
						
							|  |  |  |                   documents: { | 
					
						
							|  |  |  |                     data: expect.arrayContaining( | 
					
						
							|  |  |  |                       data.documents.slice(0, 1).map((document) => ({ | 
					
						
							|  |  |  |                         id: document.id, | 
					
						
							|  |  |  |                         attributes: selectFields(document.attributes), | 
					
						
							|  |  |  |                       })) | 
					
						
							|  |  |  |                     ), | 
					
						
							|  |  |  |                   }, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               })) | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // assign for later use
 | 
					
						
							|  |  |  |       data.labels = res.body.data.labels.data; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |     test('Deep query', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             documents(filters: { labels: { name: { contains: "label 1" } } }) { | 
					
						
							|  |  |  |               data { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   labels { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                         color { | 
					
						
							|  |  |  |                           name | 
					
						
							|  |  |  |                           red | 
					
						
							|  |  |  |                           green | 
					
						
							|  |  |  |                           blue | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           documents: { | 
					
						
							|  |  |  |             data: expect.arrayContaining(data.documents), | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update Document relations removes correctly a relation', async () => { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |       const document = data.documents[0]; | 
					
						
							|  |  |  |       const labels = [data.labels[0]]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |       // if I remove a label from an document is it working
 | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           mutation updateDocument($id: ID!, $data: DocumentInput!) { | 
					
						
							|  |  |  |             updateDocument(id: $id, data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   labels { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                         color { | 
					
						
							|  |  |  |                           name | 
					
						
							|  |  |  |                           red | 
					
						
							|  |  |  |                           green | 
					
						
							|  |  |  |                           blue | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           id: document.id, | 
					
						
							|  |  |  |           data: { | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |             labels: labels.map((label) => label.id), | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           updateDocument: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             data: { | 
					
						
							|  |  |  |               id: document.id, | 
					
						
							|  |  |  |               attributes: { | 
					
						
							|  |  |  |                 ...selectFields(document.attributes), | 
					
						
							|  |  |  |                 labels: { | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |                   data: labels.map((label) => ({ | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                     id: label.id, | 
					
						
							|  |  |  |                     attributes: { | 
					
						
							|  |  |  |                       ...selectFields(label.attributes), | 
					
						
							|  |  |  |                       color: null, | 
					
						
							|  |  |  |                     }, | 
					
						
							|  |  |  |                   })), | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Delete Labels and test Documents relations', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       for (const label of data.labels) { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         const res = await graphqlQuery({ | 
					
						
							|  |  |  |           query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             mutation deleteLabel($id: ID!) { | 
					
						
							|  |  |  |               deleteLabel(id: $id) { | 
					
						
							|  |  |  |                 data { | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |                   id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   attributes { | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                     name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                     color { | 
					
						
							|  |  |  |                       name | 
					
						
							|  |  |  |                       red | 
					
						
							|  |  |  |                       green | 
					
						
							|  |  |  |                       blue | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           `,
 | 
					
						
							|  |  |  |           variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             id: label.id, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(res.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |         expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |           data: { | 
					
						
							|  |  |  |             deleteLabel: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data: { | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |                 id: label.id, | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes: { | 
					
						
							|  |  |  |                   ...selectFields(label.attributes), | 
					
						
							|  |  |  |                   color: null, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             documents { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   labels { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                         color { | 
					
						
							|  |  |  |                           name | 
					
						
							|  |  |  |                           red | 
					
						
							|  |  |  |                           green | 
					
						
							|  |  |  |                           blue | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2020-03-16 15:42:56 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           documents: { | 
					
						
							|  |  |  |             data: expect.arrayContaining( | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |               data.documents.map((document) => ({ | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 id: document.id, | 
					
						
							|  |  |  |                 attributes: { | 
					
						
							|  |  |  |                   ...selectFields(document.attributes), | 
					
						
							|  |  |  |                   labels: { data: [] }, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               })) | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |           }, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Delete Documents', async () => { | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  |       for (const document of data.documents) { | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |         const res = await graphqlQuery({ | 
					
						
							|  |  |  |           query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             mutation deleteDocument($id: ID!) { | 
					
						
							|  |  |  |               deleteDocument(id: $id) { | 
					
						
							|  |  |  |                 data { | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |                   id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   attributes { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     labels { | 
					
						
							|  |  |  |                       data { | 
					
						
							|  |  |  |                         id | 
					
						
							|  |  |  |                         attributes { | 
					
						
							|  |  |  |                           name | 
					
						
							|  |  |  |                           color { | 
					
						
							|  |  |  |                             name | 
					
						
							|  |  |  |                             red | 
					
						
							|  |  |  |                             green | 
					
						
							|  |  |  |                           } | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           `,
 | 
					
						
							|  |  |  |           variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             id: document.id, | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         expect(res.statusCode).toBe(200); | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |         expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |           data: { | 
					
						
							|  |  |  |             deleteDocument: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data: { | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |                 id: document.id, | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes: { | 
					
						
							|  |  |  |                   ...selectFields(document.attributes), | 
					
						
							|  |  |  |                   labels: { data: [] }, | 
					
						
							|  |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2019-08-23 14:15:24 +02:00
										 |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     test('Create person', async () => { | 
					
						
							|  |  |  |       const person = { | 
					
						
							|  |  |  |         name: 'Chuck Norris', | 
					
						
							|  |  |  |         privateName: 'Jean-Eude', | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           mutation createPerson($data: PersonInput!) { | 
					
						
							|  |  |  |             createPerson(data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							|  |  |  |                   name | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           data: person, | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body).toEqual({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           createPerson: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             data: { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |               id: expect.anything(), | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               attributes: { | 
					
						
							|  |  |  |                 name: person.name, | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       data.people.push(res.body.data.createPerson.data); | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("Can't list a private field", async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             people { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   name | 
					
						
							|  |  |  |                   privateName | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(400); | 
					
						
							|  |  |  |       expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |         errors: [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             message: 'Cannot query field "privateName" on type "Person".', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Create a car linked to a person (oneToMany)', async () => { | 
					
						
							|  |  |  |       const car = { | 
					
						
							|  |  |  |         name: 'Peugeot 508', | 
					
						
							|  |  |  |         person: data.people[0].id, | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           mutation createCar($data: CarInput!) { | 
					
						
							|  |  |  |             createCar(data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |                 id | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |                   name | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |                   person { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                       attributes { | 
					
						
							|  |  |  |                         name | 
					
						
							|  |  |  |                       } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           data: car, | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           createCar: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             data: { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |               id: expect.anything(), | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               attributes: { | 
					
						
							|  |  |  |                 name: car.name, | 
					
						
							|  |  |  |                 person: { | 
					
						
							|  |  |  |                   data: data.people[0], | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               }, | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |       data.cars.push({ id: res.body.data.createCar.data.id }); | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test("Can't list a private oneToMany relation", async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             people { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   name | 
					
						
							|  |  |  |                   privateCars | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(400); | 
					
						
							|  |  |  |       expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |         errors: [ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             message: 'Cannot query field "privateCars" on type "Person".', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Edit person/cars relations removes correctly a car', async () => { | 
					
						
							|  |  |  |       const newPerson = { | 
					
						
							|  |  |  |         name: 'Check Norris Junior', | 
					
						
							|  |  |  |         privateCars: [], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const mutationRes = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           mutation updatePerson($id: ID!, $data: PersonInput!) { | 
					
						
							|  |  |  |             updatePerson(id: $id, data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |                 id | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |           id: data.people[0].id, | 
					
						
							|  |  |  |           data: newPerson, | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |       expect(mutationRes.statusCode).toBe(200); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const queryRes = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |           query ($id: ID!) { | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |             car(id: $id) { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   person { | 
					
						
							|  |  |  |                     data { | 
					
						
							|  |  |  |                       id | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           id: data.cars[0].id, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |       expect(queryRes.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(queryRes.body).toEqual({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           car: { | 
					
						
							| 
									
										
										
										
											2021-09-21 19:38:15 +02:00
										 |  |  |             data: { | 
					
						
							|  |  |  |               attributes: { | 
					
						
							|  |  |  |                 person: { | 
					
						
							|  |  |  |                   data: null, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2020-03-12 10:56:37 +01:00
										 |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2019-03-26 17:59:06 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | }); |