Skip to content

Commit

Permalink
Make getClientVersions public (matrix-org#74)
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Sand <[email protected]>

Signed-off-by: Oliver Sand <[email protected]>
  • Loading branch information
Fox32 authored Jan 26, 2023
1 parent ebef6dd commit 1f378c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/WidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ export class WidgetApi extends EventEmitter {
});
}

private getClientVersions(): Promise<ApiVersion[]> {
public getClientVersions(): Promise<ApiVersion[]> {
if (Array.isArray(this.cachedClientVersions)) {
return Promise.resolve(this.cachedClientVersions);
}
Expand Down
30 changes: 30 additions & 0 deletions test/WidgetApi-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,34 @@ describe('WidgetApi', () => {
)).rejects.toThrow('An error occurred');
});
});

describe('getClientVersions', () => {
beforeEach(() => {
jest.mocked(PostmessageTransport.prototype.send).mockResolvedValueOnce(
{
supported_versions: [
UnstableApiVersion.MSC3869, UnstableApiVersion.MSC2762,
],
} as ISupportedVersionsActionResponseData,
);
})

it('should request supported client versions', async () => {
await expect(widgetApi.getClientVersions()).resolves.toEqual([
'org.matrix.msc3869', 'org.matrix.msc2762',
]);
})

it('should cache supported client versions on successive calls', async () => {
await expect(widgetApi.getClientVersions()).resolves.toEqual([
'org.matrix.msc3869', 'org.matrix.msc2762',
]);

await expect(widgetApi.getClientVersions()).resolves.toEqual([
'org.matrix.msc3869', 'org.matrix.msc2762',
]);

expect(PostmessageTransport.prototype.send).toBeCalledTimes(1);
})
});
});

0 comments on commit 1f378c7

Please sign in to comment.