|
| 1 | +import { closeWindowOnCompletion, sendContextToTests, validateContext } from './mock-functions'; |
| 2 | +import { getAgent } from '@finos/fdc3'; |
| 3 | +import { IntentUtilityContext } from '../context-types'; |
| 4 | +import { ContextMetadata, IntentResult } from '@finos/fdc3'; |
| 5 | +import { ContextType, ControlContextType, Intent } from '../test/support/intent-support'; |
| 6 | + |
| 7 | +// Used in 'IntentContextMetadata' and 'IntentContextMetadataWithAppMetadata' conformance tests |
| 8 | +getAgent().then(async fdc3 => { |
| 9 | + await closeWindowOnCompletion(fdc3); |
| 10 | + |
| 11 | + fdc3.addIntentListener( |
| 12 | + Intent.lTestingIntent, |
| 13 | + async (context: IntentUtilityContext, metadata?: ContextMetadata): Promise<IntentResult> => { |
| 14 | + validateContext(fdc3, context.type, ContextType.testContextX); |
| 15 | + |
| 16 | + const { appMetadata } = await fdc3.getInfo(); |
| 17 | + |
| 18 | + const controlContext: Record<string, unknown> = { |
| 19 | + type: ControlContextType.A_TESTING_INTENT_LISTENER_TRIGGERED, |
| 20 | + instanceId: appMetadata.instanceId, |
| 21 | + }; |
| 22 | + |
| 23 | + if (metadata) { |
| 24 | + controlContext.contextMetadata = { |
| 25 | + source: metadata.source, |
| 26 | + timestamp: metadata.timestamp instanceof Date ? metadata.timestamp.toISOString() : String(metadata.timestamp), |
| 27 | + traceId: metadata.traceId, |
| 28 | + signature: metadata.signature, |
| 29 | + custom: metadata.custom, |
| 30 | + }; |
| 31 | + } |
| 32 | + |
| 33 | + await sendContextToTests(fdc3, controlContext as unknown as IntentUtilityContext); |
| 34 | + |
| 35 | + return; |
| 36 | + } |
| 37 | + ); |
| 38 | +}); |
0 commit comments