testing

@prismatic-io/spectral"testing"

Index#

Interfaces#

Functions#

Object literals#

Functions#

Const getAuthorizationMethods#

getAuthorizationMethods(except?: AuthorizationMethod[]): AuthorizationMethod[]

Return listing of available authorization methods. If except is provided the returned list will be any authorization methods not in that list.

Parameters:

NameType
except?AuthorizationMethod[]

Returns: AuthorizationMethod[]


Const invoke#

invokeTReturn›(action: ActionDefinition | Record‹string, ActionDefinition›, params: ActionInputParameters, context?: Partial‹ActionContext›): Promise‹InvokeResult‹TReturn››

Invokes specified ActionDefinition perform function using supplied params and optional context. Accepts a generic type matching PerformReturn as a convenience to avoid extra casting within test methods. Returns an InvokeResult containing both the action result and a mock logger for asserting logging.

Type parameters:

TReturn: PerformReturn

Parameters:

NameType
actionActionDefinition | Record‹string, ActionDefinition
paramsActionInputParameters
context?Partial‹ActionContext

Returns: Promise‹InvokeResult‹TReturn››


Const loggerMock#

loggerMock(): ActionLogger

Pre-built mock of ActionLogger. Suitable for asserting logs are created as expected.

Returns: ActionLogger

Object literals#

Const credentials#

credentials: object#

Utility functions to generate the different types of Credentials.

apiKey#

apiKey(key: string): ApiKeyCredential

Return a ApiKeyCredential assembled from provided key.

Parameters:

NameType
keystring

Returns: ApiKeyCredential

apiKeySecret#

apiKeySecret(key: string, secret: string): ApiKeySecretCredential

Return a ApiKeySecretCredential assembled from provided key and secret.

Parameters:

NameType
keystring
secretstring

Returns: ApiKeySecretCredential

basic#

basic(username: string, password: string): BasicCredential

Return a BasicCredential assembled from provided username and password.

Parameters:

NameType
usernamestring
passwordstring

Returns: BasicCredential

generate#

generate(method: AuthorizationMethod): Credential

Returns an arbitrary Credential using method. Generally used for testing negative support cases.

Parameters:

NameType
methodAuthorizationMethod

Returns: Credential

oauth2#

oauth2(token: string, redirectUri: string): OAuth2Credential

Return a OAuth2Credential assembled from provided token and optional redirectUri.

Parameters:

NameTypeDefault
tokenstring-
redirectUristring""

Returns: OAuth2Credential

oauth2ClientCredentials#

oauth2ClientCredentials(token: string): OAuth2Credential

Return a OAuth2Credential assembled from provided token.

Parameters:

NameType
tokenstring

Returns: OAuth2Credential

privateKey#

privateKey(username: string, privateKey: string): PrivateKeyCredential

Return a PrivateKeyCredential assembled from provided username and privateKey.

Parameters:

NameType
usernamestring
privateKeystring

Returns: PrivateKeyCredential