| 
									
										
										
										
											2020-11-10 14:15:31 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-29 16:43:53 +01:00
										 |  |  | const path = require('path'); | 
					
						
							| 
									
										
										
										
											2020-11-10 14:15:31 +01:00
										 |  |  | const _ = require('lodash'); | 
					
						
							| 
									
										
										
										
											2021-04-29 11:11:46 +02:00
										 |  |  | const strapi = require('../../packages/core/strapi/lib'); | 
					
						
							| 
									
										
										
										
											2020-12-29 16:43:53 +01:00
										 |  |  | const { createUtils } = require('./utils'); | 
					
						
							| 
									
										
										
										
											2020-11-10 14:15:31 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const superAdminCredentials = { | 
					
						
							|  |  |  |   email: 'admin@strapi.io', | 
					
						
							|  |  |  |   firstname: 'admin', | 
					
						
							|  |  |  |   lastname: 'admin', | 
					
						
							|  |  |  |   password: 'Password123', | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const superAdminLoginInfo = _.pick(superAdminCredentials, ['email', 'password']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const TEST_APP_URL = path.resolve(__dirname, '../../testApp'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-30 20:20:36 +01:00
										 |  |  | const createStrapiInstance = async ({ ensureSuperAdmin = true, logLevel = 'fatal' } = {}) => { | 
					
						
							| 
									
										
										
										
											2020-11-13 16:48:17 +01:00
										 |  |  |   const options = { dir: TEST_APP_URL }; | 
					
						
							|  |  |  |   const instance = strapi(options); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await instance.load(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-25 17:22:41 +01:00
										 |  |  |   instance.log.level = logLevel; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-13 16:48:17 +01:00
										 |  |  |   await instance.app | 
					
						
							|  |  |  |     // Populate Koa routes
 | 
					
						
							|  |  |  |     .use(instance.router.routes()) | 
					
						
							|  |  |  |     // Populate Koa methods
 | 
					
						
							|  |  |  |     .use(instance.router.allowedMethods()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const utils = createUtils(instance); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (ensureSuperAdmin) { | 
					
						
							|  |  |  |     await utils.createUserIfNotExists(superAdminCredentials); | 
					
						
							| 
									
										
										
										
											2020-11-10 14:15:31 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-11-13 16:48:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return instance; | 
					
						
							| 
									
										
										
										
											2020-11-10 14:15:31 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = { | 
					
						
							|  |  |  |   createStrapiInstance, | 
					
						
							|  |  |  |   superAdmin: { | 
					
						
							|  |  |  |     loginInfo: superAdminLoginInfo, | 
					
						
							|  |  |  |     credentials: superAdminCredentials, | 
					
						
							| 
									
										
										
										
											2020-11-13 16:48:17 +01:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-11-10 14:15:31 +01:00
										 |  |  | }; |