<commit_before>import { AbstractRunner } from '../../../lib/runners';
import { NestCollection } from '../../../lib/schematics/nest.collection';

describe('Nest Collection', () => {
  [
    'application',
    'class',
    'controller',
    'decorator',
    'library',
    'filter',
    'gateway',
    'guard',
    'interceptor',
    'middleware',
    'module',
    'pipe',
    'provider',
    'service',
  ].forEach(schematic => {
    it(`should call runner with ${schematic} schematic name`, async () => {
      const mock = jest.fn();
      mock.mockImplementation(() => {
        return {
          logger: {},
          run: jest.fn().mockImplementation(() => Promise.resolve()),
        };
      });
      const mockedRunner = mock();
      const collection = new NestCollection(mockedRunner as AbstractRunner);
      await collection.execute(schematic, []);
      expect(mockedRunner.run).toHaveBeenCalledWith(
        `@nestjs/schematics:${schematic}`,
      );
    });
  });
  [
    { name: 'application', alias: 'app' },
    { name: 'class', alias: 'cl' },
    { name: 'controller', alias: 'co' },
    { name: 'decorator', alias: 'd' },
    { name: 'library', alias: 'lib' },
    { name: 'filter', alias: 'f' },
    { name: 'gateway', alias: 'ga' },
    { name: 'guard', alias: 'gu' },
    { name: 'interceptor', alias: 'i' },
    { name: 'middleware', alias: 'mi' },
    { name: 'module', alias: 'mo' },
    { name: 'pipe', alias: 'pi' },
    { name: 'provider', alias: 'pr' },
    { name: 'service', alias: 's' },
  ].forEach(schematic => {
    it(`should call runner with schematic ${schematic.name} name when use ${
      schematic.alias
    } alias`, async () => {
      const mock = jest.fn();
      mock.mockImplementation(() => {
        return {
          logger: {},
          run: jest.fn().mockImplementation(() => Promise.resolve()),
        };
      });
      const mockedRunner = mock();
      const collection = new NestCollection(mockedRunner as AbstractRunner);
      await collection.execute(schematic.alias, []);
      expect(mockedRunner.run).toHaveBeenCalledWith(
        `@nestjs/schematics:${schematic.name}`,
      );
    });
  });
  it('should throw an error when schematic name is not in nest collection', async () => {
    const mock = jest.fn();
    mock.mockImplementation(() => {
      return {
        logger: {},
        run: jest.fn().mockImplementation(() => Promise.resolve()),
      };
    });
    const mockedRunner = mock();
    const collection = new NestCollection(mockedRunner as AbstractRunner);
    try {
      await collection.execute('name', []);
    } catch (error) {
      expect(error.message).toEqual(
        'Invalid schematic "name". Please, ensure that "name" really exists in this collection.',
      );
    }
  });
});
<commit_msg>tests() update unit tests<commit_after>import { AbstractRunner } from '../../../lib/runners';
import { NestCollection } from '../../../lib/schematics/nest.collection';

describe('Nest Collection', () => {
  [
    'application',
    'class',
    'controller',
    'decorator',
    'library',
    'filter',
    'gateway',
    'guard',
    'interceptor',
    'middleware',
    'module',
    'pipe',
    'provider',
    'service',
  ].forEach(schematic => {
    it(`should call runner with ${schematic} schematic name`, async () => {
      const mock = jest.fn();
      mock.mockImplementation(() => {
        return {
          logger: {},
          run: jest.fn().mockImplementation(() => Promise.resolve()),
        };
      });
      const mockedRunner = mock();
      const collection = new NestCollection(mockedRunner as AbstractRunner);
      await collection.execute(schematic, []);
      expect(mockedRunner.run).toHaveBeenCalledWith(
        `@nestjs/schematics:${schematic}`,
      );
    });
  });
  [
    { name: 'application', alias: 'app' },
    { name: 'class', alias: 'cl' },
    { name: 'controller', alias: 'co' },
    { name: 'decorator', alias: 'd' },
    { name: 'library', alias: 'lib' },
    { name: 'filter', alias: 'f' },
    { name: 'gateway', alias: 'ga' },
    { name: 'guard', alias: 'gu' },
    { name: 'interceptor', alias: 'in' },
    { name: 'middleware', alias: 'mi' },
    { name: 'module', alias: 'mo' },
    { name: 'pipe', alias: 'pi' },
    { name: 'provider', alias: 'pr' },
    { name: 'service', alias: 's' },
  ].forEach(schematic => {
    it(`should call runner with schematic ${schematic.name} name when use ${
      schematic.alias
    } alias`, async () => {
      const mock = jest.fn();
      mock.mockImplementation(() => {
        return {
          logger: {},
          run: jest.fn().mockImplementation(() => Promise.resolve()),
        };
      });
      const mockedRunner = mock();
      const collection = new NestCollection(mockedRunner as AbstractRunner);
      await collection.execute(schematic.alias, []);
      expect(mockedRunner.run).toHaveBeenCalledWith(
        `@nestjs/schematics:${schematic.name}`,
      );
    });
  });
  it('should throw an error when schematic name is not in nest collection', async () => {
    const mock = jest.fn();
    mock.mockImplementation(() => {
      return {
        logger: {},
        run: jest.fn().mockImplementation(() => Promise.resolve()),
      };
    });
    const mockedRunner = mock();
    const collection = new NestCollection(mockedRunner as AbstractRunner);
    try {
      await collection.execute('name', []);
    } catch (error) {
      expect(error.message).toEqual(
        'Invalid schematic "name". Please, ensure that "name" really exists in this collection.',
      );
    }
  });
});

{'fraction_non_alphanumeric': 0.18275923612350525, 'fraction_numerical': 0.0, 'mean_word_length': 2.6108247422680413, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '6530331', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1672, 'n_words': 393}