runOn:
    -
        minServerVersion: "4.0"
        topology: ["replicaset"]
    -
        minServerVersion: "4.1.8"
        topology: ["sharded"]

database_name: &database_name "transaction-tests"
collection_name: &collection_name "test"

data:
  - _id: 1
  - _id: 2
  - _id: 3

tests:
  - description: findOneAndDelete

    operations:
      - name: startTransaction
        object: session0
      - name: findOneAndDelete
        object: collection
        arguments:
          session: session0
          filter: {_id: 3}
        result: {_id: 3}
      - name: findOneAndDelete
        object: collection
        arguments:
          session: session0
          filter: {_id: 4}
        result:
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            findAndModify: *collection_name
            query: {_id: 3}
            remove: True
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            readConcern:
            writeConcern:
          command_name: findAndModify
          database_name: *database_name
      - command_started_event:
          command:
            findAndModify: *collection_name
            query: {_id: 4}
            remove: True
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            readConcern:
            writeConcern:
          command_name: findAndModify
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            readConcern:
            writeConcern:
          command_name: commitTransaction
          database_name: admin

    outcome:
      collection:
        data:
          - {_id: 1}
          - {_id: 2}

  - description: collection writeConcern ignored for findOneAndDelete

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            writeConcern:
              w: majority
      - name: findOneAndDelete
        object: collection
        collectionOptions:
          writeConcern:
            w: majority
        arguments:
          session: session0
          filter: {_id: 3}
        result: {_id: 3}
      - name: commitTransaction
        object: session0

    expectations:
      - command_started_event:
          command:
            findAndModify: *collection_name
            query: {_id: 3}
            remove: True
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction: true
            autocommit: false
            readConcern:
            writeConcern:
          command_name: findAndModify
          database_name: *database_name
      - command_started_event:
          command:
            commitTransaction: 1
            lsid: session0
            txnNumber:
              $numberLong: "1"
            startTransaction:
            autocommit: false
            readConcern:
            writeConcern:
              w: majority
          command_name: commitTransaction
          database_name: admin
