testing

In this section

Type Aliases

MockItemSpec

type MockItemSpec = 
  | {
  alsoFulfills?: readonly string[];
  fhir: unknown;
  fhirVersion?: string;
}
  | {
  alsoFulfills?: readonly string[];
  healthCard: readonly string[];
}
  | {
  message?: string;
  status: SmartCheckinItemStatus["status"];
};

Defined in: src/testing/mock.ts:26

What the mock wallet should return for one requested item.

Tests usually want to pin exact data ("this allergy list, missing its reaction") or exercise a non-happy status, so both are first-class.

Union Members

Type Literal
{
  alsoFulfills?: readonly string[];
  fhir: unknown;
  fhirVersion?: string;
}

Return this FHIR resource or Bundle for the item. alsoFulfills names other request items this same artifact satisfies — one bundle answering a "clinical summary" item and an "allergies" item at once, say — and those items are then reported fulfilled without an artifact of their own.


Type Literal
{
  alsoFulfills?: readonly string[];
  healthCard: readonly string[];
}

Return a SMART Health Card artifact carrying these JWS strings.


Type Literal
{
  message?: string;
  status: SmartCheckinItemStatus["status"];
}

Report a status with no artifact — declined, unavailable, error, …


MockItemSpecs

type MockItemSpecs = 
  | MockItemSpec
  | readonly MockItemSpec[];

Defined in: src/testing/mock.ts:40

One item can be answered by several artifacts: give it a list.


MockWalletOptions

type MockWalletOptions = {
  fallback?: "fabricate" | MockItemSpec;
  items?: Record<string, MockItemSpecs>;
  origin: string;
  respond?: (request) => SmartCheckinResponse;
};

Defined in: src/testing/mock.ts:43

What the mock wallet answers. mockWallet takes these, with origin optional.

Properties

fallback?
optional fallback?: "fabricate" | MockItemSpec;

Defined in: src/testing/mock.ts:66

What to do with items items doesn't mention: "fabricate" (default) invents plausible demo data; a spec applies that spec to all of them.

items?
optional items?: Record<string, MockItemSpecs>;

Defined in: src/testing/mock.ts:61

Exactly what to return, per request item id. Anything not named here follows fallback.

createMockWalletCredentialGetter({
  origin: location.origin,
  items: {
    allergies: { fhir: myAllergyBundle },
    coverage: { status: "declined" },
  },
  fallback: { status: "unavailable" },
});
origin
origin: string;

Defined in: src/testing/mock.ts:45

The EHR origin the response is bound to; mockWallet defaults it to location.origin.

respond?
optional respond?: (request) => SmartCheckinResponse;

Defined in: src/testing/mock.ts:68

Full manual control: build the entire response yourself.

Parameters
Parameter Type
request SmartCheckinRequest
Returns

SmartCheckinResponse

Variables

DEMO_HEALTH_CARD_JWS

const DEMO_HEALTH_CARD_JWS: "eyJ6aXAiOiJERUYiLCJhbGciOiJFUzI1NiIsImtpZCI6Im1vY2sta2V5In0.fZHNjtQwEIRfZVVcnZkkGmbAR1gkQFqB-Lus5tBxOhsjx4nszrBR5HdHDquBw4pj293V9VWvsDFCoxeZot7vf5FzLDt-pGFyvG95GKHgmw66Oh1Pdf3yWJYKFwO9QpaJoe-vw3GgID2Tk35nKLTxxZ-iyAXOCiZwy14sua9z85ONZJWut-EHh2hHD43DrtxVUNvrm9m3jnNP4DjOwfC3bSOePtSTA5jROTaSFRTYS1ig71d0s3Pfg4O-zusS6lo8I_yZxLKXjExDZlvR0WDdAo0vvHCEwoO9sM_YH8fQksc5nRUaG6S_Jcki1etXh6I8FmWNlNSzNjLhf2y8HS8c6CETRiGZ84XIiL38ZV4h_CjQuOVhvHm_5XwzOfJICnFuogm24fChzS3v7j4Vh0N1gkLDnjtrLOWM8uKOA_vs4t-QksJEyxi2BFobJ0c5gm3X3SwzOWTqiYMd26wThUJ2U5f1sSiroqyQUjqnlNJv.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" = "eyJ6aXAiOiJERUYiLCJhbGciOiJFUzI1NiIsImtpZCI6Im1vY2sta2V5In0.fZHNjtQwEIRfZVVcnZkkGmbAR1gkQFqB-Lus5tBxOhsjx4nszrBR5HdHDquBw4pj293V9VWvsDFCoxeZot7vf5FzLDt-pGFyvG95GKHgmw66Oh1Pdf3yWJYKFwO9QpaJoe-vw3GgID2Tk35nKLTxxZ-iyAXOCiZwy14sua9z85ONZJWut-EHh2hHD43DrtxVUNvrm9m3jnNP4DjOwfC3bSOePtSTA5jROTaSFRTYS1ig71d0s3Pfg4O-zusS6lo8I_yZxLKXjExDZlvR0WDdAo0vvHCEwoO9sM_YH8fQksc5nRUaG6S_Jcki1etXh6I8FmWNlNSzNjLhf2y8HS8c6CETRiGZ84XIiL38ZV4h_CjQuOVhvHm_5XwzOfJICnFuogm24fChzS3v7j4Vh0N1gkLDnjtrLOWM8uKOA_vs4t-QksJEyxi2BFobJ0c5gm3X3SwzOWTqiYMd26wThUJ2U5f1sSiroqyQUjqnlNJv.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";

Defined in: src/testing/mock.ts:193


DEMO_WALLET_REGISTRY

const DEMO_WALLET_REGISTRY: WalletRegistry;

Defined in: src/testing/index.ts:27

This project's demo web wallet, for demos.

Functions

buildMockResponse()

function buildMockResponse(request, options?): SmartCheckinResponse;

Defined in: src/testing/mock.ts:75

Build a response from a per-item specification. Exported so tests can assert on the response without going through the wire layer at all.

Parameters

Parameter Type
request SmartCheckinRequest
options Pick<MockWalletOptions, "items" | "fallback">

Returns

SmartCheckinResponse


fabricateResponse()

function fabricateResponse(request, include?): SmartCheckinResponse;

Defined in: src/testing/mock.ts:197

Made-up data for every item of any request (or only the items include accepts), as a plain SMART response.

Parameters

Parameter Type
request SmartCheckinRequest
include? (itemId) => boolean

Returns

SmartCheckinResponse


mockWallet()

function mockWallet(options?): Wallet;

Defined in: src/testing/index.ts:13

A wallet that answers at once with the data you specify, or plausible fabricated data.

Parameters

Parameter Type
options Omit<MockWalletOptions, "origin"> & { origin?: string; }

Returns

Wallet