<commit_before>'use strict'

import readCache from '../lib/read-cache'
import test from 'blue-tape'
import Request from './helpers/req'

test('readCache closure', t => {
  const closure = readCache({})

  t.equals(typeof closure, 'function', 'reading from cache should return a closure')
  t.end()
})

test('readCache closure is a promise', t => {
  const closure = readCache({})

  t.ok(closure() instanceof Promise, 'reading from cache should return a promise')
  t.end()
})

test('readCache success callback', t => {
  const value = {
    body: {
      responseType: 'text',
      responseText: 'Hello world',
      status: 200,
      statusText: 'OK'
    },
    headers: {
      'content-type': 'text/plain'
    }
  }

  const req = new Request()

  return new Promise((resolve) => {
    readCache(req)(JSON.stringify(value))
      .then((res) => {
        t.equals(res.body, value.body.responseText, 'response should be defined')

        resolve()
      })
      .catch((err) => {
        // add test in case of error
        t.error(err, 'hydration should not throw')

        resolve()
      })
  })
})

test('readCache error callback', t => {
  return new Promise((resolve) => {<commit_msg>test(read-cache): fix test to support value format<commit_after>'use strict'

import readCache from '../lib/read-cache'
import test from 'blue-tape'
import Request from './helpers/req'

test('readCache closure', t => {
  const closure = readCache({})

  t.equals(typeof closure, 'function', 'reading from cache should return a closure')
  t.end()
})

test('readCache closure is a promise', t => {
  const closure = readCache({})

  t.ok(closure() instanceof Promise, 'reading from cache should return a promise')
  t.end()
})

test('readCache success callback', t => {
  const value = {
    expires: 0,
    data: {
      body: {
        responseType: 'text',
        responseText: 'Hello world',
        status: 200,
        statusText: 'OK'
      },
      headers: 'content-type: text/plain'
    }
  }

  const req = new Request()

  return new Promise((resolve) => {
      .then((res) => {
    readCache(req)(value)
        t.equals(res.body, value.data.body.responseText, 'response should be defined')

        resolve()
      })
      .catch((err) => {
        // add test in case of error
        t.error(err, 'hydration should not throw')

        resolve()
      })
  })
})

test('readCache error callback', t => {
  return new Promise((resolve) => {
{'fraction_non_alphanumeric': 0.1486156351791531, 'fraction_numerical': 0.0028501628664495114, 'mean_word_length': 2.774193548387097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '2052558', 'n_tokens_mistral': 763, 'n_tokens_neox': 737, 'n_words': 221}