https://cypress.io logo
Using Cypress.add param on the reply of only part ...
# i-need-help
b
I created a command in Cypress.add which takes an array as a parameter and updates a cy.intercept response json body like so:
Copy code
Cypress.Commands.add('setExternalIds', (Array) => {
  cy.intercept(
    'GET',
    `**/${Cypress.env('API_BASE_URL')}/v2/divisions/*`,
    (req) => {
      req.reply({
        external_ids: Array,
        config: {
          entity_configurations: {
            entity: '82374982734',
          },
I only included part of the json body because the entire json body is 500 lines long and at least 10 levels of nesting. When I include the json body and I send a param, the param displays correctly in the network tab when running the Cypress test. I just don't like having these very long response bodies in my support/commands file How can I move them outside this support file? I would love a base fixture that I can iterate and edit parts of. If I nest the cy.intercept within a cy.fixture call, it does not update the external id value using a spread operator for the rest of the fixture body. I have tried variations of the code below and I don't think it will work with this deeply nested of a structure.
Copy code
Cypress.Commands.add('setExternalIds', (Array) => {
  cy.fixture('../../fixtures/SetupFiles/divisions')
    .then((response) => {
    cy.intercept(
      'GET',
       `**/${Cypress.env('API_BASE_URL')}/v2/divisions/*`,
         (req) => {
           req.reply({
             external_ids: Array,
             ...response
That said, how should I organize/store/call the remaining part of the reply? I could create multiple files within /support and keep the long response body, but have more organization around my different commands, but I'd like to know what other people are doing.