<commit_before>import * as chai from 'chai';
const { assert } = chai;

import mockNetworkInterface from './mocks/mockNetworkInterface';
import ApolloClient from '../src';

import assign = require('lodash.assign');
import clonedeep = require('lodash.clonedeep');

import gql from 'graphql-tag';

describe('fetchMore on an observable query', () => {
  const query = gql`<commit_msg>add a test for updateQuery<commit_after>import * as chai from 'chai';
const { assert } = chai;

import mockNetworkInterface from './mocks/mockNetworkInterface';
import ApolloClient from '../src';

import assign = require('lodash.assign');
import clonedeep = require('lodash.clonedeep');

import gql from 'graphql-tag';

describe('updateQuery on a simple query', () => {
  const query = gql`
    query thing {
      entry {
        value
      }
    }
  `;
  const result = {
    data: {
      entry: {
        value: 1,
      },
    },
  };

  it('triggers new result from updateQuery', () => {
    let latestResult = null;
    const networkInterface = mockNetworkInterface({
      request: { query },
      result,
    });

    const client = new ApolloClient({
      networkInterface,
    });

    const obsHandle = client.watchQuery({
      query,
    });
    const sub = obsHandle.subscribe({
      next(queryResult) {
        // do nothing
        latestResult = queryResult;
      },
    });

    return new Promise((resolve) => setTimeout(resolve))
      .then(() => obsHandle)
      .then((watchedQuery) => {
        assert.equal(latestResult.data.entry.value, 1);
        watchedQuery.updateQuery((prevResult) => {
          const res = clonedeep(prevResult);
          res.entry.value = 2;
          return res;
        });

        assert.equal(latestResult.data.entry.value, 2);
      })
      .then(() => sub.unsubscribe());
  });
});

describe('fetchMore on an observable query', () => {
  const query = gql`
{'fraction_non_alphanumeric': 0.138801261829653, 'fraction_numerical': 0.002103049421661409, 'mean_word_length': 2.7387033398821217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '6111183', 'n_tokens_mistral': 580, 'n_tokens_neox': 554, 'n_words': 141}