// @flow

import { it, describe } from 'kocha'
import assert from 'power-assert'
import type { AndFindOperation } from 'phenyl-interfaces'
import { filterWhere } from '../src/mongodb-client.js'

describe('filterWhere', () => {
  it ('renames id to _id', () => {
    const input: AndFindOperation = {
      $and: [
        { id: 'abc' },
        { type: 'bar' },
      ]
    }
    const expected = {
      $and: [
        { _id: 'abc' },
        { type: 'bar' },
      ]
    }
    const actual = filterWhere(input)
    assert.deepEqual(actual, expected)
  })

  it ('converts document path to dot notation', () => {
    const input: AndFindOperation = {
      $and: [
        { 'values[0]': 'fizz' },
        { 'values[1].test': 'buzz' },
        { 'values[1234].test': 'fizzBuzz' },
        { type: 'bar' },
      ]
    }
    const expected = {
      $and: [
        { 'values.0': 'fizz' },
        { 'values.1.test': 'buzz' },
        { 'values.1234.test': 'fizzBuzz' },
        { type: 'bar' },
      ]
    }
    const actual = filterWhere(input)
    assert.deepEqual(actual, expected)
  })
})

@@ -600,32 +600,78 @@
 ation', () =%3E %7B%0A
+    // $FlowIssue(this-is-and-find-operation)%0A
     const input:
@@ -801,29 +801,146 @@
 s%5B12
-34%5D.test': 'fizzB
+%5D.test': %7B $eq: 'fizzBuzz' %7D %7D,%0A        %7B 'values%5B123%5D.test': %7B $regex: /zz/ %7D %7D,%0A        %7B 'values%5B1234%5D.test': %7B $in: %5B'fizz', 'b
 uzz'
+%5D %7D
  %7D,%0A
@@ -1108,28 +1108,143 @@
 s.12
-34.test': 'fizzB
+.test': %7B $eq: 'fizzBuzz' %7D %7D,%0A        %7B 'values.123.test': %7B $regex: /zz/ %7D %7D,%0A        %7B 'values.1234.test': %7B $in: %5B'fizz', 'b
 uzz'
+%5D %7D
  %7D,%0A

Add query operator test cases