mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Update request helper
This commit is contained in:
		
							parent
							
								
									7e5b859575
								
							
						
					
					
						commit
						208319b8a2
					
				@ -1,7 +1,7 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
  name: 'setup',
 | 
			
		||||
  displayName: 'Setup',
 | 
			
		||||
  testMatch: ['test/?(*.)+(test).js'],
 | 
			
		||||
  testMatch: ['**/test/?(*.)+(spec|test).js'],
 | 
			
		||||
  testPathIgnorePatterns: [
 | 
			
		||||
    '<rootDir>/packages/',
 | 
			
		||||
  ],
 | 
			
		||||
 | 
			
		||||
@ -1 +0,0 @@
 | 
			
		||||
{}
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
  name: 'content-manager',
 | 
			
		||||
  displayName: 'Content Manager',
 | 
			
		||||
  testMatch: ['test/?(*.)+(test).js'],
 | 
			
		||||
  testMatch: ['**/test/?(*.)+(spec|test).js'],
 | 
			
		||||
  coveragePathIgnorePatterns: [
 | 
			
		||||
    '<rootDir>/admin/',
 | 
			
		||||
    '<rootDir>/dist/',
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,7 @@
 | 
			
		||||
let request = require('request');
 | 
			
		||||
 | 
			
		||||
request = request.defaults({
 | 
			
		||||
  baseUrl: 'http://localhost:1337'
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
// Helpers.
 | 
			
		||||
const form = require('../../../test/helpers/generators');
 | 
			
		||||
const restart = require('../../../test/helpers/restart');
 | 
			
		||||
const rq = require('../../../test/helpers/request')(request);
 | 
			
		||||
const rq = require('../../../test/helpers/request');
 | 
			
		||||
 | 
			
		||||
const cleanDate = (entry) => {
 | 
			
		||||
  delete entry.updatedAt;
 | 
			
		||||
@ -32,7 +27,7 @@ describe('App setup auth', () => {
 | 
			
		||||
        json: true
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      request = request.defaults({
 | 
			
		||||
      rq.defaults({
 | 
			
		||||
        headers: {
 | 
			
		||||
          'Authorization': `Bearer ${body.jwt}`
 | 
			
		||||
        }
 | 
			
		||||
@ -320,6 +315,39 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () =>
 | 
			
		||||
      expect(body.tags.length).toBe(0);
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
 | 
			
		||||
  test(
 | 
			
		||||
    'Delete all tags should remove the association in each articles related to them',
 | 
			
		||||
    async () => {
 | 
			
		||||
      const tagsToCreate = ['tag11, tag12'].map(tag => 
 | 
			
		||||
        rq({
 | 
			
		||||
          url: `/content-manager/explorer/tag/?source=content-manager`,
 | 
			
		||||
          method: 'POST',
 | 
			
		||||
          json: true,
 | 
			
		||||
          formData: {
 | 
			
		||||
            name: tag
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      const tags = await Promise.all(tagsToCreate);
 | 
			
		||||
 | 
			
		||||
      console.log(tags);
 | 
			
		||||
 | 
			
		||||
      const article = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/?source=content-manager`,
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        json: true,
 | 
			
		||||
        formData: {
 | 
			
		||||
          title: 'Article 12',
 | 
			
		||||
          content: 'Content',
 | 
			
		||||
          tags: [tags[0]]
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(article.tags[0].id).toBe(tags[0].id);
 | 
			
		||||
    }
 | 
			
		||||
  );
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
 | 
			
		||||
 | 
			
		||||
@ -4,22 +4,26 @@ request = request.defaults({
 | 
			
		||||
  baseUrl: 'http://localhost:1337'
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
module.exports = (request) => (options) => {
 | 
			
		||||
    const params = JSON.parse(JSON.stringify(options));
 | 
			
		||||
module.exports = function (options) {
 | 
			
		||||
  const params = JSON.parse(JSON.stringify(options));
 | 
			
		||||
 | 
			
		||||
    for (let key in params.formData) {
 | 
			
		||||
      if (typeof params.formData[key] === 'object') {
 | 
			
		||||
        params.formData[key] = JSON.stringify(params.formData[key]);
 | 
			
		||||
      }
 | 
			
		||||
  for (let key in params.formData) {
 | 
			
		||||
    if (typeof params.formData[key] === 'object') {
 | 
			
		||||
      params.formData[key] = JSON.stringify(params.formData[key]);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      request(params, (err, res, body) => {
 | 
			
		||||
        if (err || res.statusCode < 200 || res.statusCode >= 300) {
 | 
			
		||||
          return reject(err || body);
 | 
			
		||||
        }
 | 
			
		||||
  return new Promise((resolve, reject) => {
 | 
			
		||||
    request(params, (err, res, body) => {
 | 
			
		||||
      if (err || res.statusCode < 200 || res.statusCode >= 300) {
 | 
			
		||||
        return reject(err || body);
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
        return resolve(body);
 | 
			
		||||
      });
 | 
			
		||||
      return resolve(body);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports.defaults = function (options) {
 | 
			
		||||
  request = request.defaults(options);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -101,8 +101,8 @@ const main = async () => {
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  await testProcess(databases.mongo);
 | 
			
		||||
  await testProcess(databases.postgres);
 | 
			
		||||
  await testProcess(databases.mysql);
 | 
			
		||||
  // await testProcess(databases.postgres);
 | 
			
		||||
  // await testProcess(databases.mysql);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
main();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user