Skip to main content

Module: tests/utils/fixtures

Type Aliases

PageInfo

Ƭ PageInfo: Object

Type declaration

NameType
__typenamestring
endCursorstring
hasNextPageboolean
hasPreviousPageboolean
startCursorstring

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:21

Functions

composeMockedListQueryResult

composeMockedListQueryResult(query, key, typename, «destructured»): MockedResponse<Record<string, any>, Record<string, any>>

Helper function that composes a mocked list query result. It extends composeMockedQueryResult functionality by mapping the data argument using mapRelayEdges.

Parameters

NameTypeDescription
queryDocumentNodeThe GraphQL query document.
keystringThe key for the main data object.
typenamestringThe typename of the nodes in the list.
«destructured»ComposeMockedListQueryResultProps-

Returns

MockedResponse<Record<string, any>, Record<string, any>>

The composed mocked list query result.

Example

const data = [
{ id: 1, name: 'First item' },
{ id: 2, name: 'Second item' },
];
const requestMock = composeMockedListQueryResult(crudDemoItemListQuery, 'allCrudDemoItems', 'CrudDemoItemType', {
data,
});

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:134


composeMockedNestedListQueryResult

composeMockedNestedListQueryResult(query, key, listKey, typename, «destructured»): MockedResponse<Record<string, any>, Record<string, any>>

Helper function that composes a mocked nested list query result. It is using composeMockedQueryResult and map data to { [key]: { [listKey]: data } }. Additionally it adds __typename value to each data element.

note

If the listKey is set to edges it will also map each data element to { node: dataElement }

Parameters

NameTypeDescription
queryDocumentNodeThe GraphQL query document.
keystringThe key for the main data object.
listKeystringThe key for the nested list.
typenamestringThe typename of the nodes in the list.
«destructured»ComposeMockedListQueryResultProps-

Returns

MockedResponse<Record<string, any>, Record<string, any>>

The composed mocked nested list query result.

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:168


composeMockedPaginatedListQueryResult

composeMockedPaginatedListQueryResult(query, key, typename, resultProps, pageInfo): MockedResponse<Record<string, any>, Record<string, any>>

Helper function that composes a mocked paginated list query result. It is using composeMockedListQueryResult function and adds additional pageInfo object to the result.

Parameters

NameTypeDescription
queryDocumentNodeThe GraphQL query document.
keystringThe key for the main data object.
typenamestringThe typename of the nodes in the list.
resultPropsComposeMockedListQueryResultPropsProps for composing a mocked list query result.
pageInfoPick<PageInfo, "endCursor" | "hasNextPage" | "startCursor" | "hasPreviousPage">PageInfo object for pagination.

Returns

MockedResponse<Record<string, any>, Record<string, any>>

The composed mocked paginated list query result.

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:200


composeMockedQueryResult

composeMockedQueryResult<T>(query, «destructured»): MockedResponse

Helper function that will compose given GraphQL query and other params like variables, data or errors into Apollo mock format that is used by MockedProvider. It will also wrap the result function with jest.fn which is required by waitForApolloMocks returned from render and renderHook methods.

Type parameters

NameType
Textends DocumentNode

Parameters

NameType
queryT
«destructured»ComposeMockedQueryResultProps

Returns

MockedResponse

Example

Example of confirm email mutation mock that is used in tests to mock successful query result:

   const requestMock = composeMockedQueryResult(authConfirmUserEmailMutation, {
variables: {
input: { user, token },
},
data: {
confirm: {
ok: true,
},
},
});

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:62


makeId

makeId(length): string

Generates a random ID string of the specified length.

Parameters

NameTypeDescription
lengthnumberThe length of the ID string to generate.

Returns

string

A random ID string.

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:11


mapRelayEdges

mapRelayEdges(data, typename, pageInfo?): Object

Maps an array of data to a Relay-style edges object.

Parameters

NameTypeDescription
dataany[]The array of data to map.
typenamestringThe typename of the nodes in the edges.
pageInfo?PageInfoOptional PageInfo object.

Returns

Object

The mapped Relay-style edges object.

NameType
edges{ cursor: string = defaultPageInfo.endCursor; node: any }[]
pageInfo{ __typename: string = 'PageInfo'; endCursor: string = 'YXJyYXljb25uZWN0aW9uOjM='; hasNextPage: boolean = false }
pageInfo.__typenamestring
pageInfo.endCursorstring
pageInfo.hasNextPageboolean

Defined in

packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:101