# This spec is specific to the ruby driver, and is not part of the general
# `specifications` repo.

description: "find options"

schemaVersion: "1.0"
runOnRequirements:
  - serverless: 'forbid'


createEntities:
  - client:
      id: &client0 client0
      observeEvents: [ commandStartedEvent ]
  - database:
      id: &database0 database0
      client: *client0
      databaseName: &database0Name find-tests
  - collection:
      id: &collection0 collection0
      database: *database0
      collectionName: &collection0Name coll0

tests:
  - description: "sort"
    operations:
      - name: find
        arguments:
          filter: &filter { _name: "John" }
          sort: &sort { _id: 1 }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                sort: *sort
              commandName: find

  - description: "projection"
    operations:
      - name: find
        arguments:
          filter: *filter
          projection: &projection { _id: 1 }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                projection: *projection
              commandName: find
              databaseName: *database0Name

  - description: "hint"
    operations:
      - name: find
        arguments:
          filter: *filter
          hint: &hint { _id: 1 }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                hint: *hint
              commandName: find
              databaseName: *database0Name

  - description: "skip"
    operations:
      - name: find
        arguments:
          filter: *filter
          skip: &skip 10
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                skip: *skip
              commandName: find
              databaseName: *database0Name

  - description: "limit"
    operations:
      - name: find
        arguments:
          filter: *filter
          limit: &limit 10
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                limit: *limit
              commandName: find
              databaseName: *database0Name

  - description: "batchSize"
    operations:
      - name: find
        arguments:
          filter: *filter
          batchSize: &batchSize 10
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                batchSize: *batchSize
              commandName: find
              databaseName: *database0Name

  - description: "comment"
    operations:
      - name: find
        arguments:
          filter: *filter
          comment: &comment 'comment'
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                comment: *comment
              commandName: find
              databaseName: *database0Name

  - description: "maxTimeMS"
    operations:
      - name: find
        arguments:
          filter: *filter
          maxTimeMS: &maxTimeMS 1000
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                maxTimeMS: *maxTimeMS
              commandName: find
              databaseName: *database0Name

  - description: "timeoutMS"
    operations:
      - name: find
        arguments:
          filter: *filter
          timeoutMS: &timeoutMS 1000
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                maxTimeMS: { $$type: [ int ] }
              commandName: find
              databaseName: *database0Name

  - description: "max"
    operations:
      - name: find
        arguments:
          filter: *filter
          hint: { _id: 1 }
          max: &max { _id: 10 }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                max: *max
              commandName: find
              databaseName: *database0Name

  - description: "min"
    operations:
      - name: createIndex
        object: *collection0
        arguments:
          name: "name_1"
          keys: { name: 1 }
      - name: find
        arguments:
          filter: *filter
          hint: { name: 1 }
          min: &min { name: 'John' }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              commandName: createIndexes
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                min: *min
              commandName: find
              databaseName: *database0Name

  - description: "returnKey"
    operations:
      - name: find
        arguments:
          filter: *filter
          returnKey: &returnKey false
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                returnKey: *returnKey
              commandName: find
              databaseName: *database0Name

  - description: "showRecordId"
    operations:
      - name: find
        arguments:
          filter: *filter
          showRecordId: &showRecordId false
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                showRecordId: *showRecordId
              commandName: find
              databaseName: *database0Name

  - description: "oplogReplay"
    operations:
      - name: find
        arguments:
          filter: *filter
          oplogReplay: &oplogReplay false
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                oplogReplay: *oplogReplay
              commandName: find
              databaseName: *database0Name

  - description: "noCursorTimeout"
    operations:
      - name: find
        arguments:
          filter: *filter
          noCursorTimeout: &noCursorTimeout false
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                noCursorTimeout: *noCursorTimeout
              commandName: find
              databaseName: *database0Name

  - description: "allowPartialResults"
    operations:
      - name: find
        arguments:
          filter: *filter
          allowPartialResults: &allowPartialResults false
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                allowPartialResults: *allowPartialResults
              commandName: find
              databaseName: *database0Name

  - description: "collation"
    operations:
      - name: find
        arguments:
          filter: *filter
          collation: &collation { locale: "en" }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                collation: *collation
              commandName: find
              databaseName: *database0Name

  - description: "allowDiskUse"
    runOnRequirements:
      - minServerVersion: 4.4
    operations:
      - name: find
        arguments:
          filter: *filter
          allowDiskUse: &allowDiskUse true
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                allowDiskUse: *allowDiskUse
              commandName: find
              databaseName: *database0Name

  - description: "let"
    runOnRequirements:
      - minServerVersion: "5.0"
    operations:
      - name: find
        arguments:
          filter: *filter
          let: &let { name: "Mary" }
        object: *collection0
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                find: *collection0Name
                filter: *filter
                let: *let
              commandName: find
              databaseName: *database0Name
