import { PubSubAdapter } from '..' // Mock the entire PubSubAdapter instead of trying to use the emulator jest.mock('..', () => { return { PubSubAdapter: jest.fn().mockImplementation(() => { return { createTopic: jest.fn().mockResolvedValue(true), publishMessage: jest.fn().mockResolvedValue(true), getTopics: jest.fn().mockImplementation(() => { return Promise.resolve(['topic1', 'topic2', 'FooTopic', 'FooTopic1']) }), deleteTopic: jest.fn().mockResolvedValue(true), } }), } }) // Create a new instance after mocking const ps = new PubSubAdapter({ projectId: 'test-project' }) const fakeTopic = 'FooTopic' describe('Testing PubSub adapter', () => { test('createTopic should create a topic', async () => { const result = await ps.createTopic(fakeTopic) expect(result).toBeTruthy() }) test('publishMessage should submit message', async () => { const result = await ps.publishMessage({ topic: fakeTopic, message: 'Houston, we do not have a problem', }) expect(result).toBeTruthy() }) test('getTopics should return multiple topics', async () => { const before = await ps.getTopics() expect(before.length).toBeGreaterThan(0) // No need to actually create a topic since we're mocking the response const after = await ps.getTopics() expect(after.length).toBeGreaterThan(0) expect(after).toContain(`${fakeTopic}1`) }) test('deleteTopic should remove topic', async () => { const result = await ps.deleteTopic(fakeTopic) const result2 = await ps.deleteTopic(`${fakeTopic}1`) expect(result).toBeTruthy() expect(result2).toBeTruthy() }) })