Module: tests/utils/fixtures
Type Aliases
PageInfo
Ƭ PageInfo: Object
Type declaration
Name | Type |
---|---|
__typename | string |
endCursor | string |
hasNextPage | boolean |
hasPreviousPage | boolean |
startCursor | string |
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
Name | Type | Description |
---|---|---|
query | DocumentNode | The GraphQL query document. |
key | string | The key for the main data object. |
typename | string | The 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.
If the listKey
is set to edges
it will also map each data
element to { node: dataElement }
Parameters
Name | Type | Description |
---|---|---|
query | DocumentNode | The GraphQL query document. |
key | string | The key for the main data object. |
listKey | string | The key for the nested list. |
typename | string | The 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
Name | Type | Description |
---|---|---|
query | DocumentNode | The GraphQL query document. |
key | string | The key for the main data object. |
typename | string | The typename of the nodes in the list. |
resultProps | ComposeMockedListQueryResultProps | Props for composing a mocked list query result. |
pageInfo | Pick <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
Name | Type |
---|---|
T | extends DocumentNode |
Parameters
Name | Type |
---|---|
query | T |
«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
Name | Type | Description |
---|---|---|
length | number | The 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
Name | Type | Description |
---|---|---|
data | any [] | The array of data to map. |
typename | string | The typename of the nodes in the edges. |
pageInfo? | PageInfo | Optional PageInfo object. |
Returns
Object
The mapped Relay-style edges object.
Name | Type |
---|---|
edges | { cursor : string = defaultPageInfo.endCursor; node : any }[] |
pageInfo | { __typename : string = 'PageInfo'; endCursor : string = 'YXJyYXljb25uZWN0aW9uOjM='; hasNextPage : boolean = false } |
pageInfo.__typename | string |
pageInfo.endCursor | string |
pageInfo.hasNextPage | boolean |
Defined in
packages/webapp-libs/webapp-api-client/src/tests/utils/fixtures.ts:101