Skip to content

Commit

Permalink
Improving code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Mar 14, 2024
1 parent 165021c commit a21c8d1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 45 deletions.
30 changes: 7 additions & 23 deletions packages/da-server/src/directory/BasicDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Directory, DirectoryApp, DirectoryIntent } from "./DirectoryInterface"
import { Directory, DirectoryApp } from "./DirectoryInterface"
import { components } from '../directory-schema'

type schemas = components['schemas']
type DirectoryIntent = schemas['Intent'] & { intentName: string, appId: string }

export function genericResultTypeSame(a: string | undefined, b: string | undefined) {
if (a == b) {
Expand Down Expand Up @@ -27,23 +31,13 @@ export class BasicDirectory implements Directory {
this.allApps = apps
}

/** For retrieving intents */

retrieveIntents(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryIntent[] {
return this.retrieveAllIntents().filter(i => this.intentMatches(i, contextType, intentName, resultType))
}

intentMatches(i: DirectoryIntent, contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): boolean {
private intentMatches(i: DirectoryIntent, contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): boolean {
return ((intentName == undefined) || (i.intentName == intentName)) &&
((contextType == undefined) || (i.contexts.includes(contextType))) &&
(genericResultTypeSame(i.resultType, resultType))
}

retrieveAllIntents(): DirectoryIntent[] {
return this.allApps.flatMap(a => this.retrieveIntentsForApp(a))
}

retrieveIntentsForApp(a: DirectoryApp): DirectoryIntent[] {
private retrieveIntentsForApp(a: DirectoryApp): DirectoryIntent[] {
const lf = a.interop?.intents?.listensFor ?? {}
const lfa = Object.entries(lf)
const lfAugmented = lfa.map(([key, value]) => {
Expand All @@ -56,9 +50,6 @@ export class BasicDirectory implements Directory {
return lfAugmented
}


/** For retrieving apps */

retrieveApps(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryApp[] {
return this.retrieveAllApps()
.filter(a => this.retrieveIntentsForApp(a)
Expand All @@ -73,13 +64,6 @@ export class BasicDirectory implements Directory {
retrieveAllApps(): DirectoryApp[] {
return this.allApps
}

/**
* For FDC3 1.2, retreives by the name of the app
*/
retrieveAppsByName(name: string): DirectoryApp[] {
return this.retrieveAllApps().filter(a => a.name == name)
}
}


15 changes: 0 additions & 15 deletions packages/da-server/src/directory/DirectoryInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ export type DirectoryApp = schemas['Application'];

export interface Directory {

/** For retrieving intents */

//retrieveIntents(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryIntent[]

retrieveAllIntents(): DirectoryIntent[]


/** For retrieving apps */

retrieveApps(contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): DirectoryApp[]

retrieveAppsById(appId: string): DirectoryApp[]

retrieveAllApps(): DirectoryApp[]

/**
* For FDC3 1.2, retreives by the name of the app
*/
retrieveAppsByName(name: string): DirectoryApp[]

}
10 changes: 4 additions & 6 deletions packages/da-server/src/handlers/IntentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ class PendingIntent {
}

async accept(arg0: any): Promise<void> {
if (arg0.type == 'onAddIntentListener') {
const actual = createListenerRegistration(arg0)
if (matches(this.expecting, actual) && !this.complete) {
this.complete = true
forwardRequest(this.r, arg0.meta.source, this.sc, this.ih)
}
const actual = createListenerRegistration(arg0)
if (matches(this.expecting, actual) && !this.complete) {
this.complete = true
forwardRequest(this.r, arg0.meta.source, this.sc, this.ih)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ Feature: Find Intent API
| loanBook | fdc3.book | fdc3.loan |
| streamBook | fdc3.book | channel<chapter> |
| returnBook | fdc3.book | {empty} |
| streamAny | fdc3.book | channel |
And A newly instantiated FDC3 Server
And "App1/b1" registers an intent listener for "returnBook" with contextType "fdc3.book" and result type "channel<messages>"

Scenario: Failed Find Intents Request
Scenario: Unsuccessful Find Intents Request
When "App1/a1" finds intents with intent "loanBook" and contextType "fdc3.instrument" and result type "{empty}"
Then messaging will have outgoing posts
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | to.instanceId |
| findIntentResponse | loanBook | 0 | a1 |

Scenario: Unsuccessful Find Intents Request With Result Type
When "App1/a1" finds intents with intent "loanBook" and contextType "{empty}" and result type "unknownContext"
Then messaging will have outgoing posts
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | to.instanceId |
| findIntentResponse | loanBook | 0 | a1 |

Scenario: Successful Find Intents Request
When "App1/a1" finds intents with intent "loanBook" and contextType "{empty}" and result type "{empty}"
Then messaging will have outgoing posts
Expand All @@ -33,6 +40,12 @@ Feature: Find Intent API
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | msg.payload.appIntent.apps[0].appId | to.instanceId |
| findIntentResponse | streamBook | 1 | libraryApp | a1 |

Scenario: Successful Find Intents Request With an untyped Channel
When "App1/a1" finds intents with intent "streamAny" and contextType "{empty}" and result type "channel<spurious>"
Then messaging will have outgoing posts
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | msg.payload.appIntent.apps[0].appId | to.instanceId |
| findIntentResponse | streamAny | 1 | libraryApp | a1 |

Scenario: Find Intent includes results for a running app with intent listener
When "App1/a1" finds intents with intent "returnBook" and contextType "fdc3.book" and result type "{empty}"
Then messaging will have outgoing posts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Feature: Raising Intents
Given "libraryApp" is an app with the following intents
| Intent Name | Context Type | Result Type |
| returnBook | fdc3.book | {empty} |
And "unusedApp" is an app with the following intents
| Intent Name | Context Type | Result Type |
And A newly instantiated FDC3 Server
And "App1/a1" is opened
And "App1/b1" is opened
Expand All @@ -30,12 +32,14 @@ Feature: Raising Intents

Scenario: Raising An Intent To A Non-Running App
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "libraryApp"
And "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "unusedApp"
And "libraryApp/0" registers an intent listener for "returnBook" with contextType "fdc3.book" and result type "channel<messages>"
Then running apps will be
| appId | instanceId |
| App1 | a1 |
| App1 | b1 |
| libraryApp | 0 |
| unusedApp | 1 |
Then messaging will have outgoing posts
| msg.type | msg.payload.intent | to.instanceId | to.appId | msg.payload.context.type |
| raiseIntentRequest | returnBook | 0 | libraryApp | fdc3.book |
Expand Down

0 comments on commit a21c8d1

Please sign in to comment.