Skip to content

Commit

Permalink
fix(combine-adapters): status to connect underlying adapters (#1791)
Browse files Browse the repository at this point in the history
* fix(combine-adapters): status to connect underlying adapters

* Create moody-beds-rhyme.md
  • Loading branch information
tdeekens authored Aug 20, 2023
1 parent 98bcb9d commit e109d68
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-beds-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@flopflip/combine-adapters": patch
---

fix(combine-adapters): status to connect underlying adapters
50 changes: 40 additions & 10 deletions packages/combine-adapters/src/adapter/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,48 @@ describe('when combining', () => {
});

it('should resolve `waitUntilConfigured`', async () => {
await expect(adapter.waitUntilConfigured()).resolves.not.toBeDefined();
await expect(adapter.waitUntilConfigured()).resolves.toBeDefined();
});

it('should invoke `onStatusStateChange` with configured', () => {
expect(adapterEventHandlers.onStatusStateChange).toHaveBeenCalledWith(
expect.objectContaining({
id: adapter.id,
status: {
configurationStatus: AdapterConfigurationStatus.Configured,
},
})
);
describe('invokcation of `onStatusStateChange`', () => {
describe('of `combine-adapters`', () => {
it('should invoke `onStatusStateChange` with configured', () => {
expect(adapterEventHandlers.onStatusStateChange).toHaveBeenCalledWith(
expect.objectContaining({
id: adapter.id,
status: {
configurationStatus: AdapterConfigurationStatus.Configured,
},
})
);
});
});

describe('of `memory-adapter`', () => {
it('should invoke `onStatusStateChange` with configured', () => {
expect(adapterEventHandlers.onStatusStateChange).toHaveBeenCalledWith(
expect.objectContaining({
id: memoryAdapter.id,
status: {
configurationStatus: AdapterConfigurationStatus.Configured,
},
})
);
});
});

describe('of `localstorage-adapter`', () => {
it('should invoke `onStatusStateChange` with configured', () => {
expect(adapterEventHandlers.onStatusStateChange).toHaveBeenCalledWith(
expect.objectContaining({
id: localstorageAdapter.id,
status: {
configurationStatus: AdapterConfigurationStatus.Configured,
},
})
);
});
});
});

it('should invoke `onFlagsStateChange`', () => {
Expand Down
18 changes: 5 additions & 13 deletions packages/combine-adapters/src/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class CombineAdapters implements TCombinedAdapterInterface {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return adapter.configure(adapterArgsForAdapter, {
onFlagsStateChange: adapterEventHandlers.onFlagsStateChange,
onStatusStateChange: () => undefined,
onStatusStateChange: adapterEventHandlers.onStatusStateChange,
});
})
).then((allInitializationStatus) => {
Expand Down Expand Up @@ -192,7 +192,7 @@ class CombineAdapters implements TCombinedAdapterInterface {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
return adapter.reconfigure(adapterArgsForAdapter, {
onFlagsStateChange: adapterEventHandlers.onFlagsStateChange,
onStatusStateChange: () => undefined,
onStatusStateChange: adapterEventHandlers.onStatusStateChange,
});
})
).then((allInitializationStatus) => {
Expand Down Expand Up @@ -229,17 +229,9 @@ class CombineAdapters implements TCombinedAdapterInterface {
};

async waitUntilConfigured() {
return new Promise<void>((resolve) => {
if (
this.getIsConfigurationStatus(AdapterConfigurationStatus.Configured)
) {
resolve();
} else
this.#adapterState.emitter.on(
this.#__internalConfiguredStatusChange__,
resolve
);
});
return Promise.all(
this.#adapters.map(async (adapter) => adapter?.waitUntilConfigured?.())
);
}

unsubscribe = () => {
Expand Down

0 comments on commit e109d68

Please sign in to comment.