mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-04 03:43:34 +00:00 
			
		
		
		
	Restructure tests
This commit is contained in:
		
							parent
							
								
									f4b5a487d1
								
							
						
					
					
						commit
						96b023d16b
					
				@ -1,9 +1,9 @@
 | 
			
		||||
module.exports = {
 | 
			
		||||
  name: 'setup',
 | 
			
		||||
  displayName: 'Setup',
 | 
			
		||||
  testMatch: ['**/test/?(*.)+(spec|test).js'],
 | 
			
		||||
  testMatch: ['**/test/?(*.)+(spec|test).e2e.js'],
 | 
			
		||||
  testEnvironment: 'node',
 | 
			
		||||
  globalSetup: '<rootDir>/test/globalSetup.js',
 | 
			
		||||
  // globalSetup: '<rootDir>/test/globalSetup.js',
 | 
			
		||||
  coveragePathIgnorePatterns: [
 | 
			
		||||
    '<rootDir>/dist/',
 | 
			
		||||
    '<rootDir>/node_modules/',
 | 
			
		||||
 | 
			
		||||
@ -42,7 +42,7 @@
 | 
			
		||||
    "test": "snyk test && node ./test/start.js",
 | 
			
		||||
    "prettier": "node ./packages/strapi-lint/lib/internals/prettier/index.js",
 | 
			
		||||
    "snyk": "node ./scripts/snyk.js",
 | 
			
		||||
    "test:e2e": "jest --config jest.config.e2e.js --runInBand --verbose --forceExit packages/strapi-generate-api"
 | 
			
		||||
    "test:e2e": "jest --config jest.config.e2e.js --runInBand --verbose --forceExit --detectOpenHandles --no-cache"
 | 
			
		||||
  },
 | 
			
		||||
  "author": {
 | 
			
		||||
    "email": "hi@strapi.io",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										720
									
								
								packages/strapi-generate-api/test/endpoint.test.e2e.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										720
									
								
								packages/strapi-generate-api/test/endpoint.test.e2e.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,720 @@
 | 
			
		||||
// Helpers.
 | 
			
		||||
const { auth, login } = require('../../../test/helpers/auth');
 | 
			
		||||
const form = require('../../../test/helpers/generators');
 | 
			
		||||
const restart = require('../../../test/helpers/restart');
 | 
			
		||||
const createRequest = require('../../../test/helpers/request');
 | 
			
		||||
 | 
			
		||||
const cleanDate = entry => {
 | 
			
		||||
  delete entry.updatedAt;
 | 
			
		||||
  delete entry.createdAt;
 | 
			
		||||
  delete entry.created_at;
 | 
			
		||||
  delete entry.updated_at;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
let data;
 | 
			
		||||
let rq;
 | 
			
		||||
jest.setTimeout(30000);
 | 
			
		||||
 | 
			
		||||
describe('Create Strapi API End to End', () => {
 | 
			
		||||
  beforeAll(async () => {
 | 
			
		||||
    await createRequest()({
 | 
			
		||||
      url: '/auth/local/register',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: auth,
 | 
			
		||||
    }).catch(() => {});
 | 
			
		||||
 | 
			
		||||
    const body = await login();
 | 
			
		||||
 | 
			
		||||
    rq = createRequest({
 | 
			
		||||
      headers: {
 | 
			
		||||
        Authorization: `Bearer ${body.jwt}`,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  afterAll(() => new Promise(resolve, setTimeout(resolve, 5000)));
 | 
			
		||||
 | 
			
		||||
  describe('Generate test APIs', () => {
 | 
			
		||||
    beforeEach(() => restart(), 60000);
 | 
			
		||||
 | 
			
		||||
    test('Create new article API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.article,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new tag API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.tag,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new category API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.category,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new reference API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.reference,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new product API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.product,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test manyToMany relation (article - tag) with Content Manager', () => {
 | 
			
		||||
    beforeAll(async () => {
 | 
			
		||||
      await restart();
 | 
			
		||||
 | 
			
		||||
      data = {
 | 
			
		||||
        articles: [],
 | 
			
		||||
        tags: [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create tag1', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/tags',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'tag1',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('tag1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create tag2', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/tags',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'tag2',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('tag2');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create tag3', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/tags',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'tag3',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('tag3');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article1 without relation', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 1',
 | 
			
		||||
        content: 'My super content 1',
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/articles',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article2 with tag1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 2',
 | 
			
		||||
        content: 'Content 2',
 | 
			
		||||
        tags: [data.tags[0]],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/articles',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(1);
 | 
			
		||||
      expect(body.tags[0].id).toBe(data.tags[0].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 add tag2', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        tags: [data.tags[1]],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(1);
 | 
			
		||||
      expect(body.tags[0].id).toBe(data.tags[1].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 add tag1 and tag3', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
      entry.tags.push(data.tags[0]);
 | 
			
		||||
      entry.tags.push(data.tags[2]);
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(3);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 remove one tag', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
      entry.tags = entry.tags.slice(1);
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(2);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 remove all tag', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        tags: [],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
 | 
			
		||||
    beforeAll(() => {
 | 
			
		||||
      data = {
 | 
			
		||||
        articles: [],
 | 
			
		||||
        categories: [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create cat1', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/categories',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'cat1',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('cat1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create cat2', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/categories',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'cat2',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('cat2');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article1 with cat1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 1',
 | 
			
		||||
        content: 'Content 1',
 | 
			
		||||
        category: data.categories[0],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/articles',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 with cat2', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        category: data.categories[1],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article2', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 2',
 | 
			
		||||
        content: 'Content 2',
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/articles',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article2 with cat2', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[1], {
 | 
			
		||||
        category: data.categories[1],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[1] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update cat1 with article1', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.categories[0]);
 | 
			
		||||
      entry.articles.push(data.articles[0]);
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/categories/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.name).toBe(entry.name);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create cat3 with article1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        name: 'cat3',
 | 
			
		||||
        articles: [data.articles[0]],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/categories',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.name).toBe(entry.name);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get article1 with cat3', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${data.articles[0].id}`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.category.id).toBe(data.categories[2].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get article2 with cat2', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${data.articles[1].id}`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.category.id).toBe(data.categories[1].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get cat1 without relations', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/categories/${data.categories[0].id}`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.articles.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get cat2 with article2', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/categories/${data.categories[1].id}`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.articles[0].id).toBe(data.articles[1].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get cat3 with article1', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/categories/${data.categories[2].id}`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.articles[0].id).toBe(data.articles[0].id);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test oneToOne relation (article - reference) with Content Manager', () => {
 | 
			
		||||
    beforeAll(() => {
 | 
			
		||||
      data = {
 | 
			
		||||
        articles: [],
 | 
			
		||||
        references: [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create ref1', async () => {
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/references',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'ref1',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.references.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.name).toBe('ref1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 1',
 | 
			
		||||
        content: 'Content 1',
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/articles',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 with ref1', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        reference: data.references[0].id,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: `/articles/${entry.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article2 with ref1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 2',
 | 
			
		||||
        content: 'Content 2',
 | 
			
		||||
        reference: data.references[0].id,
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      const { body } = await rq({
 | 
			
		||||
        url: '/articles',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test oneWay relation (reference - tag) with Content Manager', () => {
 | 
			
		||||
    test('Attach Tag to a Reference', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/tags',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'tag111',
 | 
			
		||||
        },
 | 
			
		||||
      }).then(({ body: tagToCreate }) => {
 | 
			
		||||
        return rq({
 | 
			
		||||
          url: '/references',
 | 
			
		||||
          method: 'POST',
 | 
			
		||||
          body: {
 | 
			
		||||
            name: 'cat111',
 | 
			
		||||
            tag: tagToCreate,
 | 
			
		||||
          },
 | 
			
		||||
        }).then(({ body }) => {
 | 
			
		||||
          expect(body.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Detach Tag to a Reference', async () => {
 | 
			
		||||
      const { body: tagToCreate } = await rq({
 | 
			
		||||
        url: '/tags',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'tag111',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToCreate } = await rq({
 | 
			
		||||
        url: '/references',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'cat111',
 | 
			
		||||
          tag: tagToCreate,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToUpdate } = await rq({
 | 
			
		||||
        url: `/references/${referenceToCreate.id}`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        body: {
 | 
			
		||||
          tag: null,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(referenceToUpdate.tag).toBe(null);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete Tag so the relation in the Reference side should be removed', async () => {
 | 
			
		||||
      const { body: tagToCreate } = await rq({
 | 
			
		||||
        url: '/tags',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'tag111',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToCreate } = await rq({
 | 
			
		||||
        url: '/references',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'cat111',
 | 
			
		||||
          tag: tagToCreate,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: `/tags/${tagToCreate.id}`,
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToGet } = await rq({
 | 
			
		||||
        url: `/references/${referenceToCreate.id}`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      if (Object.keys(referenceToGet.tag).length == 0) return;
 | 
			
		||||
      expect(referenceToGet.tag).toBe(null);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Delete test APIs', () => {
 | 
			
		||||
    beforeEach(() => restart(), 60000);
 | 
			
		||||
 | 
			
		||||
    test('Delete article API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/article',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete tag API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/tag',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete category API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/category',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete reference API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/reference',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete product API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/product',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -1,712 +0,0 @@
 | 
			
		||||
// Helpers.
 | 
			
		||||
const { login } = require('../../../test/helpers/auth');
 | 
			
		||||
const form = require('../../../test/helpers/generators');
 | 
			
		||||
const restart = require('../../../test/helpers/restart');
 | 
			
		||||
const createRequest = require('../../../test/helpers/request');
 | 
			
		||||
 | 
			
		||||
const cleanDate = entry => {
 | 
			
		||||
  delete entry.updatedAt;
 | 
			
		||||
  delete entry.createdAt;
 | 
			
		||||
  delete entry.created_at;
 | 
			
		||||
  delete entry.updated_at;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
let data;
 | 
			
		||||
 | 
			
		||||
let rq;
 | 
			
		||||
 | 
			
		||||
jest.setTimeout(30000);
 | 
			
		||||
 | 
			
		||||
beforeAll(async () => {
 | 
			
		||||
  const body = await login();
 | 
			
		||||
 | 
			
		||||
  rq = createRequest({
 | 
			
		||||
    headers: {
 | 
			
		||||
      Authorization: `Bearer ${body.jwt}`,
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Generate test APIs', () => {
 | 
			
		||||
  beforeEach(() => restart(), 60000);
 | 
			
		||||
 | 
			
		||||
  test('Create new article API', () => {
 | 
			
		||||
    return rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.article,
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create new tag API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.tag,
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create new category API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.category,
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create new reference API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.reference,
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create new product API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.product,
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
 | 
			
		||||
  beforeAll(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
 | 
			
		||||
    data = {
 | 
			
		||||
      articles: [],
 | 
			
		||||
      tags: [],
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create tag1', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/tags',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'tag1',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('tag1');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create tag2', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/tags',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'tag2',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('tag2');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create tag3', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/tags',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'tag3',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('tag3');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create article1 without relation', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 1',
 | 
			
		||||
      content: 'My super content 1',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/articles',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create article2 with tag1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 2',
 | 
			
		||||
      content: 'Content 2',
 | 
			
		||||
      tags: [data.tags[0]],
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/articles',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(1);
 | 
			
		||||
    expect(body.tags[0].id).toBe(data.tags[0].id);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article1 add tag2', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      tags: [data.tags[1]],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(1);
 | 
			
		||||
    expect(body.tags[0].id).toBe(data.tags[1].id);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article1 add tag1 and tag3', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
    entry.tags.push(data.tags[0]);
 | 
			
		||||
    entry.tags.push(data.tags[2]);
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(3);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article1 remove one tag', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
    entry.tags = entry.tags.slice(1);
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(2);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article1 remove all tag', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      tags: [],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
 | 
			
		||||
  beforeAll(() => {
 | 
			
		||||
    data = {
 | 
			
		||||
      articles: [],
 | 
			
		||||
      categories: [],
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create cat1', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/categories',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'cat1',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('cat1');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create cat2', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/categories',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'cat2',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('cat2');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create article1 with cat1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 1',
 | 
			
		||||
      content: 'Content 1',
 | 
			
		||||
      category: data.categories[0],
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/articles',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article1 with cat2', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      category: data.categories[1],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create article2', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 2',
 | 
			
		||||
      content: 'Content 2',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/articles',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article2 with cat2', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[1], {
 | 
			
		||||
      category: data.categories[1],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[1] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update cat1 with article1', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.categories[0]);
 | 
			
		||||
    entry.articles.push(data.articles[0]);
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/categories/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.categories[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.name).toBe(entry.name);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create cat3 with article1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      name: 'cat3',
 | 
			
		||||
      articles: [data.articles[0]],
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/categories',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.name).toBe(entry.name);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Get article1 with cat3', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${data.articles[0].id}`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.category.id).toBe(data.categories[2].id);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Get article2 with cat2', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${data.articles[1].id}`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.category.id).toBe(data.categories[1].id);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Get cat1 without relations', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/categories/${data.categories[0].id}`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.articles.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Get cat2 with article2', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/categories/${data.categories[1].id}`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.articles[0].id).toBe(data.articles[1].id);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Get cat3 with article1', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/categories/${data.categories[2].id}`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.articles[0].id).toBe(data.articles[0].id);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneToOne relation (article - reference) with Content Manager', () => {
 | 
			
		||||
  beforeAll(() => {
 | 
			
		||||
    data = {
 | 
			
		||||
      articles: [],
 | 
			
		||||
      references: [],
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create ref1', async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/references',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'ref1',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.references.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.name).toBe('ref1');
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create article1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 1',
 | 
			
		||||
      content: 'Content 1',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/articles',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Update article1 with ref1', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      reference: data.references[0].id,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: `/articles/${entry.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Create article2 with ref1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 2',
 | 
			
		||||
      content: 'Content 2',
 | 
			
		||||
      reference: data.references[0].id,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/articles',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneWay relation (reference - tag) with Content Manager', () => {
 | 
			
		||||
  test('Attach Tag to a Reference', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/tags',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'tag111',
 | 
			
		||||
      },
 | 
			
		||||
    }).then(({ body: tagToCreate }) => {
 | 
			
		||||
      return rq({
 | 
			
		||||
        url: '/references',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          name: 'cat111',
 | 
			
		||||
          tag: tagToCreate,
 | 
			
		||||
        },
 | 
			
		||||
      }).then(({ body }) => {
 | 
			
		||||
        expect(body.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Detach Tag to a Reference', async () => {
 | 
			
		||||
    const { body: tagToCreate } = await rq({
 | 
			
		||||
      url: '/tags',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'tag111',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const { body: referenceToCreate } = await rq({
 | 
			
		||||
      url: '/references',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'cat111',
 | 
			
		||||
        tag: tagToCreate,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
 | 
			
		||||
    const { body: referenceToUpdate } = await rq({
 | 
			
		||||
      url: `/references/${referenceToCreate.id}`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      body: {
 | 
			
		||||
        tag: null,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(referenceToUpdate.tag).toBe(null);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete Tag so the relation in the Reference side should be removed', async () => {
 | 
			
		||||
    const { body: tagToCreate } = await rq({
 | 
			
		||||
      url: '/tags',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'tag111',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const { body: referenceToCreate } = await rq({
 | 
			
		||||
      url: '/references',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        name: 'cat111',
 | 
			
		||||
        tag: tagToCreate,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: `/tags/${tagToCreate.id}`,
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const { body: referenceToGet } = await rq({
 | 
			
		||||
      url: `/references/${referenceToCreate.id}`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (Object.keys(referenceToGet.tag).length == 0) return;
 | 
			
		||||
    expect(referenceToGet.tag).toBe(null);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Delete test APIs', () => {
 | 
			
		||||
  beforeEach(() => restart(), 60000);
 | 
			
		||||
 | 
			
		||||
  test('Delete article API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/article',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete tag API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/tag',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete category API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/category',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete reference API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/reference',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete product API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/product',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
    }).then(res => {
 | 
			
		||||
      expect(res.statusCode).toBe(200);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										771
									
								
								packages/strapi-plugin-content-manager/test/index.test.e2e.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										771
									
								
								packages/strapi-plugin-content-manager/test/index.test.e2e.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,771 @@
 | 
			
		||||
// Helpers.
 | 
			
		||||
const { auth, login } = require('../../../test/helpers/auth');
 | 
			
		||||
const form = require('../../../test/helpers/generators');
 | 
			
		||||
const restart = require('../../../test/helpers/restart');
 | 
			
		||||
const createRequest = require('../../../test/helpers/request');
 | 
			
		||||
 | 
			
		||||
const cleanDate = entry => {
 | 
			
		||||
  delete entry.updatedAt;
 | 
			
		||||
  delete entry.createdAt;
 | 
			
		||||
  delete entry.created_at;
 | 
			
		||||
  delete entry.updated_at;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
let data;
 | 
			
		||||
 | 
			
		||||
let rq;
 | 
			
		||||
jest.setTimeout(30000);
 | 
			
		||||
 | 
			
		||||
describe('Content Manager End to End', () => {
 | 
			
		||||
  beforeAll(async () => {
 | 
			
		||||
    await createRequest()({
 | 
			
		||||
      url: '/auth/local/register',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: auth,
 | 
			
		||||
    }).catch(() => {});
 | 
			
		||||
 | 
			
		||||
    const body = await login();
 | 
			
		||||
 | 
			
		||||
    rq = createRequest({
 | 
			
		||||
      headers: {
 | 
			
		||||
        Authorization: `Bearer ${body.jwt}`,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  afterAll(() => new Promise(resolve, setTimeout(resolve, 5000)));
 | 
			
		||||
 | 
			
		||||
  describe('Generate test APIs', () => {
 | 
			
		||||
    beforeEach(() => restart(), 60000);
 | 
			
		||||
 | 
			
		||||
    test('Create new article API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.article,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new tag API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.tag,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new category API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.category,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new reference API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.reference,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create new product API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: form.product,
 | 
			
		||||
      }).then(res => {
 | 
			
		||||
        expect(res.statusCode).toBe(200);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test manyToMany relation (article - tag) with Content Manager', () => {
 | 
			
		||||
    beforeAll(async () => {
 | 
			
		||||
      await restart();
 | 
			
		||||
 | 
			
		||||
      data = {
 | 
			
		||||
        articles: [],
 | 
			
		||||
        tags: [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create tag1', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag1',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('tag1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create tag2', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag2',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('tag2');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create tag3', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag3',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('tag3');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article1 without relation', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 1',
 | 
			
		||||
        content: 'My super content 1',
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article2 with tag1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 2',
 | 
			
		||||
        content: 'Content 2',
 | 
			
		||||
        tags: [data.tags[0]],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(1);
 | 
			
		||||
      expect(body.tags[0].id).toBe(data.tags[0].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 add tag2', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        tags: [data.tags[1]],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(1);
 | 
			
		||||
      expect(body.tags[0].id).toBe(data.tags[1].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 add tag1 and tag3', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
      entry.tags.push(data.tags[0]);
 | 
			
		||||
      entry.tags.push(data.tags[2]);
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(3);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 remove one tag', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
      entry.tags = entry.tags.slice(1);
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(2);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 remove all tag', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        tags: [],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
      expect(body.tags.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete all articles should remove the association in each tags related to them', async () => {
 | 
			
		||||
      const { body: tagToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag11',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: article12 } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          title: 'article12',
 | 
			
		||||
          content: 'Content',
 | 
			
		||||
          tags: [tagToCreate],
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: article13 } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          title: 'article13',
 | 
			
		||||
          content: 'Content',
 | 
			
		||||
          tags: [tagToCreate],
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const articles = [article12, article13];
 | 
			
		||||
 | 
			
		||||
      expect(Array.isArray(articles[0].tags)).toBeTruthy();
 | 
			
		||||
      expect(articles[0].tags.length).toBe(1);
 | 
			
		||||
      expect(Array.isArray(articles[1].tags)).toBeTruthy();
 | 
			
		||||
      expect(articles[1].tags.length).toBe(1);
 | 
			
		||||
 | 
			
		||||
      let { body: tagToGet } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(Array.isArray(tagToGet.articles)).toBeTruthy();
 | 
			
		||||
      expect(tagToGet.articles.length).toBe(2);
 | 
			
		||||
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: `/content-manager/explorer/deleteAll/article/?source=content-manager&${articles
 | 
			
		||||
          .map((article, index) => `${index}=${article.id}`)
 | 
			
		||||
          .join('&')}`,
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      let { body: tagToGet2 } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(Array.isArray(tagToGet2.articles)).toBeTruthy();
 | 
			
		||||
      expect(tagToGet2.articles.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
 | 
			
		||||
    beforeAll(() => {
 | 
			
		||||
      data = {
 | 
			
		||||
        articles: [],
 | 
			
		||||
        categories: [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create cat1', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/category/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'cat1',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('cat1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create cat2', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/category/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'cat2',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.name).toBe('cat2');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article1 with cat1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 1',
 | 
			
		||||
        content: 'Content 1',
 | 
			
		||||
        category: data.categories[0],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 with cat2', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        category: data.categories[1],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article2', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 2',
 | 
			
		||||
        content: 'Content 2',
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article2 with cat2', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[1], {
 | 
			
		||||
        category: data.categories[1],
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[1] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
      expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update cat1 with article1', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.categories[0]);
 | 
			
		||||
      entry.articles.push(data.articles[0]);
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/category/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.name).toBe(entry.name);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create cat3 with article1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        name: 'cat3',
 | 
			
		||||
        articles: [data.articles[0]],
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/category/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.name).toBe(entry.name);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get article1 with cat3', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${data.articles[0].id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.category.id).toBe(data.categories[2].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get article2 with cat2', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${data.articles[1].id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.category.id).toBe(data.categories[1].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get cat1 without relations', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/category/${data.categories[0].id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.articles.length).toBe(0);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get cat2 with article2', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/category/${data.categories[1].id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.articles[0].id).toBe(data.articles[1].id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Get cat3 with article1', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/category/${data.categories[2].id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.articles.length).toBe(1);
 | 
			
		||||
      expect(body.articles[0].id).toBe(data.articles[0].id);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test oneToOne relation (article - reference) with Content Manager', () => {
 | 
			
		||||
    beforeAll(() => {
 | 
			
		||||
      data = {
 | 
			
		||||
        articles: [],
 | 
			
		||||
        references: [],
 | 
			
		||||
      };
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create ref1', async () => {
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'ref1',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.references.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.name).toBe('ref1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 1',
 | 
			
		||||
        content: 'Content 1',
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Update article1 with ref1', async () => {
 | 
			
		||||
      const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
        reference: data.references[0].id,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Create article2 with ref1', async () => {
 | 
			
		||||
      const entry = {
 | 
			
		||||
        title: 'Article 2',
 | 
			
		||||
        content: 'Content 2',
 | 
			
		||||
        reference: data.references[0].id,
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
      let { body } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/article?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: entry,
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
      expect(body.id);
 | 
			
		||||
      expect(body.title).toBe(entry.title);
 | 
			
		||||
      expect(body.content).toBe(entry.content);
 | 
			
		||||
      expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Test oneWay relation (reference - tag) with Content Manager', () => {
 | 
			
		||||
    test('Attach Tag to a Reference', async () => {
 | 
			
		||||
      const { body: tagToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag111',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'cat111',
 | 
			
		||||
          tag: tagToCreate,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Detach Tag to a Reference', async () => {
 | 
			
		||||
      const { body: tagToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag111',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'cat111',
 | 
			
		||||
          tag: tagToCreate,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToUpdate } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/reference/${referenceToCreate.id}?source=content-manager`,
 | 
			
		||||
        method: 'PUT',
 | 
			
		||||
        formData: {
 | 
			
		||||
          tag: null,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(referenceToUpdate.tag).toBe(null);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete Tag so the relation in the Reference side should be removed', async () => {
 | 
			
		||||
      const { body: tagToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'tag111',
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToCreate } = await rq({
 | 
			
		||||
        url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        formData: {
 | 
			
		||||
          name: 'cat111',
 | 
			
		||||
          tag: tagToCreate,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`,
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      const { body: referenceToGet } = await rq({
 | 
			
		||||
        url: `/content-manager/explorer/reference/${referenceToCreate.id}?source=content-manager`,
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      if (Object.keys(referenceToGet.tag).length == 0) return;
 | 
			
		||||
      expect(referenceToGet.tag).toBe(null);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('Delete test APIs', () => {
 | 
			
		||||
    beforeEach(() => restart(), 60000);
 | 
			
		||||
 | 
			
		||||
    test('Delete article API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/article',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete tag API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/tag',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete category API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/category',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete reference API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/reference',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('Delete product API', async () => {
 | 
			
		||||
      await rq({
 | 
			
		||||
        url: '/content-type-builder/models/product',
 | 
			
		||||
        method: 'DELETE',
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -1,824 +0,0 @@
 | 
			
		||||
// Helpers.
 | 
			
		||||
const { login } = require('../../../test/helpers/auth');
 | 
			
		||||
const form = require('../../../test/helpers/generators');
 | 
			
		||||
const restart = require('../../../test/helpers/restart');
 | 
			
		||||
const rq = require('../../../test/helpers/request');
 | 
			
		||||
 | 
			
		||||
const cleanDate = entry => {
 | 
			
		||||
  delete entry.updatedAt;
 | 
			
		||||
  delete entry.createdAt;
 | 
			
		||||
  delete entry.created_at;
 | 
			
		||||
  delete entry.updated_at;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
let data;
 | 
			
		||||
 | 
			
		||||
beforeAll(async () => {
 | 
			
		||||
  const body = await login();
 | 
			
		||||
 | 
			
		||||
  rq.defaults({
 | 
			
		||||
    headers: {
 | 
			
		||||
      Authorization: `Bearer ${body.jwt}`,
 | 
			
		||||
    },
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Generate test APIs', () => {
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
    await new Promise(resolve => setTimeout(resolve, 1000));
 | 
			
		||||
  }, 60000);
 | 
			
		||||
 | 
			
		||||
  test('Create new article API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.article,
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Create new tag API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.tag,
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Create new category API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.category,
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Create new reference API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.reference,
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Create new product API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: form.product,
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
 | 
			
		||||
  beforeAll(() => {
 | 
			
		||||
    data = {
 | 
			
		||||
      articles: [],
 | 
			
		||||
      tags: [],
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
    await new Promise(resolve => setTimeout(resolve, 1000));
 | 
			
		||||
  }, 60000);
 | 
			
		||||
 | 
			
		||||
  test('Create tag1', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag1',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('tag1');
 | 
			
		||||
  });
 | 
			
		||||
  test('Create tag2', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag2',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('tag2');
 | 
			
		||||
  });
 | 
			
		||||
  test('Create tag3', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag3',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.tags.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('tag3');
 | 
			
		||||
  });
 | 
			
		||||
  test('Create article1 without relation', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 1',
 | 
			
		||||
      content: 'My super content 1',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
  test('Create article2 with tag1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 2',
 | 
			
		||||
      content: 'Content 2',
 | 
			
		||||
      tags: [data.tags[0]],
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(1);
 | 
			
		||||
    expect(body.tags[0].id).toBe(data.tags[0].id);
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article1 add tag2', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      tags: [data.tags[1]],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(1);
 | 
			
		||||
    expect(body.tags[0].id).toBe(data.tags[1].id);
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article1 add tag1 and tag3', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
    entry.tags.push(data.tags[0]);
 | 
			
		||||
    entry.tags.push(data.tags[2]);
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(3);
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article1 remove one tag', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0]);
 | 
			
		||||
    entry.tags = entry.tags.slice(1);
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(2);
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article1 remove all tag', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      tags: [],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
    expect(body.tags.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete all articles should remove the association in each tags related to them', async () => {
 | 
			
		||||
    const tagToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag11',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const article12 = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        title: 'article12',
 | 
			
		||||
        content: 'Content',
 | 
			
		||||
        tags: [tagToCreate],
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const article13 = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        title: 'article13',
 | 
			
		||||
        content: 'Content',
 | 
			
		||||
        tags: [tagToCreate],
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const articles = [article12, article13];
 | 
			
		||||
 | 
			
		||||
    expect(Array.isArray(articles[0].tags)).toBeTruthy();
 | 
			
		||||
    expect(articles[0].tags.length).toBe(1);
 | 
			
		||||
    expect(Array.isArray(articles[1].tags)).toBeTruthy();
 | 
			
		||||
    expect(articles[1].tags.length).toBe(1);
 | 
			
		||||
 | 
			
		||||
    let tagToGet = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(Array.isArray(tagToGet.articles)).toBeTruthy();
 | 
			
		||||
    expect(tagToGet.articles.length).toBe(2);
 | 
			
		||||
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: `/content-manager/explorer/deleteAll/article/?source=content-manager&${articles
 | 
			
		||||
        .map((article, index) => `${index}=${article.id}`)
 | 
			
		||||
        .join('&')}`,
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    tagToGet = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(Array.isArray(tagToGet.articles)).toBeTruthy();
 | 
			
		||||
    expect(tagToGet.articles.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneToMany - manyToOne relation (article - category) with Content Manager', () => {
 | 
			
		||||
  beforeAll(() => {
 | 
			
		||||
    data = {
 | 
			
		||||
      articles: [],
 | 
			
		||||
      categories: [],
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
    await new Promise(resolve => setTimeout(resolve, 1000));
 | 
			
		||||
  }, 60000);
 | 
			
		||||
 | 
			
		||||
  test('Create cat1', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/category/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'cat1',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('cat1');
 | 
			
		||||
  });
 | 
			
		||||
  test('Create cat2', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/category/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'cat2',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.name).toBe('cat2');
 | 
			
		||||
  });
 | 
			
		||||
  test('Create article1 with cat1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 1',
 | 
			
		||||
      content: 'Content 1',
 | 
			
		||||
      category: data.categories[0],
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article1 with cat2', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      category: data.categories[1],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
  test('Create article2', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 2',
 | 
			
		||||
      content: 'Content 2',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article2 with cat2', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[1], {
 | 
			
		||||
      category: data.categories[1],
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles[1] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.category.name).toBe(entry.category.name);
 | 
			
		||||
    expect(Array.isArray(body.tags)).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
  test('Update cat1 with article1', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.categories[0]);
 | 
			
		||||
    entry.articles.push(data.articles[0]);
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/category/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.categories[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.name).toBe(entry.name);
 | 
			
		||||
  });
 | 
			
		||||
  test('Create cat3 with article1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      name: 'cat3',
 | 
			
		||||
      articles: [data.articles[0]],
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/category/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.categories.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(Array.isArray(body.articles)).toBeTruthy();
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.name).toBe(entry.name);
 | 
			
		||||
  });
 | 
			
		||||
  test('Get article1 with cat3', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${data.articles[0].id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.category.id).toBe(data.categories[2].id);
 | 
			
		||||
  });
 | 
			
		||||
  test('Get article2 with cat2', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${data.articles[1].id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.category.id).toBe(data.categories[1].id);
 | 
			
		||||
  });
 | 
			
		||||
  test('Get cat1 without relations', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/category/${data.categories[0].id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.articles.length).toBe(0);
 | 
			
		||||
  });
 | 
			
		||||
  test('Get cat2 with article2', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/category/${data.categories[1].id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.articles[0].id).toBe(data.articles[1].id);
 | 
			
		||||
  });
 | 
			
		||||
  test('Get cat3 with article1', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/category/${data.categories[2].id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.articles.length).toBe(1);
 | 
			
		||||
    expect(body.articles[0].id).toBe(data.articles[0].id);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneToOne relation (article - reference) with Content Manager', () => {
 | 
			
		||||
  beforeAll(() => {
 | 
			
		||||
    data = {
 | 
			
		||||
      articles: [],
 | 
			
		||||
      references: [],
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
    await new Promise(resolve => setTimeout(resolve, 1000));
 | 
			
		||||
  }, 60000);
 | 
			
		||||
 | 
			
		||||
  test('Create ref1', async () => {
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'ref1',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.references.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.name).toBe('ref1');
 | 
			
		||||
  });
 | 
			
		||||
  test('Create article1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 1',
 | 
			
		||||
      content: 'Content 1',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
  });
 | 
			
		||||
  test('Update article1 with ref1', async () => {
 | 
			
		||||
    const entry = Object.assign({}, data.articles[0], {
 | 
			
		||||
      reference: data.references[0].id,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    cleanDate(entry);
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/article/${entry.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles[0] = body;
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
  });
 | 
			
		||||
  test('Create article2 with ref1', async () => {
 | 
			
		||||
    const entry = {
 | 
			
		||||
      title: 'Article 2',
 | 
			
		||||
      content: 'Content 2',
 | 
			
		||||
      reference: data.references[0].id,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let body = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/article?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      formData: entry,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    body = JSON.parse(body);
 | 
			
		||||
 | 
			
		||||
    data.articles.push(body);
 | 
			
		||||
 | 
			
		||||
    expect(body.id);
 | 
			
		||||
    expect(body.title).toBe(entry.title);
 | 
			
		||||
    expect(body.content).toBe(entry.content);
 | 
			
		||||
    expect(body.reference.id).toBe(entry.reference);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Test oneWay relation (reference - tag) with Content Manager', () => {
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
    await new Promise(resolve => setTimeout(resolve, 1000));
 | 
			
		||||
  }, 60000);
 | 
			
		||||
 | 
			
		||||
  test('Attach Tag to a Reference', async () => {
 | 
			
		||||
    const tagToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag111',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const referenceToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'cat111',
 | 
			
		||||
        tag: tagToCreate,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Detach Tag to a Reference', async () => {
 | 
			
		||||
    const tagToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag111',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const referenceToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'cat111',
 | 
			
		||||
        tag: tagToCreate,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(referenceToCreate.tag.id).toBe(tagToCreate.id);
 | 
			
		||||
 | 
			
		||||
    const referenceToUpdate = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/reference/${referenceToCreate.id}?source=content-manager`,
 | 
			
		||||
      method: 'PUT',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        tag: null,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    expect(referenceToUpdate.tag).toBe(null);
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('Delete Tag so the relation in the Reference side should be removed', async () => {
 | 
			
		||||
    const tagToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/tag/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'tag111',
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const referenceToCreate = await rq({
 | 
			
		||||
      url: '/content-manager/explorer/reference/?source=content-manager',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      json: true,
 | 
			
		||||
      formData: {
 | 
			
		||||
        name: 'cat111',
 | 
			
		||||
        tag: tagToCreate,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const tagToDelete = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`,
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    const referenceToGet = await rq({
 | 
			
		||||
      url: `/content-manager/explorer/reference/${referenceToCreate.id}?source=content-manager`,
 | 
			
		||||
      method: 'GET',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      if (Object.keys(referenceToGet.tag).length == 0) {
 | 
			
		||||
        referenceToGet.tag = null;
 | 
			
		||||
      }
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
      // Silent
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    expect(referenceToGet.tag).toBe(null);
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
describe('Delete test APIs', () => {
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await restart();
 | 
			
		||||
    await new Promise(resolve => setTimeout(resolve, 1000));
 | 
			
		||||
  }, 60000);
 | 
			
		||||
 | 
			
		||||
  test('Delete article API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/article',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Delete tag API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/tag',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Delete category API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/category',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Delete reference API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/reference',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
  test('Delete product API', async () => {
 | 
			
		||||
    await rq({
 | 
			
		||||
      url: '/content-type-builder/models/product',
 | 
			
		||||
      method: 'DELETE',
 | 
			
		||||
      json: true,
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
@ -50,14 +50,19 @@ const main = async () => {
 | 
			
		||||
      });
 | 
			
		||||
    })
 | 
			
		||||
    .catch(err => {
 | 
			
		||||
      console.log(err);
 | 
			
		||||
      process.stdout.write('testApp exited before the end with error', () => {
 | 
			
		||||
        process.exit(1);
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
  await test().catch(() => {});
 | 
			
		||||
  await test().catch(() => {
 | 
			
		||||
    process.stdout.write('Tests failed', () => {
 | 
			
		||||
      process.exit(1);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  process.kill(testApp.pid);
 | 
			
		||||
  process.exit(0);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
main();
 | 
			
		||||
 | 
			
		||||
@ -1,15 +0,0 @@
 | 
			
		||||
const { auth } = require('./helpers/auth');
 | 
			
		||||
const createReq = require('./helpers/request');
 | 
			
		||||
 | 
			
		||||
const rq = createReq();
 | 
			
		||||
 | 
			
		||||
module.exports = async () => {
 | 
			
		||||
  await rq({
 | 
			
		||||
    url: '/auth/local/register',
 | 
			
		||||
    method: 'POST',
 | 
			
		||||
    body: auth,
 | 
			
		||||
  }).catch(err => {
 | 
			
		||||
    console.log(err);
 | 
			
		||||
    throw err;
 | 
			
		||||
  });
 | 
			
		||||
};
 | 
			
		||||
@ -10,18 +10,16 @@ const rq = createRq();
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
  auth,
 | 
			
		||||
  login: () => {
 | 
			
		||||
    return new Promise(async resolve => {
 | 
			
		||||
      const res = await rq({
 | 
			
		||||
        url: '/auth/local',
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        body: {
 | 
			
		||||
          identifier: auth.email,
 | 
			
		||||
          password: auth.password,
 | 
			
		||||
        },
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      resolve(res.body);
 | 
			
		||||
  login: async () => {
 | 
			
		||||
    const { body } = await rq({
 | 
			
		||||
      url: '/auth/local',
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      body: {
 | 
			
		||||
        identifier: auth.email,
 | 
			
		||||
        password: auth.password,
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    return body;
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ const createReq = (defaults = {}) => {
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return async options => {
 | 
			
		||||
    await restart(1000);
 | 
			
		||||
    await restart(2000);
 | 
			
		||||
 | 
			
		||||
    const params = JSON.parse(JSON.stringify(options));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,31 +1,21 @@
 | 
			
		||||
const request = require('request');
 | 
			
		||||
const request = require('request-promise-native');
 | 
			
		||||
 | 
			
		||||
module.exports = function(initTime = 8000) {
 | 
			
		||||
  const ping = async () => {
 | 
			
		||||
    return new Promise((resolve, reject) => {
 | 
			
		||||
      // set timeout to avoid ping indefinitely
 | 
			
		||||
      setTimeout(() => reject(new Error('Timeout too long to request')), 30000);
 | 
			
		||||
 | 
			
		||||
      // ping _health
 | 
			
		||||
      request(
 | 
			
		||||
        {
 | 
			
		||||
          url: 'http://localhost:1337/_health',
 | 
			
		||||
          method: 'HEAD',
 | 
			
		||||
          mode: 'no-cors',
 | 
			
		||||
          json: true,
 | 
			
		||||
          headers: {
 | 
			
		||||
            'Content-Type': 'application/json',
 | 
			
		||||
            'Keep-Alive': false,
 | 
			
		||||
          },
 | 
			
		||||
      request({
 | 
			
		||||
        url: 'http://localhost:1337/_health',
 | 
			
		||||
        method: 'HEAD',
 | 
			
		||||
        mode: 'no-cors',
 | 
			
		||||
        json: true,
 | 
			
		||||
        headers: {
 | 
			
		||||
          'Content-Type': 'application/json',
 | 
			
		||||
          'Keep-Alive': false,
 | 
			
		||||
        },
 | 
			
		||||
        (err, res) => {
 | 
			
		||||
          // 204 means ok
 | 
			
		||||
          if (res && res.statusCode === 204) {
 | 
			
		||||
            return resolve();
 | 
			
		||||
          }
 | 
			
		||||
          return new Promise(resolve => setTimeout(resolve, 1000)).then(ping);
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
      }).then(resolve, reject);
 | 
			
		||||
    }).catch(() => {
 | 
			
		||||
      return new Promise(resolve => setTimeout(resolve, 1000)).then(ping);
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user