<commit_before>import './custom-matchers';
import {
  GeneratorConfig,
  gql,
  GraphQLSchema,
  introspectionToGraphQLSchema,
  makeExecutableSchema,
  SchemaTemplateContext,
  schemaToTemplateContext,
  transformDocument
} from 'graphql-codegen-core';
import { compileTemplate } from 'graphql-codegen-compiler';
import config from '../dist';
import * as fs from 'fs';

describe('TypeScript template', () => {
  const compileAndBuildContext = (typeDefs: string): { context: SchemaTemplateContext; schema: GraphQLSchema } => {
    const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;

    return {
      schema,
      context: schemaToTemplateContext(schema)
    };
  };

  it('should handle prepend option correctly', async () => {
    const { context } = compileAndBuildContext(`
      type Query {
        test: String
      }

      schema {
        query: Query
      }
    `);

    const compiled = await compileTemplate(
      {
        ...config,
        config: {
          prepend: ['// Test']
        }
      } as GeneratorConfig,
      context
    );

    const content = compiled[0].content;

    expect(content).toBeSimilarStringTo(`
    // Test
    `);
  });

  it('should handle interfacePrefix option correctly', async () => {
    const { context } = compileAndBuildContext(`
      type Foo {
        bar: Bar
      }
      type Bar {<commit_msg>Adjust test to include previously failing characters<commit_after>import './custom-matchers';
import {
  GeneratorConfig,
  gql,
  GraphQLSchema,
  introspectionToGraphQLSchema,
  makeExecutableSchema,
  SchemaTemplateContext,
  schemaToTemplateContext,
  transformDocument
} from 'graphql-codegen-core';
import { compileTemplate } from 'graphql-codegen-compiler';
import config from '../dist';
import * as fs from 'fs';

describe('TypeScript template', () => {
  const compileAndBuildContext = (typeDefs: string): { context: SchemaTemplateContext; schema: GraphQLSchema } => {
    const schema = makeExecutableSchema({ typeDefs, resolvers: {}, allowUndefinedInResolve: true }) as GraphQLSchema;

    return {
      schema,
      context: schemaToTemplateContext(schema)
    };
  };

  it('should handle prepend option correctly', async () => {
    const { context } = compileAndBuildContext(`
      type Query {
        test: String
      }

      schema {
        query: Query
      }
    `);

    const compiled = await compileTemplate(
      {
        ...config,
        config: {
          prepend: ['// Test [="]']
        }
      } as GeneratorConfig,
      context
    );

    const content = compiled[0].content;

    expect(content).toBeSimilarStringTo(`
    // Test [="]
    `);
  });

  it('should handle interfacePrefix option correctly', async () => {
    const { context } = compileAndBuildContext(`
      type Foo {
        bar: Bar
      }
      type Bar {
{'fraction_non_alphanumeric': 0.11529168104936141, 'fraction_numerical': 0.0006903693476009665, 'mean_word_length': 2.8081471747700393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '3397651', 'n_tokens_mistral': 815, 'n_tokens_neox': 796, 'n_words': 198}