Skip to content

Commit

Permalink
refactor: simplify client
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Czigler committed Aug 11, 2023
1 parent b868ede commit d6d7b90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 2 additions & 7 deletions packages/pubsub/src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ export type ClientConfig = {
projectId: string
}

const localProjectId: string = 'local'
const localProjectId = 'local'
const clients: Record<string, PubSub> = {}

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.
Expand Down
8 changes: 6 additions & 2 deletions packages/pubsub/src/lib/pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -154,7 +156,9 @@ describe('creates an instance of PubSub', () => {
onSuccess: () => undefined,
})

expect(PubSub).toHaveBeenCalledWith(mockConfig)
expect(PubSub).toHaveBeenCalledWith({
projectId: mockConfig.projectId,
})
})
})
})
Expand Down

0 comments on commit d6d7b90

Please sign in to comment.