|
1 | 1 | import { assert, expect, test, beforeEach, vi } from "vitest"; |
2 | 2 | import { AMQPClient } from '../src/amqp-socket-client.js'; |
| 3 | +import { AMQPWebSocketClient } from '../src/amqp-websocket-client.js'; |
3 | 4 | import { AMQPMessage } from '../src/amqp-message.js'; |
4 | 5 | import type { AMQPError } from "../src/amqp-error.js"; |
5 | 6 |
|
@@ -750,5 +751,84 @@ test('can bind queues in parallel', async () => { |
750 | 751 | q.bind('test-exchange', 'quux:*'), |
751 | 752 | ]) |
752 | 753 |
|
753 | | - await expect(Promise.resolve('success')).resolves.toBe('success') |
| 754 | + // Verify the test completed successfully - parallel binds worked without hanging |
| 755 | + expect(q.name).toBe('test-queue') |
| 756 | +}) |
| 757 | + |
| 758 | +test('should have no logger by default', () => { |
| 759 | + const amqp = getNewClient() |
| 760 | + expect(amqp.logger).toBeUndefined() |
| 761 | +}) |
| 762 | + |
| 763 | +test('should accept logger in AMQPClient constructor', () => { |
| 764 | + const mockLogger = { |
| 765 | + debug: vi.fn(), |
| 766 | + info: vi.fn(), |
| 767 | + warn: vi.fn(), |
| 768 | + error: vi.fn() |
| 769 | + } |
| 770 | + |
| 771 | + const amqp = new AMQPClient("amqp://127.0.0.1", undefined, mockLogger) |
| 772 | + expect(amqp.logger).toBe(mockLogger) |
| 773 | +}) |
| 774 | + |
| 775 | +test('should accept logger in AMQPWebSocketClient constructor', () => { |
| 776 | + const mockLogger = { |
| 777 | + debug: vi.fn(), |
| 778 | + info: vi.fn(), |
| 779 | + warn: vi.fn(), |
| 780 | + error: vi.fn() |
| 781 | + } |
| 782 | + |
| 783 | + const client = new AMQPWebSocketClient("wss://example.com/ws", undefined, undefined, undefined, undefined, undefined, undefined, mockLogger) |
| 784 | + expect(client.logger).toBe(mockLogger) |
| 785 | +}) |
| 786 | + |
| 787 | +test('should accept logger via AMQPWebSocketClient init object', () => { |
| 788 | + const mockLogger = { |
| 789 | + debug: vi.fn(), |
| 790 | + info: vi.fn(), |
| 791 | + warn: vi.fn(), |
| 792 | + error: vi.fn() |
| 793 | + } |
| 794 | + |
| 795 | + const client = new AMQPWebSocketClient({ |
| 796 | + url: "wss://example.com/ws", |
| 797 | + logger: mockLogger |
| 798 | + }) |
| 799 | + expect(client.logger).toBe(mockLogger) |
| 800 | +}) |
| 801 | + |
| 802 | +test('should not log when logger is null', () => { |
| 803 | + const amqp = getNewClient() |
| 804 | + |
| 805 | + // This should not throw even with null logger |
| 806 | + expect(() => { |
| 807 | + amqp.logger?.error("test message") |
| 808 | + amqp.logger?.warn("test message") |
| 809 | + amqp.logger?.info("test message") |
| 810 | + amqp.logger?.debug("test message") |
| 811 | + }).not.toThrow() |
| 812 | +}) |
| 813 | + |
| 814 | +test('should use provided logger when available', () => { |
| 815 | + const mockLogger = { |
| 816 | + debug: vi.fn(), |
| 817 | + info: vi.fn(), |
| 818 | + warn: vi.fn(), |
| 819 | + error: vi.fn() |
| 820 | + } |
| 821 | + |
| 822 | + const amqp = new AMQPClient("amqp://127.0.0.1", undefined, mockLogger) |
| 823 | + |
| 824 | + // Call logger methods directly (simulating how they're used in the code) |
| 825 | + amqp.logger?.error("error message") |
| 826 | + amqp.logger?.warn("warn message") |
| 827 | + amqp.logger?.info("info message") |
| 828 | + amqp.logger?.debug("debug message") |
| 829 | + |
| 830 | + expect(mockLogger.error).toHaveBeenCalledWith("error message") |
| 831 | + expect(mockLogger.warn).toHaveBeenCalledWith("warn message") |
| 832 | + expect(mockLogger.info).toHaveBeenCalledWith("info message") |
| 833 | + expect(mockLogger.debug).toHaveBeenCalledWith("debug message") |
754 | 834 | }) |
0 commit comments