maxgui/tests/unit/utils.js
/**
 * This function tests if PATCH request is sent with accurate
 * endpoint and payload data. Notice: mounted component must have
 * dispatchRelationshipUpdate method
 * @param {Object} payload.wrapper mounted component
 * @param {Object} payload.currentResource target resource to be updated
 * @param {Object} payload.axiosPatchStub axios stub to be tested
 * @param {String} payload.relationshipType type of relationship being updated
 */
This function tests if PATCH request is sent with accurate
endpoint and payload data. Notice: mounted component must have
dispatchRelationshipUpdate method
@param {Object} payload.wrapper mounted component
@param {Object} payload.currentResource target resource to be updated
@param {Object} payload.axiosPatchStub axios stub to be tested
@param {String} payload.relationshipType type of relationship being updated
This function tests if PATCH request is sent with accurate endpoint and payload data . Notice : mounted component must have dispatchRelationshipUpdate method @param { Object } payload . wrapper mounted component @param { Object } payload . currentResource target resource to be updated @param { Object } payload . axiosPatchStub axios stub to be tested @param { String } payload . relationshipType type of relationship being updated
async function testRelationshipUpdate({
    wrapper,
    currentResource,
    axiosPatchStub,
    relationshipType,
}) {
    const {
        id: currentResourceId,
        type: currentResourceType,
        relationships: {
            [relationshipType]: { data: currentData },
        },
    } = currentResource
    const dataStub = [...currentData, { id: 'test', relationshipType }]
    await wrapper.vm.dispatchRelationshipUpdate({ type: relationshipType, data: dataStub })
    await axiosPatchStub.should.have.been.calledWith(
        `/${currentResourceType}/${currentResourceId}/relationships/${relationshipType}`,
        {
            data: dataStub,
        }
    )
}
async function testRelationshipUpdate ( { wrapper , currentResource , axiosPatchStub , relationshipType , } ) { const { id : currentResourceId , type : currentResourceType , relationships : { [ relationshipType ] : { data : currentData } , } , } = currentResource const dataStub = [ ... currentData , { id : 'test' , relationshipType } ] await wrapper . vm . dispatchRelationshipUpdate ( { type : relationshipType , data : dataStub } ) await axiosPatchStub . should . have . been . calledWith ( ` ${ currentResourceType } ${ currentResourceId } ${ relationshipType } ` , { data : dataStub , } ) }
This function tests if PATCH request is sent with accurate
 endpoint and payload data.
This function tests if PATCH request is sent with accurate endpoint and payload data .