Skip to content

Commit

Permalink
Add jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bouk250 committed Sep 17, 2024
1 parent da17498 commit 981cd55
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/end_to_end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,5 +1284,49 @@ const Pulsar = require('../index');
await consumer.close();
await client.close();
});

test('AuthenticationToken token supplier', async () => {
const mockTokenSupplier = jest.fn().mockReturnValue('token');
const auth = new Pulsar.AuthenticationToken({
token: mockTokenSupplier,
});
const client = new Pulsar.Client({
serviceUrl: 'pulsar://localhost:6650',
authentication: auth,
});

// A producer/consumer is needed to triger the callback function
const topic = 'persistent://public/default/token-auth';
const producer = await client.createProducer({
topic,
});
expect(producer).not.toBeNull();
expect(mockTokenSupplier).toHaveBeenCalledTimes(1);

await producer.close();
await client.close();
});

test('AuthenticationToken async token supplier', async () => {
const mockTokenSupplier = jest.fn().mockResolvedValue('token');
const auth = new Pulsar.AuthenticationToken({
token: mockTokenSupplier,
});
const client = new Pulsar.Client({
serviceUrl: 'pulsar://localhost:6650',
authentication: auth,
});

// A producer/consumer is needed to triger the callback function
const topic = 'persistent://public/default/token-auth';
const producer = await client.createProducer({
topic,
});
expect(producer).not.toBeNull();
expect(mockTokenSupplier).toHaveBeenCalledTimes(1);

await producer.close();
await client.close();
});
});
})();

0 comments on commit 981cd55

Please sign in to comment.