const Broker = require('../index')
const COORDINATOR_TYPES = require('../../protocol/coordinatorTypes')
const {
  secureRandom,
  createTopic,
  createConnection,
  newLogger,
  retryProtocol,
} = require('testHelpers')

describe('Broker > AddPartitionsToTxn', () => {
  let broker, seedBroker, transactionalId, producerId, producerEpoch, topicName

  beforeEach(async () => {
    transactionalId = `producer-group-id-${secureRandom()}`
    topicName = `test-topic-${secureRandom()}`

    seedBroker = new Broker({
      connection: createConnection(),
      logger: newLogger(),
    })
    await seedBroker.connect()
    await createTopic({ topic: topicName, partitions: 4 })

    const {
      coordinator: { host, port },
    } = await retryProtocol(
      'GROUP_COORDINATOR_NOT_AVAILABLE',
      async () =>
        await seedBroker.findGroupCoordinator({
          groupId: transactionalId,
          coordinatorType: COORDINATOR_TYPES.TRANSACTION,
        })
    )

    broker = new Broker({
      connection: createConnection({ host, port }),
      logger: newLogger(),
    })
    await broker.connect()
    ;({ producerId, producerEpoch } = await broker.initProducerId({
      transactionalId,
      transactionTimeout: 30000,
    }))
  })

  afterEach(async () => {
    await seedBroker.disconnect()
    await broker.disconnect()
  })

  test('request', async () => {
    const result = await broker.addPartitionsToTxn({
      transactionalId,
      producerId,
      producerEpoch,
      topics: [
        {
          topic: topicName,
          partitions: [1, 2],
        },
      ],
    })

    expect(result).toEqual({
      throttleTime: 0,
      errors: [
        {
          topic: topicName,
          partitionErrors: [{ errorCode: 0, partition: 1 }, { errorCode: 0, partition: 2 }],
        },
      ],
    })
  })

  test('throws for invalid producer id', async () => {
    expect(
      broker.addPartitionsToTxn({
        transactionalId,
        producerId: 'foo',
        producerEpoch,
        topics: [
          {
            topic: topicName,
            partitions: [1, 2],
          },
        ],
      })
    ).rejects.toEqual({
      error:
        'The producer attempted to use a producer id which is not currently assigned to its transactional id',
    })
  })
})

@@ -572,32 +572,33 @@
 ogger(),%0A    %7D)%0A
+%0A
     await seedBr
@@ -1075,24 +1075,25 @@
 r(),%0A    %7D)%0A
+%0A
     await br
@@ -1115,39 +1115,20 @@
     
-;(%7B producerId, producerEpoch %7D
+const result
  = a
@@ -1218,17 +1218,93 @@
 ,%0A    %7D)
-)
+%0A%0A    producerId = result.producerId%0A    producerEpoch = result.producerEpoch
 %0A  %7D)%0A%0A 

Remove corner case for semicolon on initProducerId broker tests