<commit_before>/* eslint-disable no-new, no-unused-expressions */
const expect = require('chai').expect;

const fail = expect.fail;
const JDLParser = require('../../../lib/parser/jdl_parser');
const EntityParser = require('../../../lib/parser/entity_parser');
const parseFromFiles = require('../../../lib/reader/jdl_reader').parseFromFiles;
const ApplicationTypes = require('../../../lib/core/jhipster/application_types').APPLICATION_TYPES;
const DatabaseTypes = require('../../../lib/core/jhipster/database_types').Types;

describe('::convert', () => {
  describe('when passing invalid parameters', () => {
    describe('such as undefined', () => {
      it('throws an error', () => {
        try {
          EntityParser.parse();
          fail();
        } catch (error) {
          expect(error.name).to.eq('NullPointerException');
        }
      });
    });
    describe('such as an no databaseType', () => {
      const input = parseFromFiles(['./test/test_files/valid_jdl.jdl']);
      it('throws an error', () => {
        try {
          EntityParser.parse({
            jdlObject: JDLParser.parse({
              document: input,
              databaseType: 'sql'
            })
          });
          fail();
        } catch (error) {
          expect(error.name).to.eq('NullPointerException');
        }
      });
    });
    describe('such as invalid databaseType', () => {
      const input = parseFromFiles(['./test/test_files/valid_jdl.jdl']);
      it('throws an error', () => {
        try {
          EntityParser.parse({
            jdlObject: JDLParser.parse({
              document: input,
              databaseType: 'sql'
            }),
            databaseType: 'mongodb'
          });
          fail();
        } catch (error) {
          expect(error.name).to.eq('NoSQLModelingException');
        }
      });
    });
  });
  describe('when passing valid arguments', () => {
    describe('when passing args for a gateway app', () => {
      const input = parseFromFiles(['./test/test_files/complex_jdl.jdl']);
      it('does not fail because of NoSQL modeling mistakes', () => {
        EntityParser.parse({
          jdlObject: JDLParser.parse({
            document: input,
            databaseType: 'mysql'
          }),
          databaseType: 'cassandra',
          applicationType: 'gateway'
        });
      });
    });
    describe('when converting JDL to entity json for SQL type', () => {
      const input = parseFromFiles(['./test/test_files/complex_jdl.jdl']);
      const content = EntityParser.parse({
        jdlObject: JDLParser.parse({
          document: input,
          databaseType: 'mysql'
        }),
        databaseType: 'mysql'
      });
      it('converts it', () => {
        expect(content).not.to.be.null;
        expect(Object.keys(content).length).to.eq(8);
        for (let i = 0, entities = Object.keys(content); i < entities.length; i++) {
          expect(content[entities[i]].fluentMethods).to.eq(true);
        }
        expect(content.Department.relationships.length).to.eq(2);
        expect(content.Department.relationships[1].javadoc).to.eq('A relationship');
        expect(content.Department.fields.length).to.eq(2);
        expect(content.Department.entityTableName).to.eq('department');
        expect(content.Employee.javadoc).to.eq('The Employee entity.\nSecond line in javadoc.');
        expect(content.Employee.pagination).to.eq('infinite-scroll');
        expect(content.Employee.relationships[3].javadoc).to.eq('Another side of the same relationship');
        expect(content.Job.relationships[0].otherEntityRelationshipName).to.eq('job');
        expect(content.Task.relationships[0].otherEntityRelationshipName).to.eq('chore');
      });
    });
    describe('when converting JDL to entity json for MongoDB type', () => {
      const input = parseFromFiles(['./test/test_files/mongo_jdl.jdl']);
      const content = EntityParser.parse({
        jdlObject: JDLParser.parse({
          document: input,
          databaseType: 'mongodb'
        }),
        databaseType: 'mongodb'
      });
      it('converts it', () => {
        expect(content).not.to.be.null;
        expect(Object.keys(content).length).to.eq(8);
        expect(content.Department.relationships.length).to.eq(0);
        expect(content.Department.fields.length).to.eq(2);
        expect(content.Department.entityTableName).to.eq('department');
        expect(content.Employee.javadoc).to.eq('The Employee entity.');
        expect(content.Employee.pagination).to.eq('infinite-scroll');
      });
    });
    describe('when converting JDL to entity json for Couchbase type', () => {
      const input = parseFromFiles(['./test/test_files/couchbase_jdl.jdl']);
      const content = EntityParser.parse({
        jdlObject: JDLParser.parse(input, 'couchbase'),
        databaseType: 'couchbase'
      });
      it('converts it', () => {
        expect(content).not.to.be.null;
        expect(Object.keys(content).length).to.eq(8);
        expect(content.Department.relationships.length).to.eq(0);<commit_msg>Fixed test<commit_after>/* eslint-disable no-new, no-unused-expressions */
const expect = require('chai').expect;

const fail = expect.fail;
const JDLParser = require('../../../lib/parser/jdl_parser');
const EntityParser = require('../../../lib/parser/entity_parser');
const parseFromFiles = require('../../../lib/reader/jdl_reader').parseFromFiles;
const ApplicationTypes = require('../../../lib/core/jhipster/application_types').APPLICATION_TYPES;
const DatabaseTypes = require('../../../lib/core/jhipster/database_types').Types;

describe('::convert', () => {
  describe('when passing invalid parameters', () => {
    describe('such as undefined', () => {
      it('throws an error', () => {
        try {
          EntityParser.parse();
          fail();
        } catch (error) {
          expect(error.name).to.eq('NullPointerException');
        }
      });
    });
    describe('such as an no databaseType', () => {
      const input = parseFromFiles(['./test/test_files/valid_jdl.jdl']);
      it('throws an error', () => {
        try {
          EntityParser.parse({
            jdlObject: JDLParser.parse({
              document: input,
              databaseType: 'sql'
            })
          });
          fail();
        } catch (error) {
          expect(error.name).to.eq('NullPointerException');
        }
      });
    });
    describe('such as invalid databaseType', () => {
      const input = parseFromFiles(['./test/test_files/valid_jdl.jdl']);
      it('throws an error', () => {
        try {
          EntityParser.parse({
            jdlObject: JDLParser.parse({
              document: input,
              databaseType: 'sql'
            }),
            databaseType: 'mongodb'
          });
          fail();
        } catch (error) {
          expect(error.name).to.eq('NoSQLModelingException');
        }
      });
    });
  });
  describe('when passing valid arguments', () => {
    describe('when passing args for a gateway app', () => {
      const input = parseFromFiles(['./test/test_files/complex_jdl.jdl']);
      it('does not fail because of NoSQL modeling mistakes', () => {
        EntityParser.parse({
          jdlObject: JDLParser.parse({
            document: input,
            databaseType: 'mysql'
          }),
          databaseType: 'cassandra',
          applicationType: 'gateway'
        });
      });
    });
    describe('when converting JDL to entity json for SQL type', () => {
      const input = parseFromFiles(['./test/test_files/complex_jdl.jdl']);
      const content = EntityParser.parse({
        jdlObject: JDLParser.parse({
          document: input,
          databaseType: 'mysql'
        }),
        databaseType: 'mysql'
      });
      it('converts it', () => {
        expect(content).not.to.be.null;
        expect(Object.keys(content).length).to.eq(8);
        for (let i = 0, entities = Object.keys(content); i < entities.length; i++) {
          expect(content[entities[i]].fluentMethods).to.eq(true);
        }
        expect(content.Department.relationships.length).to.eq(2);
        expect(content.Department.relationships[1].javadoc).to.eq('A relationship');
        expect(content.Department.fields.length).to.eq(2);
        expect(content.Department.entityTableName).to.eq('department');
        expect(content.Employee.javadoc).to.eq('The Employee entity.\nSecond line in javadoc.');
        expect(content.Employee.pagination).to.eq('infinite-scroll');
        expect(content.Employee.relationships[3].javadoc).to.eq('Another side of the same relationship');
        expect(content.Job.relationships[0].otherEntityRelationshipName).to.eq('job');
        expect(content.Task.relationships[0].otherEntityRelationshipName).to.eq('chore');
      });
    });
    describe('when converting JDL to entity json for MongoDB type', () => {
      const input = parseFromFiles(['./test/test_files/mongo_jdl.jdl']);
      const content = EntityParser.parse({
        jdlObject: JDLParser.parse({
          document: input,
          databaseType: 'mongodb'
        }),
        databaseType: 'mongodb'
      });
      it('converts it', () => {
        expect(content).not.to.be.null;
        expect(Object.keys(content).length).to.eq(8);
        expect(content.Department.relationships.length).to.eq(0);
        expect(content.Department.fields.length).to.eq(2);
        expect(content.Department.entityTableName).to.eq('department');
        expect(content.Employee.javadoc).to.eq('The Employee entity.');
        expect(content.Employee.pagination).to.eq('infinite-scroll');
      });
    });
    describe('when converting JDL to entity json for Couchbase type', () => {
      const input = parseFromFiles(['./test/test_files/couchbase_jdl.jdl']);
      const content = EntityParser.parse({
        jdlObject: JDLParser.parse({ document: input, databaseType: 'couchbase' }),
        databaseType: 'couchbase'
      });
      it('converts it', () => {
        expect(content).not.to.be.null;
        expect(Object.keys(content).length).to.eq(8);
        expect(content.Department.relationships.length).to.eq(0);
{'fraction_non_alphanumeric': 0.16395704010247314, 'fraction_numerical': 0.002561828751601143, 'mean_word_length': 2.4784098697738175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '808070', 'n_tokens_mistral': 2956, 'n_tokens_neox': 2882, 'n_words': 479}