Skip to content

Commit

Permalink
Merge pull request #876 from finos/adding-missing-fn-to-method.ts
Browse files Browse the repository at this point in the history
Add missing createPrivateChannel and findInstances fns to Methods.ts
  • Loading branch information
kriswest authored Dec 7, 2022
2 parents dc42f96 + fca10bd commit e8d0248
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finos/fdc3",
"version": "2.0.0-beta.4",
"version": "2.0.0-beta.5",
"author": "Fintech Open Source Foundation (FINOS)",
"homepage": "https://fdc3.finos.org",
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions src/api/Methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Listener,
ImplementationMetadata,
AppMetadata,
PrivateChannel,
} from '..';

const DEFAULT_TIMEOUT = 5000;
Expand Down Expand Up @@ -157,6 +158,10 @@ export function leaveCurrentChannel(): Promise<void> {
return rejectIfNoGlobal(() => window.fdc3.leaveCurrentChannel());
}

export function createPrivateChannel(): Promise<PrivateChannel> {
return rejectIfNoGlobal(() => window.fdc3.createPrivateChannel());
}

export function getInfo(): Promise<ImplementationMetadata> {
return rejectIfNoGlobal(() => window.fdc3.getInfo());
}
Expand All @@ -165,6 +170,10 @@ export function getAppMetadata(app: AppIdentifier): Promise<AppMetadata> {
return rejectIfNoGlobal(() => window.fdc3.getAppMetadata(app));
}

export function findInstances(app: AppIdentifier): Promise<AppIdentifier[]> {
return rejectIfNoGlobal(() => window.fdc3.findInstances(app));
}

/**
* Compare numeric semver version number strings (in the form `1.2.3`).
*
Expand Down
34 changes: 33 additions & 1 deletion test/Methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
raiseIntent,
raiseIntentForContext,
versionIsAtLeast,
createPrivateChannel,
findInstances,
} from '../src';

const UnavailableError = new Error('FDC3 DesktopAgent not available at `window.fdc3`.');
Expand Down Expand Up @@ -52,10 +54,14 @@ beforeEach(() => {

describe('test ES6 module', () => {
describe('without `window.fdc3` global', () => {
test('open should reject', async () => {
test('open (via name) should reject', async () => {
await expect(open(expect.any(String))).rejects.toEqual(UnavailableError);
});

test('open (via AppIdentifier) should reject', async () => {
await expect(open(expect.any(Object))).rejects.toEqual(UnavailableError);
});

test('findIntent should reject', async () => {
await expect(findIntent(expect.any(String))).rejects.toEqual(UnavailableError);
});
Expand Down Expand Up @@ -113,6 +119,18 @@ describe('test ES6 module', () => {
test('getInfo should reject', async () => {
await expect(() => getInfo()).rejects.toEqual(UnavailableError);
});

test('createPrivateChannel should reject', async () => {
await expect(() => createPrivateChannel()).rejects.toEqual(UnavailableError);
});

test('findInstances should reject', async () => {
await expect(() => findInstances(expect.any(Object))).rejects.toEqual(UnavailableError);
});

test('getAppMetadata should reject', async () => {
await expect(() => getAppMetadata(expect.any(Object))).rejects.toEqual(UnavailableError);
});
});

describe('with `window.fdc3` global', () => {
Expand Down Expand Up @@ -283,6 +301,20 @@ describe('test ES6 module', () => {
expect(window.fdc3.getAppMetadata).toHaveBeenCalledTimes(1);
expect(window.fdc3.getAppMetadata).toHaveBeenCalledWith(dummyApp);
});

test('createPrivateChannel should delegate to window.fdc3.createPrivateChannel', async () => {
await createPrivateChannel();

expect(window.fdc3.createPrivateChannel).toHaveBeenCalledTimes(1);
});

test('findInstances should delegate to window.fdc3.findInstances', async () => {
const dummyApp = { appId: 'dummy' };
await findInstances(dummyApp);

expect(window.fdc3.findInstances).toHaveBeenCalledTimes(1);
expect(window.fdc3.findInstances).toHaveBeenCalledWith(dummyApp);
});
});

describe('fdc3Ready', () => {
Expand Down

0 comments on commit e8d0248

Please sign in to comment.