Skip to content

Commit

Permalink
Fixed tests, allowing separate apis
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Dec 1, 2023
1 parent d0de9cd commit 5a8ba1c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/testing/dist/cucumber-report.html

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions packages/testing/test/features/user-channels.feature
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Feature: Basic User Channels Support

Background: Desktop Agent API
Given A Basic API Setup
Given A Desktop Agent in "api"
Given "instrumentMessageOne" is a "fdc3.instrument" broadcastRequest message on channel "one"

Scenario: List User Channels

There should be a selection of user channels to choose from

When I call the API "getUserChannels"
When I call "api" with "getUserChannels"
Then "result" is an array of objects with the following contents
| id | type | displayMetadata.color |
| one | user | red |
Expand All @@ -19,31 +19,31 @@ Background: Desktop Agent API

At startup, the user channel shouldn't be set

When I call the API "getCurrentChannel"
When I call "api" with "getCurrentChannel"
Then "result" is null

Scenario: Changing Channel

You should be able to join a channel knowing it's ID.

When I call the API "joinUserChannel" with parameter "one"
When I call the API "getCurrentChannel"
When I call "api" with "joinUserChannel" with parameter "one"
When I call "api" with "getCurrentChannel"
Then "result" is an object with the following contents
| id | type | displayMetadata.color |
| one | user | red |

Scenario: Adding a Listener on a given User Channel
Given "resultHandler" pipes context to "contexts"
When I call the API "joinUserChannel" with parameter "one"
And I call the API "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
When I call "api" with "joinUserChannel" with parameter "one"
And I call "api" with "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
And messaging receives "{instrumentMessageOne}"
Then "contexts" is an array of objects with the following contents
| id.ticker | type | name |
| AAPL | fdc3.instrument | Apple |

Scenario: If you haven't joined a channel, your listener receives nothing
Given "resultHandler" pipes context to "contexts"
When I call the API "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
When I call "api" with "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
And messaging receives "{instrumentMessageOne}"
Then "contexts" is empty

Expand All @@ -53,8 +53,8 @@ Background: Desktop Agent API

Given "resultHandler" pipes context to "contexts"
When messaging receives "{instrumentMessageOne}"
And I call the API "joinUserChannel" with parameter "one"
And I call the API "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
And I call "api" with "joinUserChannel" with parameter "one"
And I call "api" with "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
Then "contexts" is an array of objects with the following contents
| id.ticker | type | name |
| AAPL | fdc3.instrument | Apple |
Expand All @@ -66,8 +66,13 @@ Background: Desktop Agent API

Given "resultHandler" pipes context to "contexts"
When messaging receives "{instrumentMessageOne}"
And I call the API "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
And I call the API "joinUserChannel" with parameter "one"
And I call "api" with "addContextListener" with parameters "fdc3.instrument" and "{resultHandler}"
And I call "api" with "joinUserChannel" with parameter "one"
Then "contexts" is an array of objects with the following contents
| id.ticker | type | name |
| AAPL | fdc3.instrument | Apple |
| AAPL | fdc3.instrument | Apple |


Scenario: Rejoining a channel shouldn't replay context already seen


29 changes: 15 additions & 14 deletions packages/testing/test/step-definitions/generic.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { DataTable, Given, Then, When } from '@cucumber/cucumber'
import expect from 'expect';
import { doesRowMatch, handleResolve, indexOf } from '../support/matching';

Given('A Basic API Setup', function () {
Given('A Desktop Agent in {string}', function (field: string) {

this.messaging = new TestMessaging()
this.defaultChannels = createDefaultChannels(this.messaging);
if (!this.messaging) {
this.messaging = new TestMessaging();
}

this.desktopAgent = new BasicDesktopAgent(
new DefaultChannelSupport(this.messaging, this.defaultChannels, null),
this[field] = new BasicDesktopAgent(
new DefaultChannelSupport(this.messaging, createDefaultChannels(this.messaging), null),
new DefaultIntentSupport(),
new DefaultAppSupport(),
"2.0",
Expand All @@ -24,25 +25,25 @@ Given('A Basic API Setup', function () {
this.result = null
})

When('I call the API {string}', async function (fnName: string) {
const fn = this.desktopAgent[fnName];
const result = await fn.call(this.desktopAgent)
When('I call {string} with {string}', async function (field: string, fnName: string) {
const fn = this[field][fnName];
const result = await fn.call(this[field])
if (result) {
this.result = result;
}
})

When('I call the API {string} with parameter {string}', async function (fnName: string, param: string) {
const fn = this.desktopAgent[fnName];
const result = await fn.call(this.desktopAgent, handleResolve(param, this))
When('I call {string} with {string} with parameter {string}', async function (field: string, fnName: string, param: string) {
const fn = this[field][fnName];
const result = await fn.call(this[field], handleResolve(param, this))
if (result) {
this.result = result;
}
})

When('I call the API {string} with parameters {string} and {string}', async function (fnName: string, param1: string, param2: string) {
const fn = this.desktopAgent[fnName];
const result = await fn.call(this.desktopAgent, handleResolve(param1, this), handleResolve(param2, this))
When('I call {string} with {string} with parameters {string} and {string}', async function (field: string, fnName: string, param1: string, param2: string) {
const fn = this[field][fnName];
const result = await fn.call(this[field], handleResolve(param1, this), handleResolve(param2, this))
if (result) {
this.result = result;
}
Expand Down

0 comments on commit 5a8ba1c

Please sign in to comment.