| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 10:32:20 +02:00
										 |  |  | const { createAuthRequest } = require('api-tests/request'); | 
					
						
							|  |  |  | const { createStrapiInstance } = require('api-tests/strapi'); | 
					
						
							|  |  |  | const { createTestBuilder } = require('api-tests/builder'); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | let strapi; | 
					
						
							|  |  |  | let rq; | 
					
						
							|  |  |  | const builder = createTestBuilder(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 15:50:34 +02:00
										 |  |  | const data = { | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |   stamps: [], | 
					
						
							|  |  |  |   collectors: [], | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const stamp = { | 
					
						
							| 
									
										
										
										
											2021-09-13 16:57:04 +02:00
										 |  |  |   displayName: 'stamp', | 
					
						
							|  |  |  |   singularName: 'stamp', | 
					
						
							|  |  |  |   pluralName: 'stamps', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |   kind: 'collectionType', | 
					
						
							|  |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'string', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const collector = { | 
					
						
							| 
									
										
										
										
											2021-09-13 16:57:04 +02:00
										 |  |  |   displayName: 'collector', | 
					
						
							|  |  |  |   singularName: 'collector', | 
					
						
							|  |  |  |   pluralName: 'collectors', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |   kind: 'collectionType', | 
					
						
							|  |  |  |   attributes: { | 
					
						
							|  |  |  |     name: { | 
					
						
							|  |  |  |       type: 'string', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     age: { | 
					
						
							|  |  |  |       type: 'integer', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     stamps: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'oneToMany', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::stamp.stamp', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |     stamps_one_way: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'oneToOne', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::stamp.stamp', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |     stamps_m2m: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'manyToMany', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       targetAttribute: 'collectors', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::stamp.stamp', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |     stamps_one_many: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'oneToMany', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       targetAttribute: 'collector', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::stamp.stamp', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |     stamps_one_one: { | 
					
						
							| 
									
										
										
										
											2021-07-08 18:15:32 +02:00
										 |  |  |       type: 'relation', | 
					
						
							|  |  |  |       relation: 'oneToOne', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       targetAttribute: 'collector_one_one', | 
					
						
							| 
									
										
										
										
											2021-08-06 18:09:49 +02:00
										 |  |  |       target: 'api::stamp.stamp', | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const stampFixtures = [ | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     name: '1946', | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     name: '1947', | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     name: '1948', | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 18:37:23 +09:00
										 |  |  | const collectorFixtures = ({ stamp }) => [ | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |   { | 
					
						
							|  |  |  |     name: 'Bernard', | 
					
						
							|  |  |  |     age: 25, | 
					
						
							|  |  |  |     stamps: [stamp[0].id, stamp[1].id], | 
					
						
							|  |  |  |     stamps_m2m: [stamp[0].id], | 
					
						
							|  |  |  |     stamps_one_many: [], | 
					
						
							|  |  |  |     stamps_one_way: stamp[0].id, | 
					
						
							|  |  |  |     stamps_one_one: stamp[0].id, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     name: 'Isabelle', | 
					
						
							|  |  |  |     age: 55, | 
					
						
							|  |  |  |     stamps: [stamp[0].id], | 
					
						
							|  |  |  |     stamps_m2m: [], | 
					
						
							|  |  |  |     stamps_one_many: [stamp[1].id, stamp[2].id], | 
					
						
							|  |  |  |     stamps_one_way: stamp[1].id, | 
					
						
							|  |  |  |     stamps_one_one: stamp[1].id, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     name: 'Emma', | 
					
						
							|  |  |  |     age: 23, | 
					
						
							|  |  |  |     stamps: [], | 
					
						
							|  |  |  |     stamps_m2m: [stamp[0].id, stamp[1].id], | 
					
						
							|  |  |  |     stamps_one_many: [stamp[0].id], | 
					
						
							|  |  |  |     stamps_one_way: stamp[2].id, | 
					
						
							|  |  |  |     stamps_one_one: stamp[2].id, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  | const getCollectorByName = (collectors, name) => collectors.find((c) => c.name === name); | 
					
						
							|  |  |  | const getStampByName = (stamps, name) => stamps.find((s) => s.name === name); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('CM API', () => { | 
					
						
							| 
									
										
										
										
											2023-01-31 15:38:39 +01:00
										 |  |  |   describe.each([{ populateRelations: false }, { populateRelations: true }])( | 
					
						
							|  |  |  |     `populate relations in webhooks ($populateRelations)`, | 
					
						
							|  |  |  |     ({ populateRelations }) => { | 
					
						
							|  |  |  |       beforeAll(async () => { | 
					
						
							|  |  |  |         await builder | 
					
						
							|  |  |  |           .addContentTypes([stamp, collector]) | 
					
						
							|  |  |  |           .addFixtures(stamp.singularName, stampFixtures) | 
					
						
							|  |  |  |           .addFixtures(collector.singularName, collectorFixtures) | 
					
						
							|  |  |  |           .build(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         strapi = await createStrapiInstance(); | 
					
						
							|  |  |  |         rq = await createAuthRequest({ strapi }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         strapi.config.set('server.webhooks.populateRelations', populateRelations); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         data.collectors = await builder.sanitizedFixturesFor(collector.singularName, strapi); | 
					
						
							|  |  |  |         data.stamps = await builder.sanitizedFixturesFor(stamp.singularName, strapi); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-31 15:38:39 +01:00
										 |  |  |       afterAll(async () => { | 
					
						
							|  |  |  |         await strapi.destroy(); | 
					
						
							|  |  |  |         await builder.cleanup(); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-31 15:38:39 +01:00
										 |  |  |       describe('Automatic count and populate relations', () => { | 
					
						
							|  |  |  |         test('many-way', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'name:ASC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           // all relations are populated and xToMany relations are counted
 | 
					
						
							|  |  |  |           expect(res.body.results).toMatchObject([ | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               age: 25, | 
					
						
							|  |  |  |               createdBy: null, | 
					
						
							|  |  |  |               id: 1, | 
					
						
							|  |  |  |               name: 'Bernard', | 
					
						
							|  |  |  |               stamps: { count: 2 }, | 
					
						
							|  |  |  |               stamps_m2m: { count: 1 }, | 
					
						
							|  |  |  |               stamps_one_many: { count: 0 }, | 
					
						
							|  |  |  |               stamps_one_one: { | 
					
						
							|  |  |  |                 id: 1, | 
					
						
							|  |  |  |                 name: '1946', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               stamps_one_way: { | 
					
						
							|  |  |  |                 id: 1, | 
					
						
							|  |  |  |                 name: '1946', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               updatedBy: null, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               age: 23, | 
					
						
							|  |  |  |               createdBy: null, | 
					
						
							|  |  |  |               id: 3, | 
					
						
							|  |  |  |               name: 'Emma', | 
					
						
							|  |  |  |               stamps: { count: 0 }, | 
					
						
							|  |  |  |               stamps_m2m: { count: 2 }, | 
					
						
							|  |  |  |               stamps_one_many: { count: 1 }, | 
					
						
							|  |  |  |               stamps_one_one: { | 
					
						
							|  |  |  |                 id: 3, | 
					
						
							|  |  |  |                 name: '1948', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               stamps_one_way: { | 
					
						
							|  |  |  |                 id: 3, | 
					
						
							|  |  |  |                 name: '1948', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               updatedBy: null, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |               age: 55, | 
					
						
							|  |  |  |               createdBy: null, | 
					
						
							|  |  |  |               id: 2, | 
					
						
							|  |  |  |               name: 'Isabelle', | 
					
						
							|  |  |  |               stamps: { count: 1 }, | 
					
						
							|  |  |  |               stamps_m2m: { count: 0 }, | 
					
						
							|  |  |  |               stamps_one_many: { count: 2 }, | 
					
						
							|  |  |  |               stamps_one_one: { | 
					
						
							|  |  |  |                 id: 2, | 
					
						
							|  |  |  |                 name: '1947', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               stamps_one_way: { | 
					
						
							|  |  |  |                 id: 2, | 
					
						
							|  |  |  |                 name: '1947', | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |               updatedBy: null, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           ]); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('findOne', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: `/content-manager/collection-types/api::collector.collector/${data.collectors[0].id}`, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(res.body).toMatchObject({ | 
					
						
							|  |  |  |             age: 25, | 
					
						
							|  |  |  |             id: 1, | 
					
						
							|  |  |  |             name: 'Bernard', | 
					
						
							|  |  |  |             stamps: { count: 2 }, | 
					
						
							|  |  |  |             stamps_m2m: { count: 1 }, | 
					
						
							|  |  |  |             stamps_one_many: { count: 0 }, | 
					
						
							|  |  |  |             stamps_one_one: { count: 1 }, | 
					
						
							|  |  |  |             stamps_one_way: { count: 1 }, | 
					
						
							|  |  |  |             createdBy: null, | 
					
						
							|  |  |  |             updatedBy: null, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-31 15:38:39 +01:00
										 |  |  |       describe('Filter relations', () => { | 
					
						
							|  |  |  |         test('many-way', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { stamps: { name: '1946' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(2); | 
					
						
							|  |  |  |           expect(res.body.results[0].name).toBe('Bernard'); | 
					
						
							|  |  |  |           expect(res.body.results[1].name).toBe('Isabelle'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('many-to-many (collector -> stamps)', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { stamps_m2m: { name: '1946' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(2); | 
					
						
							|  |  |  |           expect(getCollectorByName(res.body.results, 'Bernard')).toBeDefined(); | 
					
						
							|  |  |  |           expect(getCollectorByName(res.body.results, 'Emma')).toBeDefined(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('many-to-many (stamp -> collectors)', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::stamp.stamp', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { collectors: { name: 'Emma' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(2); | 
					
						
							|  |  |  |           expect(getStampByName(res.body.results, '1946')).toBeDefined(); | 
					
						
							|  |  |  |           expect(getStampByName(res.body.results, '1947')).toBeDefined(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('one-to-many', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { stamps_one_many: { name: '1947' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(1); | 
					
						
							|  |  |  |           expect(res.body.results[0].name).toBe('Isabelle'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('many-to-one', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::stamp.stamp', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { collector: { name: 'Isabelle' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(2); | 
					
						
							|  |  |  |           expect(getStampByName(res.body.results, '1947')).toBeDefined(); | 
					
						
							|  |  |  |           expect(getStampByName(res.body.results, '1948')).toBeDefined(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('one-way', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { stamps_one_way: { name: '1947' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(1); | 
					
						
							|  |  |  |           expect(getCollectorByName(res.body.results, 'Isabelle')).toBeDefined(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('one-one', async () => { | 
					
						
							|  |  |  |           const res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               filters: { stamps_one_one: { name: '1947' } }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(1); | 
					
						
							|  |  |  |           expect(getCollectorByName(res.body.results, 'Isabelle')).toBeDefined(); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-31 15:38:39 +01:00
										 |  |  |       describe('Sort relations', () => { | 
					
						
							|  |  |  |         test('many-to-one', async () => { | 
					
						
							|  |  |  |           let res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::stamp.stamp', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'collector.name:ASC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(3); | 
					
						
							|  |  |  |           expect(res.body.results[0].collector.name).toBe('Emma'); | 
					
						
							|  |  |  |           expect(res.body.results[1].collector.name).toBe('Isabelle'); | 
					
						
							|  |  |  |           expect(res.body.results[2].collector.name).toBe('Isabelle'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::stamp.stamp', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'collector.name:DESC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(3); | 
					
						
							|  |  |  |           expect(res.body.results[0].collector.name).toBe('Isabelle'); | 
					
						
							|  |  |  |           expect(res.body.results[1].collector.name).toBe('Isabelle'); | 
					
						
							|  |  |  |           expect(res.body.results[2].collector.name).toBe('Emma'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('one-way', async () => { | 
					
						
							|  |  |  |           let res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'stamps_one_way.name:ASC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(3); | 
					
						
							|  |  |  |           expect(res.body.results[0].stamps_one_way.name).toBe('1946'); | 
					
						
							|  |  |  |           expect(res.body.results[1].stamps_one_way.name).toBe('1947'); | 
					
						
							|  |  |  |           expect(res.body.results[2].stamps_one_way.name).toBe('1948'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'stamps_one_way.name:DESC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(3); | 
					
						
							|  |  |  |           expect(res.body.results[0].stamps_one_way.name).toBe('1948'); | 
					
						
							|  |  |  |           expect(res.body.results[1].stamps_one_way.name).toBe('1947'); | 
					
						
							|  |  |  |           expect(res.body.results[2].stamps_one_way.name).toBe('1946'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('one-one', async () => { | 
					
						
							|  |  |  |           let res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'stamps_one_one.name:ASC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(3); | 
					
						
							|  |  |  |           expect(res.body.results[0].stamps_one_one.name).toBe('1946'); | 
					
						
							|  |  |  |           expect(res.body.results[1].stamps_one_one.name).toBe('1947'); | 
					
						
							|  |  |  |           expect(res.body.results[2].stamps_one_one.name).toBe('1948'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           res = await rq({ | 
					
						
							|  |  |  |             method: 'GET', | 
					
						
							|  |  |  |             url: '/content-manager/collection-types/api::collector.collector', | 
					
						
							|  |  |  |             qs: { | 
					
						
							|  |  |  |               sort: 'stamps_one_one.name:DESC', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |           expect(Array.isArray(res.body.results)).toBe(true); | 
					
						
							|  |  |  |           expect(res.body.results).toHaveLength(3); | 
					
						
							|  |  |  |           expect(res.body.results[0].stamps_one_one.name).toBe('1948'); | 
					
						
							|  |  |  |           expect(res.body.results[1].stamps_one_one.name).toBe('1947'); | 
					
						
							|  |  |  |           expect(res.body.results[2].stamps_one_one.name).toBe('1946'); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2023-01-31 15:38:39 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2021-01-11 17:21:01 +01:00
										 |  |  | }); |