<commit_before>// Copyright 2019, Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import test from 'ava'
import { shiritoriApp } from '.'
import sinon from 'sinon'
import admin from 'firebase-admin'

const corpus = require('./corpus.json')

test.beforeEach(t => {
  sinon.stub(Math, 'random').returns(0)
})

test.afterEach(t => {
  Math.random.restore()
  if (t.context.database !== undefined) {
    t.context.database.restore()
  }
})

test.serial('welcome', async t => {
  t.snapshot((await shiritoriApp({'inputs': [
    {
      'intent': 'actions.intent.MAIN'
    }
  ]}, {})).body)
})

test.serial('game: next', async t => {
  t.context.database = sinon.stub(admin, 'database').get(
      () => () => fakeDb(corpus)
  )
  t.snapshot((await shiritoriApp({'inputs': [
    {
      'intent': 'actions.intent.TEXT',
      'rawInputs': [
        {
          'inputType': 'VOICE',
          'query': 'とんかつ'
        }
      ]
    }
  ]}, {})).body)
})

test.serial('game: loose', async t => {
  t.context.database = sinon.stub(admin, 'database').get(<commit_msg>shiritori/test: loose -> lose<commit_after>// Copyright 2019, Google, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import test from 'ava'
import { shiritoriApp } from '.'
import sinon from 'sinon'
import admin from 'firebase-admin'

const corpus = require('./corpus.json')

test.beforeEach(t => {
  sinon.stub(Math, 'random').returns(0)
})

test.afterEach(t => {
  Math.random.restore()
  if (t.context.database !== undefined) {
    t.context.database.restore()
  }
})

test.serial('welcome', async t => {
  t.snapshot((await shiritoriApp({'inputs': [
    {
      'intent': 'actions.intent.MAIN'
    }
  ]}, {})).body)
})

test.serial('game: next', async t => {
  t.context.database = sinon.stub(admin, 'database').get(
      () => () => fakeDb(corpus)
  )
  t.snapshot((await shiritoriApp({'inputs': [
    {
      'intent': 'actions.intent.TEXT',
      'rawInputs': [
        {
          'inputType': 'VOICE',
          'query': 'とんかつ'
        }
      ]
    }
  ]}, {})).body)
})

test.serial('game: lose', async t => {
  t.context.database = sinon.stub(admin, 'database').get(
{'fraction_non_alphanumeric': 0.16062992125984252, 'fraction_numerical': 0.005669291338582677, 'mean_word_length': 3.0927835051546393, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7083964', 'n_tokens_mistral': 1005, 'n_tokens_neox': 1018, 'n_words': 287}