mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 18:08:11 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			31 lines
		
	
	
		
			758 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			758 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| 'use strict';
 | |
| 
 | |
| const { createAgent } = require('./agent');
 | |
| const { superAdmin } = require('./strapi');
 | |
| 
 | |
| const createRequest = ({ strapi } = {}) => createAgent(strapi);
 | |
| 
 | |
| const createContentAPIRequest = ({ strapi } = {}) => {
 | |
|   return createAgent(strapi, { urlPrefix: '/api', token: 'test-token' });
 | |
| };
 | |
| 
 | |
| const createAuthRequest = ({ strapi, userInfo = superAdmin.credentials }) => {
 | |
|   return createAgent(strapi).login(userInfo);
 | |
| };
 | |
| 
 | |
| const transformToRESTResource = input => {
 | |
|   if (Array.isArray(input)) {
 | |
|     return input.map(value => transformToRESTResource(value));
 | |
|   }
 | |
| 
 | |
|   const { id, ...attributes } = input;
 | |
|   return { id, attributes };
 | |
| };
 | |
| 
 | |
| module.exports = {
 | |
|   createRequest,
 | |
|   createContentAPIRequest,
 | |
|   createAuthRequest,
 | |
|   transformToRESTResource,
 | |
| };
 | 
