| 
									
										
										
										
											2020-10-27 11:27:17 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 10:32:20 +02:00
										 |  |  | const { createStrapiInstance } = require('api-tests/strapi'); | 
					
						
							|  |  |  | const { createRequest, createAuthRequest } = require('api-tests/request'); | 
					
						
							|  |  |  | const { createTestBuilder } = require('api-tests/builder'); | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  | // Test a simple default API with no relations
 | 
					
						
							| 
									
										
										
										
											2024-02-22 17:18:32 +00:00
										 |  |  | describe.skip('Simple Test GraphQL Users API End to End', () => { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |   let strapi; | 
					
						
							|  |  |  |   let rq; | 
					
						
							|  |  |  |   let graphqlQuery; | 
					
						
							|  |  |  |   const user = { | 
					
						
							|  |  |  |     username: 'User 1', | 
					
						
							|  |  |  |     email: 'user1@strapi.io', | 
					
						
							|  |  |  |     password: 'test1234', | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   const data = {}; | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |   beforeAll(async () => { | 
					
						
							|  |  |  |     strapi = await createStrapiInstance(); | 
					
						
							|  |  |  |     rq = await createRequest({ strapi }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     graphqlQuery = (body) => { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |       return rq({ | 
					
						
							|  |  |  |         url: '/graphql', | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   afterAll(async () => { | 
					
						
							|  |  |  |     await strapi.destroy(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('Test register and login', () => { | 
					
						
							|  |  |  |     test('Register a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           mutation register($input: UsersPermissionsRegisterInput!) { | 
					
						
							|  |  |  |             register(input: $input) { | 
					
						
							|  |  |  |               jwt | 
					
						
							|  |  |  |               user { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 email | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           input: user, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           register: { | 
					
						
							|  |  |  |             jwt: expect.any(String), | 
					
						
							|  |  |  |             user: { | 
					
						
							|  |  |  |               id: expect.any(String), | 
					
						
							|  |  |  |               email: user.email, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.user = res.body.data.register.user; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Log in a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           mutation login($input: UsersPermissionsLoginInput!) { | 
					
						
							|  |  |  |             login(input: $input) { | 
					
						
							|  |  |  |               jwt | 
					
						
							|  |  |  |               user { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 email | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           input: { | 
					
						
							|  |  |  |             identifier: user.username, | 
					
						
							|  |  |  |             password: user.password, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           login: { | 
					
						
							|  |  |  |             jwt: expect.any(String), | 
					
						
							|  |  |  |             user: { | 
					
						
							|  |  |  |               id: expect.any(String), | 
					
						
							|  |  |  |               email: user.email, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Use the JWT returned by the login request to
 | 
					
						
							|  |  |  |       // authentify the next queries or mutations
 | 
					
						
							|  |  |  |       rq.setLoggedUser(user).setToken(res.body.data.login.jwt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       data.user = res.body.data.login.user; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Update a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           mutation updateUser($id: ID!, $data: UsersPermissionsUserInput!) { | 
					
						
							|  |  |  |             updateUsersPermissionsUser(id: $id, data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   username | 
					
						
							|  |  |  |                   email | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           id: data.user.id, | 
					
						
							|  |  |  |           data: { username: 'User Test' }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |       const { body } = res; | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           updateUsersPermissionsUser: { | 
					
						
							|  |  |  |             data: { | 
					
						
							|  |  |  |               attributes: { | 
					
						
							|  |  |  |                 username: 'User Test', | 
					
						
							|  |  |  |                 email: data.user.email, | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Delete a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           mutation deleteUser($id: ID!) { | 
					
						
							|  |  |  |             deleteUsersPermissionsUser(id: $id) { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   username | 
					
						
							|  |  |  |                   email | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           id: data.user.id, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           deleteUsersPermissionsUser: { | 
					
						
							|  |  |  |             data: { | 
					
						
							|  |  |  |               attributes: { | 
					
						
							|  |  |  |                 username: 'User Test', | 
					
						
							|  |  |  |                 email: data.user.email, | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Test with attributes such as components, relations..
 | 
					
						
							| 
									
										
										
										
											2024-02-22 17:18:32 +00:00
										 |  |  | describe.skip('Advanced Test GraphQL Users API End to End', () => { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |   const builder = createTestBuilder(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let strapi; | 
					
						
							|  |  |  |   let rq; | 
					
						
							|  |  |  |   let authReq; | 
					
						
							|  |  |  |   let graphqlQuery; | 
					
						
							|  |  |  |   const user = { | 
					
						
							|  |  |  |     username: 'User 2', | 
					
						
							|  |  |  |     email: 'user2@strapi.io', | 
					
						
							|  |  |  |     password: 'test1234', | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   const component = { | 
					
						
							|  |  |  |     displayName: 'somecomponent', | 
					
						
							|  |  |  |     attributes: { | 
					
						
							|  |  |  |       name: { | 
					
						
							|  |  |  |         type: 'string', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       isTesting: { | 
					
						
							|  |  |  |         type: 'boolean', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   const data = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const restart = async () => { | 
					
						
							|  |  |  |     await strapi.destroy(); | 
					
						
							|  |  |  |     strapi = await createStrapiInstance(); | 
					
						
							|  |  |  |     rq = await createAuthRequest({ strapi }); | 
					
						
							|  |  |  |     authReq = await createAuthRequest({ strapi }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     graphqlQuery = (body) => { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |       return rq({ | 
					
						
							|  |  |  |         url: '/graphql', | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |   beforeAll(async () => { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |     await builder.addComponent(component).build(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 20:20:36 +01:00
										 |  |  |     strapi = await createStrapiInstance(); | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |     rq = await createRequest({ strapi }); | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |     authReq = await createAuthRequest({ strapi }); | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     graphqlQuery = (body) => { | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |       return rq({ | 
					
						
							|  |  |  |         url: '/graphql', | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         body, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2021-03-26 20:15:38 +01:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |   afterAll(async () => { | 
					
						
							|  |  |  |     await strapi.destroy(); | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |     await builder.cleanup(); | 
					
						
							| 
									
										
										
										
											2020-11-17 15:38:41 +01:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |   test('Update user to add component attribute', async () => { | 
					
						
							|  |  |  |     const uid = 'plugin::users-permissions.user'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const res = await authReq({ | 
					
						
							|  |  |  |       method: 'PUT', | 
					
						
							|  |  |  |       url: `/content-type-builder/content-types/${uid}`, | 
					
						
							|  |  |  |       body: { | 
					
						
							|  |  |  |         contentType: { | 
					
						
							|  |  |  |           displayName: 'User', | 
					
						
							|  |  |  |           singularName: 'user', | 
					
						
							|  |  |  |           pluralName: 'users', | 
					
						
							|  |  |  |           description: '', | 
					
						
							|  |  |  |           kind: 'collectionType', | 
					
						
							|  |  |  |           collectionName: 'up_users', | 
					
						
							|  |  |  |           attributes: { | 
					
						
							|  |  |  |             username: { | 
					
						
							|  |  |  |               type: 'string', | 
					
						
							|  |  |  |               minLength: 3, | 
					
						
							|  |  |  |               unique: true, | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |               required: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             email: { | 
					
						
							|  |  |  |               type: 'email', | 
					
						
							|  |  |  |               minLength: 6, | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |               required: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             provider: { | 
					
						
							|  |  |  |               type: 'string', | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             password: { | 
					
						
							|  |  |  |               type: 'password', | 
					
						
							|  |  |  |               minLength: 6, | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |               private: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             resetPasswordToken: { | 
					
						
							|  |  |  |               type: 'string', | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |               private: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             confirmationToken: { | 
					
						
							|  |  |  |               type: 'string', | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |               private: true, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             confirmed: { | 
					
						
							|  |  |  |               type: 'boolean', | 
					
						
							|  |  |  |               default: false, | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             blocked: { | 
					
						
							|  |  |  |               type: 'boolean', | 
					
						
							|  |  |  |               default: false, | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             role: { | 
					
						
							|  |  |  |               type: 'relation', | 
					
						
							|  |  |  |               relation: 'manyToOne', | 
					
						
							|  |  |  |               target: 'plugin::users-permissions.role', | 
					
						
							|  |  |  |               inversedBy: 'users', | 
					
						
							|  |  |  |               configurable: false, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             someComponent: { | 
					
						
							|  |  |  |               type: 'component', | 
					
						
							|  |  |  |               repeatable: false, | 
					
						
							|  |  |  |               component: 'default.somecomponent', | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(res.statusCode).toBe(201); | 
					
						
							|  |  |  |     expect(res.body).toEqual({ | 
					
						
							|  |  |  |       data: { | 
					
						
							|  |  |  |         uid, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await restart(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('Test register and login with component', () => { | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |     test('Register a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2020-05-04 13:32:47 -03:00
										 |  |  |           mutation register($input: UsersPermissionsRegisterInput!) { | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |             register(input: $input) { | 
					
						
							|  |  |  |               jwt | 
					
						
							|  |  |  |               user { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 email | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           input: user, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           register: { | 
					
						
							|  |  |  |             jwt: expect.any(String), | 
					
						
							|  |  |  |             user: { | 
					
						
							|  |  |  |               id: expect.any(String), | 
					
						
							|  |  |  |               email: user.email, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |       data.user = res.body.data.register.user; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     test('Log in a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           mutation login($input: UsersPermissionsLoginInput!) { | 
					
						
							|  |  |  |             login(input: $input) { | 
					
						
							|  |  |  |               jwt | 
					
						
							|  |  |  |               user { | 
					
						
							|  |  |  |                 id | 
					
						
							|  |  |  |                 email | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           input: { | 
					
						
							|  |  |  |             identifier: user.username, | 
					
						
							|  |  |  |             password: user.password, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           login: { | 
					
						
							|  |  |  |             jwt: expect.any(String), | 
					
						
							|  |  |  |             user: { | 
					
						
							|  |  |  |               id: expect.any(String), | 
					
						
							|  |  |  |               email: user.email, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Use the JWT returned by the login request to
 | 
					
						
							|  |  |  |       // authentify the next queries or mutations
 | 
					
						
							|  |  |  |       rq.setLoggedUser(user).setToken(res.body.data.login.jwt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |       data.user = res.body.data.login.user; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |     test('Update a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							|  |  |  |           mutation updateUser($id: ID!, $data: UsersPermissionsUserInput!) { | 
					
						
							|  |  |  |             updateUsersPermissionsUser(id: $id, data: $data) { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							|  |  |  |                   username | 
					
						
							|  |  |  |                   email | 
					
						
							|  |  |  |                   someComponent { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     isTesting | 
					
						
							|  |  |  |                   } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							|  |  |  |           id: data.user.id, | 
					
						
							|  |  |  |           data: { | 
					
						
							|  |  |  |             username: 'User Test', | 
					
						
							|  |  |  |             someComponent: { name: 'Changed Name', isTesting: false }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           updateUsersPermissionsUser: { | 
					
						
							|  |  |  |             data: { | 
					
						
							|  |  |  |               attributes: { | 
					
						
							|  |  |  |                 username: 'User Test', | 
					
						
							|  |  |  |                 email: data.user.email, | 
					
						
							|  |  |  |                 someComponent: { | 
					
						
							|  |  |  |                   name: 'Changed Name', | 
					
						
							|  |  |  |                   isTesting: false, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |     test('Delete a user', async () => { | 
					
						
							|  |  |  |       const res = await graphqlQuery({ | 
					
						
							|  |  |  |         query: /* GraphQL */ `
 | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |           mutation deleteUser($id: ID!) { | 
					
						
							|  |  |  |             deleteUsersPermissionsUser(id: $id) { | 
					
						
							|  |  |  |               data { | 
					
						
							|  |  |  |                 attributes { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |                   username | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |                   email | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |                   someComponent { | 
					
						
							|  |  |  |                     name | 
					
						
							|  |  |  |                     isTesting | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |         variables: { | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |           id: data.user.id, | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { body } = res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(body).toMatchObject({ | 
					
						
							|  |  |  |         data: { | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |           deleteUsersPermissionsUser: { | 
					
						
							|  |  |  |             data: { | 
					
						
							|  |  |  |               attributes: { | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |                 username: 'User Test', | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |                 email: data.user.email, | 
					
						
							| 
									
										
										
										
											2022-01-05 23:54:58 +09:00
										 |  |  |                 someComponent: null, | 
					
						
							| 
									
										
										
										
											2021-09-27 17:17:24 +02:00
										 |  |  |               }, | 
					
						
							| 
									
										
										
										
											2019-10-16 00:17:54 +09:00
										 |  |  |             }, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |