description: "updateMany-comment"
schemaVersion: "1.0"

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

initialData: &initialData
  - collectionName: *collection0Name
    databaseName: *database0Name
    documents:
      - { _id: 1, x: 11 }

tests:
  - description: "UpdateMany with string comment"
    runOnRequirements:
      - minServerVersion: "4.4"
    operations:
      - name: updateMany
        object: *collection0
        arguments:
          filter: &filter { _id: 1 }
          update: &update { $set: {x: 22} }
          comment: "comment"
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                update: *collection0Name
                updates:
                  -
                    q: *filter
                    u: *update
                    multi: true
                    upsert: { $$unsetOrMatches: false }
                comment: "comment"
    outcome: &outcome
      - collectionName: *collection0Name
        databaseName: *database0Name
        documents:
          - { _id: 1, x: 22 }

  - description: "UpdateMany with document comment"
    runOnRequirements:
      - minServerVersion: "4.4"
    operations:
      - name: updateMany
        object: *collection0
        arguments:
          filter: *filter
          update: *update
          comment: &comment { key: "value" }
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                update: *collection0Name
                updates:
                  -
                    q: *filter
                    u: *update
                    multi: true
                    upsert: { $$unsetOrMatches: false }
                comment: *comment
    outcome: *outcome

  - description: "UpdateMany with comment - pre 4.4"
    runOnRequirements:
      - minServerVersion: "3.4.0"
        maxServerVersion: "4.2.99"
    operations:
      - name: updateMany
        object: *collection0
        arguments:
          filter: *filter
          update: *update
          comment: "comment"
        expectError:
          isClientError: false
    expectEvents:
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                update: *collection0Name
                updates:
                  -
                    q: *filter
                    u: *update
                    multi: true
                    upsert: { $$unsetOrMatches: false }
                comment: "comment"
    outcome: *initialData
