diff --git a/packages/pubsub/src/lib/client.ts b/packages/pubsub/src/lib/client.ts index de35d68b..a3d484f3 100644 --- a/packages/pubsub/src/lib/client.ts +++ b/packages/pubsub/src/lib/client.ts @@ -5,15 +5,10 @@ export type ClientConfig = { projectId: string } -const localProjectId: string = 'local' +const localProjectId = 'local' const clients: Record = {} -const init = (config?: ClientConfig) => { - let projectId: string = localProjectId - if (config && config.projectId) { - projectId = config.projectId - } - +const init = ({ projectId }: ClientConfig = { projectId: localProjectId }) => { if (!clients[projectId]) { if (projectId === localProjectId) { // Create a default client when there is no config. diff --git a/packages/pubsub/src/lib/pubsub.spec.ts b/packages/pubsub/src/lib/pubsub.spec.ts index d06df1ac..02a96669 100644 --- a/packages/pubsub/src/lib/pubsub.spec.ts +++ b/packages/pubsub/src/lib/pubsub.spec.ts @@ -143,7 +143,9 @@ describe('creates an instance of PubSub', () => { await createdPubsub.topic(topicName, mockConfig).publish(topicData) - expect(PubSub).toHaveBeenCalledWith(mockConfig) + expect(PubSub).toHaveBeenCalledWith({ + projectId: mockConfig.projectId, + }) }) it('when subscribing', async () => { @@ -154,7 +156,9 @@ describe('creates an instance of PubSub', () => { onSuccess: () => undefined, }) - expect(PubSub).toHaveBeenCalledWith(mockConfig) + expect(PubSub).toHaveBeenCalledWith({ + projectId: mockConfig.projectId, + }) }) }) })