[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/fedex-shipping/2.1-graphql.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import {
  updateRetry,
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support'
import {
  getAppSettings,
  validateGetAppSettingsResponse,
  getDocks,
  validateGetDockConnectionResponse,
  saveAppSetting,
  validateSaveAppSettingResponse,
  updateDockConnection,
  validateUpdateDockConnectionResponse,
  verifyInventoryIsUnlimitedForFedexWareHouse,
  validateInventory,
  loadingDock,
  verifyDockisActive,
  warehouse,
  validateWareHouseIsActiveAndLinkedWithDocks,
} from '../../support/fedex-shipping/graphql_testcase'
import {
  appSetting,
  docks,
  warehouseId,
  Apache2020SkuId,
  Amacsa2020SkuId,
} from '../../support/fedex-shipping/outputvalidation'
import {
  FEDEX_SHIPPING_APP,
  INVENTORY_GRAPHQL_APP,
  LOGISTICS_CARRIER_GRAPHQL_APP,
} from '../../support/fedex-shipping/graphql_apps'
import { graphql } from '../../support/common/graphql_utils'

const prefix = 'Graphql testcase'

describe('FedEx GraphQL Validation', () => {
  loginViaCookies()

  it(`${prefix} - Get App Settings`, updateRetry(2), () => {
    cy.visit('/')
    graphql(FEDEX_SHIPPING_APP, getAppSettings(), (response) => {
      validateGetAppSettingsResponse(response)
      cy.setAppSettingstoJSON('config', response.body)
    })
  })

  it(`${prefix} - save App Settings`, updateRetry(2), () => {
    graphql(
      FEDEX_SHIPPING_APP,
      saveAppSetting(appSetting),
      validateSaveAppSettingResponse
    )
  })

  it('Get userAuthCookie and set cookie', updateRetry(2), () => {
    cy.qe('Getting user auth cookie and setting cookie')
    cy.getVtexItems().then((vtex) => {
      const cookieName = vtex.userAuthCookieName

      cy.getCookie(cookieName).then(({ value }) => {
        cy.setAppSettingstoJSON(cookieName, value)
      })
    })
  })

  it(`${prefix} - Update Dock Connection`, updateRetry(2), () => {
    for (const { id } of Object.values(docks)) {
      graphql(
        FEDEX_SHIPPING_APP,
        updateDockConnection(id, false),
        validateUpdateDockConnectionResponse
      )
    }
  })

  it(`${prefix} - Get Docks`, updateRetry(2), () => {
    graphql(
      FEDEX_SHIPPING_APP,
      getDocks(),
      validateGetDockConnectionResponse,
      Object.values(docks)
    )
  })

  it(`Verify by UI - Test Credentials`, () => {
    cy.qe('Visit admin fedex-shipping page')
    cy.visit('/admin/app/fedex-shipping')
    cy.get('#meter').should('be.visible').should('not.have.value', '')
    cy.qe("To verify test credentials click on 'Test Credentials' button")
    cy.contains('Test Credentials').should('be.visible').click()
    cy.qe("Once tested,it will show 'Success' popup")
    cy.contains('Success')
  })

  it(`${prefix} - For fedex docks, verify inventory is set to infinite`, () => {
    graphql(
      INVENTORY_GRAPHQL_APP,
      verifyInventoryIsUnlimitedForFedexWareHouse(warehouseId, Apache2020SkuId),
      validateInventory
    )
    graphql(
      INVENTORY_GRAPHQL_APP,
      verifyInventoryIsUnlimitedForFedexWareHouse(warehouseId, Amacsa2020SkuId),
      validateInventory
    )
  })

  it(`${prefix} - Fedex docks should be active`, () => {
    for (const { id } of Object.values(docks)) {
      graphql(
        LOGISTICS_CARRIER_GRAPHQL_APP,
        loadingDock(id),
        verifyDockisActive
      )
    }
  })

  it(`${prefix} - Fedex warehouse should be active and linked with fedex docks`, () => {
    graphql(
      LOGISTICS_CARRIER_GRAPHQL_APP,
      warehouse(warehouseId),
      validateWareHouseIsActiveAndLinkedWithDocks,
      Object.values(docks)
    )
  })

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/fedex-shipping/2.9-validate-shipping-from-different-origins.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/valid-expect */
/* eslint-disable jest/valid-expect-in-promise */
/* eslint-disable jest/expect-expect */
import { loginViaCookies, updateRetry } from '../../support/common/support.js'
import { data } from '../../fixtures/fedex-shipping-fixtures/shippingRatePayload.json'
import {
  loadCalculateShippingAPI,
  validateCalculateShipping,
} from '../../support/fedex-shipping/api_testcase.js'

describe('Validate Ship Rates API from different origins', () => {
  loginViaCookies()

  it(
    'For Non Supported Country - eg: Poland should get response with status code 500',
    updateRetry(5),
    () => {
      cy.qe('Validate invalid shipping address by giving poland address')
      cy.addDelayBetweenRetries(3000)
      data.destination = {
        zipCode: '00-005',
        country: 'PL',
        state: null,
        city: null,
        coordinates: null,
        residential: false,
      }
      loadCalculateShippingAPI(data).then((response) => {
        expect(response.status).to.have.equal(404)
      })
    }
  )

  it(
    'Use Shipment from Italy to USA(Supported country) ( Origin -> destination = ITA -> USA)',
    updateRetry(5),
    () => {
      cy.addDelayBetweenRetries(10000)
      data.destination = {
        zipCode: '33301',
        country: 'USA',
        state: null,
        city: null,
        coordinates: null,
        residential: false,
      }
      data.origin = {
        zipCode: '06010',
        country: 'ITA',
        state: null,
        city: null,
        coordinates: null,
        residential: false,
      }
      loadCalculateShippingAPI(data, validateCalculateShipping)
    }
  )

  it(
    'Use Shipment From USA(Supported country) to Italy ( Origin -> destination = USA -> ITA)',
    updateRetry(5),
    () => {
      cy.addDelayBetweenRetries(10000)
      data.destination = {
        zipCode: '06010',
        country: 'ITA',
        state: null,
        city: null,
        coordinates: null,
        residential: false,
      }
      data.origin = {
        zipCode: '33301',
        country: 'USA',
        state: null,
        city: null,
        coordinates: null,
        residential: false,
      }
      loadCalculateShippingAPI(data, validateCalculateShipping)
    }
  )
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.6.2-buyer_scenarios_orgA_costA2.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { ROLE_DROP_DOWN, STATUSES } from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import { verifySession } from '../../support/b2b/common.js'
import { createQuote, filterQuoteByStatus } from '../../support/b2b/quotes.js'
import {
  quickOrderByCategory,
  quickOrderByCategoryNegativeTestCase,
} from '../../support/quick-order/testcase.js'

describe('Organization A - Cost Center A2 - Buyer Scenarios', () => {
  loginViaCookies({ storeFrontCookie: false })
  const { users, costCenter2, quotes, product3, gmailCreds } = b2b.OrganizationA

  loginToStoreFront(users.Buyer2, ROLE_DROP_DOWN.Buyer, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter2.name, ROLE_DROP_DOWN.Buyer)
  quickOrderByCategory(ROLE_DROP_DOWN.Buyer, quotes.Buyer2.quotes1, '$84.60')
  quickOrderByCategoryNegativeTestCase(
    ROLE_DROP_DOWN.Buyer,
    quotes.Buyer2.quotes2,
    '$4,230.00'
  )
  createQuote({
    product: product3,
    quoteEnv: quotes.Buyer2.quotes3,
    role: ROLE_DROP_DOWN.Buyer,
  })
  filterQuoteByStatus(STATUSES.pending)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/wipe.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/no-conditional-expect */
/* eslint-disable jest/consistent-test-it */
/* eslint-disable jest/valid-expect */
import b2b from '../../support/b2b/constants.js'
import {
  loginViaCookies,
  updateRetry,
  preserveCookie,
} from '../../support/common/support.js'
import { deleteOrganization } from '../../support/b2b/graphql.js'

const config = Cypress.env()

// Constants
const { name } = config.workspace

// Define constants
const APP_NAME = 'vtex.b2b-organizations-graphql'
const APP_VERSION = '*.x'
const APP = `${APP_NAME}@${APP_VERSION}`

function deleteCostCenter(organization, costCenter) {
  it(`Delete ${costCenter.name} - ${organization}`, updateRetry(2), () => {
    cy.getVtexItems().then((vtex) => {
      const CUSTOM_URL = `${vtex.baseUrl}/_v/private/admin-graphql-ide/v0/${APP}`

      const GRAPHQL_DELETE_ORAGANIZATION_MUTATION =
        'mutation' + '($id: ID!)' + '{deleteCostCenter(id: $id){status}}'

      cy.getOrganizationItems().then((items) => {
        const costCenterId = items[costCenter.name]

        if (costCenterId) {
          cy.callGraphqlAndAddLogs({
            url: CUSTOM_URL,
            query: GRAPHQL_DELETE_ORAGANIZATION_MUTATION,
            variables: {
              id: costCenterId,
            },
          }).then((response) => {
            expect(response.status).to.equal(200)
            expect(response.body.data.deleteCostCenter.status).to.equal(
              'success'
            )
          })
        }
      })
    })
  })
}

function deleteUsers() {
  it('Delete users via graphql', updateRetry(5), () => {
    cy.getVtexItems().then((vtex) => {
      cy.url().then((url) => {
        if (url.includes('blank')) {
          cy.visit('/')
        }
      })
      const CUSTOM_URL = `${vtex.baseUrl}/_v/private/admin-graphql-ide/v0/${APP}`

      const GRAPHQL_DELETE_ORAGANIZATION_MUTATION =
        'mutation' +
        '($id: ID!,$email:String!,$clId: ID!)' +
        '{removeUser(id: $id,email:$email,clId:$clId){status}}'

      const GRAPHQL_GET_USERS_QUERY =
        'query' +
        '($pageSize: Int,$search: String)' +
        '{getUsersPaginated(pageSize: $pageSize,search: $search){data{id,email,clId}}}'

      cy.callGraphqlAndAddLogs({
        url: CUSTOM_URL,
        query: GRAPHQL_GET_USERS_QUERY,
        variables: {
          pageSize: 100,
          search: name,
        },
        headers: { VtexIdclientAutCookie: vtex.userAuthCookieValue },
      }).then((response) => {
        expect(response.status).to.equal(200)
        const clients = response.body.data.getUsersPaginated.data

        expect(clients).to.not.equal(null)
        if (clients.length > 0) {
          for (const { clId, id, email } of clients) {
            cy.callGraphqlAndAddLogs({
              url: CUSTOM_URL,
              query: GRAPHQL_DELETE_ORAGANIZATION_MUTATION,
              variables: {
                id,
                email,
                clId,
              },
            }).then((removeUserResponse) => {
              expect(removeUserResponse.status).to.equal(200)
              expect(removeUserResponse.body.data.removeUser.status).to.equal(
                'success'
              )
            })
          }
        }
      })
    })
  })
}

describe('Wipe datas', () => {
  const {
    organizationName: organizationA,
    costCenter1,
    costCenter2,
  } = b2b.OrganizationA

  const { organizationName: organizationB, costCenter1: costCenterB1 } =
    b2b.OrganizationB

  loginViaCookies({ storeFrontCookie: false })

  deleteUsers()
  deleteCostCenter(organizationA, costCenter1)
  deleteCostCenter(organizationA, costCenter2)
  deleteCostCenter(organizationB, costCenterB1)
  deleteOrganization(name)
  deleteOrganization(name, true)
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.13.1-sales_manager_scenarios.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_ID_EMAIL_MAPPING as roleObject,
  STATUSES,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
  userShouldNotImpersonateThisUser,
} from '../../support/b2b/common.js'
import { searchQuote, filterQuoteByStatus } from '../../support/b2b/quotes.js'
import { salesManagerQuotesAccess } from '../../support/b2b/impersonation_quote_access.js'

describe('Organization A - Cost Center A1 - Sales Manager Basic Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { nonAvailableProduct, users, costCenter1, quotes, gmailCreds } =
    b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(
    users.SalesManager,
    roleObject.SalesManager.role,
    gmailCreds
  )
  verifySession(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesManager.role
  )
  userShouldNotImpersonateThisUser(
    roleObject.SalesManager.role,
    roleObject.SalesRepresentative.role,
    users.SalesRep
  )
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  salesManagerQuotesAccess(b2b.OrganizationA, organizationB, organizationBQuote)

  searchQuote(quotes.OrganizationAdmin.quotes1)
  filterQuoteByStatus(STATUSES.pending)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.6.1-buyer_scenarios_orgA_costA2.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { ROLE_DROP_DOWN } from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
} from '../../support/b2b/common.js'
import { quoteShouldNotBeVisibleTestCase } from '../../support/b2b/quotes.js'

describe('Organization A - Cost Center A2 - Buyer Scenarios', () => {
  loginViaCookies({ storeFrontCookie: false })
  const {
    organizationName,
    nonAvailableProduct,
    users,
    costCenter2,
    quotes,
    gmailCreds,
  } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(users.Buyer2, ROLE_DROP_DOWN.Buyer, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter2.name, ROLE_DROP_DOWN.Buyer)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    quotes.OrganizationAdmin.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationBQuote.OrganizationAdmin.quotes1,
    organizationB
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.2.2-add_buyer_approver_organizationA.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import { addUser } from '../../support/b2b/add_users.js'
import {
  ROLE_DROP_DOWN,
  ROLE_DROP_DOWN_EMAIL_MAPPING as role,
} from '../../support/b2b/utils.js'
import {
  createQuote,
  // filterQuote,
  searchQuote,
} from '../../support/b2b/quotes.js'
import { verifyBindings } from '../../support/b2b/graphql.js'

describe('OrganizationA - Create a Buyer and Approver, associate Cost Center and assign payment terms', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    costCenter1,
    costCenter2,
    users,
    product,
    quotes,
    gmailCreds,
  } = b2b.OrganizationA

  verifyBindings(users.OrganizationAdmin1, true)

  loginToStoreFront(
    users.OrganizationAdmin1,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )

  addUser({
    organizationName,
    costCenter: costCenter1.name,
    role: role.Buyer1,
    gmailCreds,
  })
  addUser({
    organizationName,
    costCenter: costCenter1.name,
    role: role.Approver1,
    gmailCreds,
  })

  addUser({
    organizationName,
    costCenter: costCenter2.name,
    role: role.Buyer2,
    gmailCreds,
  })

  // Add/Delete users in costcenter1 - Hold
  // Add/Update users for costcenter2 - Hold bug

  addUser({
    organizationName,
    costCenter: costCenter2.name,
    role: role.OrganizationAdmin2,
    gmailCreds,
  })
  addUser({
    organizationName,
    costCenter: costCenter2.name,
    role: role.Approver2,
    gmailCreds,
  })

  createQuote({
    product,
    quoteEnv: quotes.OrganizationAdmin.quotes1,
    role: ROLE_DROP_DOWN.OrganizationAdmin,
  })
  searchQuote(quotes.OrganizationAdmin.quotes1)
  // filterQuote(costCenter1.name)
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.1.3-organization_negative_testcases.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { loginViaCookies } from '../../support/common/support.js'
import {
  createOrganizationWithInvalidEmail,
  createOrganizationWithoutName,
  createOrganizationWithoutCostCenterNameAndAddress,
} from '../../support/b2b/organization_request.js'
import b2b from '../../support/b2b/constants.js'

describe('Organization Negative TestCases', () => {
  loginViaCookies({ storeFrontCookie: false })
  const email = b2b.OrganizationA.users.OrganizationAdmin1

  createOrganizationWithoutCostCenterNameAndAddress(
    b2b.OrganizationA.organizationName,
    {
      costCenterName: b2b.OrganizationA.costCenter1.name,
      costCenterAddress: b2b.OrganizationA.costCenter1.addresses[0],
    },
    email
  )

  createOrganizationWithoutName(
    b2b.OrganizationA.organizationName,
    {
      costCenterName: b2b.OrganizationA.costCenter1.name,
      costCenterAddress: b2b.OrganizationA.costCenter1.addresses[0],
    },
    email
  )
  createOrganizationWithInvalidEmail(
    b2b.OrganizationA.organizationName,
    {
      costCenterName: b2b.OrganizationA.costCenter1.name,
      costCenterAddress: b2b.OrganizationA.costCenter1.addresses[0],
    },
    email
  )
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.8.2-organization_admin_scenarios-orgA.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { ROLE_DROP_DOWN, STATUSES } from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import { verifySession } from '../../support/b2b/common.js'
import {
  checkoutProduct,
  fillContactInfo,
  verifyAddress,
  verifyPayment,
  ordertheProduct,
} from '../../support/b2b/checkout.js'
import {
  // rejectQuote,
  filterQuoteByStatus,
} from '../../support/b2b/quotes.js'
import {
  quickOrderBySkuAndQuantityTestCase1,
  quickOrderBySkuAndQuantityTestCase2,
  quickOrderBySkuAnd51QuantityTestCase,
} from '../../support/quick-order/testcase.js'

describe('Organization A - Cost Center A1 - Organization Admin2 Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { product, costCenter2, users, quotes, gmailCreds } = b2b.OrganizationA

  loginToStoreFront(
    users.OrganizationAdmin2,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )
  verifySession(
    b2b.OrganizationA,
    costCenter2.name,
    ROLE_DROP_DOWN.OrganizationAdmin
  )
  quickOrderBySkuAndQuantityTestCase1(
    ROLE_DROP_DOWN.OrganizationAdmin,
    quotes.OrganizationAdmin2.quotes1,
    '$162.00'
  )
  quickOrderBySkuAndQuantityTestCase2(ROLE_DROP_DOWN.OrganizationAdmin)
  quickOrderBySkuAnd51QuantityTestCase(ROLE_DROP_DOWN.OrganizationAdmin)
  filterQuoteByStatus(STATUSES.declined)

  checkoutProduct(product)
  fillContactInfo()
  verifyAddress(costCenter2.addresses)
  verifyPayment(false)
  ordertheProduct(ROLE_DROP_DOWN.OrganizationAdmin)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.14.1-sales_rep_scenarios.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_ID_EMAIL_MAPPING as roleObject,
  STATUSES,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
  userShouldNotImpersonateThisUser,
} from '../../support/b2b/common.js'
import {
  searchQuote,
  updateQuote,
  filterQuoteByStatus,
} from '../../support/b2b/quotes.js'
import { salesRepQuotesAccess } from '../../support/b2b/impersonation_quote_access.js'

describe('Organization A - Cost Center A1 - Sales Rep Basic Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { nonAvailableProduct, users, costCenter1, quotes, gmailCreds } =
    b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(
    users.SalesRep,
    roleObject.SalesRepresentative.role,
    gmailCreds
  )
  verifySession(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesRepresentative.role
  )

  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  salesRepQuotesAccess(b2b.OrganizationA, organizationB, organizationBQuote)

  userShouldNotImpersonateThisUser(
    roleObject.SalesRepresentative.role,
    roleObject.SalesManager.role,
    users.SalesManager
  )
  searchQuote(quotes.SalesRep.updateQuote)
  const price = '30.00'

  updateQuote(quotes.SalesRep.updateQuote, { price })
  filterQuoteByStatus(STATUSES.revised)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.2.1-add_buyer_approver_organizationA.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  addPaymentTermsCollectionPriceTablesTestCase,
  setOrganizationIdInJSON,
} from '../../support/b2b/common.js'
import {
  addAddressinCostCenter,
  deleteCostCenter,
  addCostCenter,
  updateCostCenter,
  updatePaymentTermsinCostCenter,
} from '../../support/b2b/cost_center.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import { ROLE_DROP_DOWN, PAYMENT_TERMS } from '../../support/b2b/utils.js'
import { verifyBindings } from '../../support/b2b/graphql.js'

describe('OrganizationA - Create a Buyer and Approver, associate Cost Center and assign payment terms', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    costCenter1,
    costCenter2,
    costCenter3,
    users,
    gmailCreds,
  } = b2b.OrganizationA

  verifyBindings(users.OrganizationAdmin1, true)

  loginToStoreFront(
    users.OrganizationAdmin1,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )

  setOrganizationIdInJSON(organizationName, costCenter1.name)
  addPaymentTermsCollectionPriceTablesTestCase(b2b.OrganizationA)

  // CostCenter 2 - Scenarios
  addCostCenter(organizationName, costCenter2.name, costCenter2.addresses[0])
  updatePaymentTermsinCostCenter(
    organizationName,
    costCenter2.name,
    PAYMENT_TERMS.Promissory
  )
  addAddressinCostCenter(costCenter2.name, costCenter2.addresses[1])

  // // Cost Center 3 - Scenarios
  addCostCenter(
    organizationName,
    costCenter3.temporaryName,
    costCenter3.addresses[0]
  )
  updateCostCenter(costCenter3.temporaryName, costCenter3.name)
  deleteCostCenter(costCenter3.name)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.5.2-buyer_scenarios_orgA_costA1.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { ROLE_DROP_DOWN, STATUSES } from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import { verifySession } from '../../support/b2b/common.js'
import { createQuote, filterQuoteByStatus } from '../../support/b2b/quotes.js'
import {
  quickOrderByOneByOneTestCase,
  quickOrderByOneByOneNegativeTestCase,
} from '../../support/quick-order/testcase.js'

describe('Organization A - Cost Center A1 - Buyer Create Quote Scenarios', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { costCenter1, users, product, product2, quotes, gmailCreds } =
    b2b.OrganizationA

  loginToStoreFront(users.Buyer1, ROLE_DROP_DOWN.Buyer, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter1.name, ROLE_DROP_DOWN.Buyer)
  createQuote({
    product,
    quoteEnv: quotes.Buyer.quotes4,
    role: ROLE_DROP_DOWN.Buyer,
  })
  createQuote({
    product,
    quoteEnv: quotes.Buyer.quotes5,
    role: ROLE_DROP_DOWN.Buyer,
  })
  quickOrderByOneByOneTestCase(
    ROLE_DROP_DOWN.Buyer,
    product2,
    quotes.Buyer.quotes6,
    '$486.00'
  )
  quickOrderByOneByOneNegativeTestCase(
    ROLE_DROP_DOWN.Buyer,
    product2,
    quotes.Buyer.quotes7,
    '$24,300.00'
  )
  filterQuoteByStatus(STATUSES.ready)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.4.3-show_organization_by_adding_principal_sales_channel.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/valid-expect */
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { ROLE_DROP_DOWN } from '../../support/b2b/utils.js'
import b2b from '../../support/b2b/constants.js'
import {
  verifySalesChannel,
  verifyBindings,
  addBindingsWhichShowsOrganization,
} from '../../support/b2b/graphql.js'
import { loginToStoreFront } from '../../support/b2b/login.js'

const { users, gmailCreds } = b2b.OrganizationB

describe('Add binding which shows Organization in profile page', () => {
  loginViaCookies({ storeFrontCookie: false })

  addBindingsWhichShowsOrganization()

  verifySalesChannel(1)

  verifyBindings(users.OrganizationAdmin1, true)

  loginToStoreFront(
    users.OrganizationAdmin1,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )

  it('Verify Organization is showing up', updateRetry(2), () => {
    cy.organizationShouldShowInProfile()
  })

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.12.2-sales_admin_scenarios.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_ID_EMAIL_MAPPING as roleObject,
  ROLE_DROP_DOWN,
  // ROLE_DROP_DOWN_EMAIL_MAPPING as role,
  STATUSES,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  salesUserShouldImpersonateNonSalesUser,
  verifySession,
  stopImpersonation,
} from '../../support/b2b/common.js'
import {
  searchQuote,
  createQuote,
  // discountSliderShouldNotExist,
  updateQuote,
  // rejectQuote,
  // filterQuote,
  filterQuoteByStatus,
} from '../../support/b2b/quotes.js'
import { salesAdminQuotesAccess } from '../../support/b2b/impersonation_quote_access.js'

describe('Organization A - Cost Center A1 - Sales Admin Impersonation Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { product, costCenter1, users, quotes, gmailCreds } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  const impersonatedRole = ROLE_DROP_DOWN.Approver

  loginToStoreFront(users.SalesAdmin, roleObject.SalesAdmin.role, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter1.name, roleObject.SalesAdmin.role)

  salesUserShouldImpersonateNonSalesUser(
    roleObject.SalesAdmin.role,
    impersonatedRole,
    users.Approver1
  )

  updateQuote(quotes.Buyer.quotes1, { discount: '20' })
  updateQuote(quotes.Buyer.quotes2, { notes: 'Notes' })
  const price = '250.00'
  const quantity = '10'

  updateQuote(quotes.Buyer.quotes6, { price, quantity })
  filterQuoteByStatus(STATUSES.ready, STATUSES.declined)

  salesAdminQuotesAccess(b2b.OrganizationA, organizationB, organizationBQuote)

  const quote = 'IMPERSONATE_QUOTE_1'

  createQuote({
    product,
    quoteEnv: quote,
    role: roleObject.SalesManager.role,
    impersonatedRole,
  })
  searchQuote(quote, users.Approver1)
  stopImpersonation(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesAdmin.role
  )
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.13.2-sales_manager_scenarios.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_ID_EMAIL_MAPPING as roleObject,
  ROLE_DROP_DOWN,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  salesUserShouldImpersonateNonSalesUser,
  verifySession,
  stopImpersonation,
} from '../../support/b2b/common.js'
import { createQuote, searchQuote } from '../../support/b2b/quotes.js'
import { salesManagerQuotesAccess } from '../../support/b2b/impersonation_quote_access.js'

describe('Organization A - Cost Center A1 - Sales Manager Impersonation Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { users, product, costCenter1, gmailCreds } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(
    users.SalesManager,
    roleObject.SalesManager.role,
    gmailCreds
  )
  verifySession(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesManager.role
  )

  const impersonatedRole = ROLE_DROP_DOWN.OrganizationAdmin

  salesUserShouldImpersonateNonSalesUser(
    roleObject.SalesManager.role,
    impersonatedRole,
    users.OrganizationAdmin1
  )
  const quote = 'IMPERSONATE_QUOTE_2'

  salesManagerQuotesAccess(b2b.OrganizationA, organizationB, organizationBQuote)

  createQuote({
    product,
    quoteEnv: quote,
    role: roleObject.SalesManager.role,
    impersonatedRole,
  })
  searchQuote(quote, users.OrganizationAdmin1)
  stopImpersonation(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesManager.role
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.3-add_buyer_approver_organizationB.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  addPaymentTermsCollectionPriceTablesTestCase,
  setOrganizationIdInJSON,
} from '../../support/b2b/common.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import { addUser, duplicateUserTestCase } from '../../support/b2b/add_users.js'
import {
  ROLE_DROP_DOWN_EMAIL_MAPPING as role,
  ROLE_DROP_DOWN,
} from '../../support/b2b/utils.js'
import { createQuote } from '../../support/b2b/quotes.js'

describe('OrganizationB - Create a Buyer and Approver associate Cost Center and assign payment terms', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { organizationName, costCenter1, users, product, quotes, gmailCreds } =
    b2b.OrganizationB

  loginToStoreFront(
    users.OrganizationAdmin1,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )
  setOrganizationIdInJSON(organizationName, costCenter1.name)
  addPaymentTermsCollectionPriceTablesTestCase(b2b.OrganizationB)
  addUser({
    organizationName,
    costCenter: costCenter1.name,
    role: role.Buyer1,
    gmailCreds,
  })
  addUser({
    organizationName,
    costCenter: costCenter1.name,
    role: role.Approver1,
    gmailCreds,
  })
  duplicateUserTestCase({
    organizationName,
    costCenter: costCenter1.name,
    role: role.Approver1,
    gmailCreds,
  })
  createQuote({
    product,
    quoteEnv: quotes.OrganizationAdmin.quotes1,
    role: ROLE_DROP_DOWN.OrganizationAdmin,
  })
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.5.1-buyer_scenarios_orgA_costA1.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_DROP_DOWN_EMAIL_MAPPING as role,
  ROLE_DROP_DOWN,
  ROLE_ID_EMAIL_MAPPING as roleObject,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
  userAndCostCenterShouldNotBeEditable,
  userShouldNotImpersonateThisUser,
} from '../../support/b2b/common.js'
import {
  searchQuote,
  createQuote,
  quoteShouldbeVisibleTestCase,
  quoteShouldNotBeVisibleTestCase,
} from '../../support/b2b/quotes.js'

describe('Organization A - Cost Center A1 - Buyer Scenarios', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    nonAvailableProduct,
    costCenter1,
    users,
    product,
    quotes,
    gmailCreds,
  } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(users.Buyer1, ROLE_DROP_DOWN.Buyer, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter1.name, ROLE_DROP_DOWN.Buyer)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  userAndCostCenterShouldNotBeEditable({
    organizationName,
    costCenter: costCenter1.name,
    gmailCreds,
    role: role.Buyer1,
  })
  userShouldNotImpersonateThisUser(
    ROLE_DROP_DOWN.Buyer,
    roleObject.SalesManager.role,
    users.SalesManager
  )
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.OrganizationAdmin.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationBQuote.OrganizationAdmin.quotes1,
    organizationB
  )
  searchQuote(quotes.OrganizationAdmin.quotes1)
  createQuote({
    product,
    quoteEnv: quotes.Buyer.quotes1,
    role: ROLE_DROP_DOWN.Buyer,
  })
  createQuote(
    {
      product,
      quoteEnv: quotes.Buyer.quotes2,
      role: ROLE_DROP_DOWN.Buyer,
    },
    false
  )
  createQuote({
    product,
    quoteEnv: quotes.Buyer.quotes3,
    role: ROLE_DROP_DOWN.Buyer,
  })
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.12.1-sales_admin_scenarios.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_ID_EMAIL_MAPPING as roleObject,
  // ROLE_DROP_DOWN_EMAIL_MAPPING as role,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
  userShouldNotImpersonateThisUser,
} from '../../support/b2b/common.js'
import {
  searchQuote,
  verifyQuotesAndSavedCarts,
  // discountSliderShouldNotExist,
  // rejectQuote,
  // filterQuote,
} from '../../support/b2b/quotes.js'
import { salesAdminQuotesAccess } from '../../support/b2b/impersonation_quote_access.js'

describe('Organization A - Cost Center A1 - Sales Admin Basic Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { nonAvailableProduct, costCenter1, users, quotes, gmailCreds } =
    b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(users.SalesAdmin, roleObject.SalesAdmin.role, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter1.name, roleObject.SalesAdmin.role)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)

  // Impersonate users
  userShouldNotImpersonateThisUser(
    roleObject.SalesAdmin.role,
    roleObject.SalesManager.role,
    users.SalesManager
  )
  salesAdminQuotesAccess(b2b.OrganizationA, organizationB, organizationBQuote)

  verifyQuotesAndSavedCarts()
  searchQuote(quotes.Buyer.quotes1)

  // filterQuote(costCenter1.name, organizationB)

  // discountSliderShouldNotExist(quotes.Buyer2.quotes3)

  // rejectQuote(quotes.Buyer.quotes3, roleObject.SalesAdmin.role)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.1.1-create_&_approve_organizationA.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { loginViaCookies } from '../../support/common/support.js'
import { createOrganizationTestCase } from '../../support/b2b/organization_request.js'
import b2b from '../../support/b2b/constants.js'
import { deleteOrganization } from '../../support/b2b/graphql.js'

describe('Create & Approve OrganizationA', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { organizationName, costCenter1, users } = b2b.OrganizationA

  deleteOrganization(organizationName, true)
  deleteOrganization(organizationName)

  // Create and approve Organization A request
  createOrganizationTestCase(
    {
      name: organizationName,
      email: users.OrganizationAdmin1,
    },
    {
      costCenterName: costCenter1.name,
      costCenterAddress: costCenter1.addresses[0],
      approved: true,
    }
  )
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.9-approver_scenarios_orgA.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_DROP_DOWN,
  ROLE_DROP_DOWN_EMAIL_MAPPING as role,
  STATUSES,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
} from '../../support/b2b/common.js'
import {
  searchQuote,
  // rejectQuote,
  useQuoteForPlacingTheOrder,
  filterQuoteByStatus,
  quoteShouldbeVisibleTestCase,
  quoteShouldNotBeVisibleTestCase,
  verifyTotal,
} from '../../support/b2b/quotes.js'
import {
  quickOrderByXLS,
  // quickOrderByXLSNegativeTestCase,
} from '../../support/quick-order/testcase.js'
import {
  fillContactInfo,
  verifyAddress,
  verifyPayment,
} from '../../support/b2b/checkout.js'

describe('Organization A - Cost Center A1 - Approver Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    nonAvailableProduct,
    users,
    costCenter1,
    quotes,
    gmailCreds,
  } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBquotes } =
    b2b.OrganizationB

  loginToStoreFront(users.Approver1, ROLE_DROP_DOWN.Approver, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter1.name, ROLE_DROP_DOWN.Approver)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.OrganizationAdmin.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationBquotes.OrganizationAdmin.quotes1,
    organizationB
  )
  quickOrderByXLS(quotes.Approver.quotes1)
  // Negative test case not working
  // Ticket - https://vtex-dev.atlassian.net/browse/QUICKORDER-36
  // quickOrderByXLSNegativeTestCase(quotes.Approver.quotes2)
  searchQuote(quotes.Buyer.quotes6)

  // Reject Quote not working
  // rejectQuote(quotes.Buyer.quotes6, role.Approver1.dropDownText)
  // rejectQuote(quotes.Buyer.quotes4, role.Approver1.dropDownText)
  filterQuoteByStatus(STATUSES.declined)

  useQuoteForPlacingTheOrder(quotes.Buyer.quotes1, role.Approver1.dropDownText)
  verifyTotal(quotes.Buyer.quotes1)
  fillContactInfo()
  verifyAddress(costCenter1.addresses)
  verifyPayment()

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.8.1-organization_admin_scenarios-orgA.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_DROP_DOWN,
  ROLE_ID_EMAIL_MAPPING as roleObject,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
  userShouldNotImpersonateThisUser,
} from '../../support/b2b/common.js'
import { organizationAdminShouldNotAbleToEditSalesUsers } from '../../support/b2b/organization_request.js'
import {
  searchQuote,
  // rejectQuote,
  quoteShouldbeVisibleTestCase,
  quoteShouldNotBeVisibleTestCase,
} from '../../support/b2b/quotes.js'

describe('Organization A - Cost Center A1 - Organization Admin2 Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    nonAvailableProduct,
    costCenter2,
    users,
    quotes,
    gmailCreds,
  } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  loginToStoreFront(
    users.OrganizationAdmin2,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )
  verifySession(
    b2b.OrganizationA,
    costCenter2.name,
    ROLE_DROP_DOWN.OrganizationAdmin
  )
  organizationAdminShouldNotAbleToEditSalesUsers()
  userShouldNotImpersonateThisUser(
    ROLE_DROP_DOWN.OrganizationAdmin,
    roleObject.SalesManager.role,
    users.SalesManager
  )
  userShouldNotImpersonateThisUser(
    ROLE_DROP_DOWN.OrganizationAdmin,
    ROLE_DROP_DOWN.Buyer,
    users.Buyer1
  )
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.OrganizationAdmin.quotes1,
    organizationName
  )
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.Buyer2.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationBQuote.OrganizationAdmin.quotes1,
    organizationB
  )
  searchQuote(quotes.OrganizationAdmin.quotes1)
  // rejectQuote(
  //   quotes.OrganizationAdmin2.declineQuote,
  //   ROLE_DROP_DOWN.OrganizationAdmin
  // )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.11-approver_scenarios_orgB.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { ROLE_DROP_DOWN } from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
} from '../../support/b2b/common.js'
import {
  checkoutProduct,
  fillContactInfo,
  verifyAddress,
  verifyPayment,
  ordertheProduct,
} from '../../support/b2b/checkout.js'
import {
  quoteShouldbeVisibleTestCase,
  quoteShouldNotBeVisibleTestCase,
} from '../../support/b2b/quotes.js'

describe('Organization B - Cost Center B1 - Approver Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    product,
    nonAvailableProduct,
    costCenter1,
    users,
    quotes,
    organizationName,
    gmailCreds,
  } = b2b.OrganizationB

  const { organizationName: organizationA, quotes: organizationAQuotes } =
    b2b.OrganizationA

  loginToStoreFront(users.Approver1, ROLE_DROP_DOWN.Approver, gmailCreds)
  verifySession(b2b.OrganizationB, costCenter1.name, ROLE_DROP_DOWN.Approver)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.OrganizationAdmin.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationAQuotes.OrganizationAdmin.quotes1,
    organizationA
  )
  checkoutProduct(product)
  fillContactInfo()
  verifyAddress(costCenter1.addresses)
  verifyPayment(false)
  ordertheProduct(ROLE_DROP_DOWN.Approver)
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.14.2-sales_rep_scenarios.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_DROP_DOWN,
  ROLE_ID_EMAIL_MAPPING as roleObject,
  STATUSES,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  salesUserShouldImpersonateNonSalesUser,
  verifySession,
  stopImpersonation,
} from '../../support/b2b/common.js'
import {
  searchQuote,
  createQuote,
  updateQuote,
  filterQuoteByStatus,
} from '../../support/b2b/quotes.js'
import { salesRepQuotesAccess } from '../../support/b2b/impersonation_quote_access.js'

describe('Organization A - Cost Center A1 - Sales Rep Impersonation Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const { users, product, costCenter1, quotes, gmailCreds } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBQuote } =
    b2b.OrganizationB

  const impersonatedRole = ROLE_DROP_DOWN.Buyer

  loginToStoreFront(
    users.SalesRep,
    roleObject.SalesRepresentative.role,
    gmailCreds
  )
  verifySession(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesRepresentative.role
  )

  salesUserShouldImpersonateNonSalesUser(
    roleObject.SalesRepresentative.role,
    impersonatedRole,
    users.Buyer1
  )

  searchQuote(quotes.SalesRep.updateQuote)
  const price = '30.00'

  updateQuote(quotes.SalesRep.updateQuote, { price })
  filterQuoteByStatus(STATUSES.revised)
  salesRepQuotesAccess(b2b.OrganizationA, organizationB, organizationBQuote)

  const quote = 'IMPERSONATE_QUOTE_3'

  createQuote({
    product,
    quoteEnv: quote,
    role: roleObject.SalesRepresentative.role,
    impersonatedRole,
  })
  searchQuote(quote, users.Buyer1)
  stopImpersonation(
    b2b.OrganizationA,
    costCenter1.name,
    roleObject.SalesRepresentative.role
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.4.2-hide_organization_by_adding_dolar_sales_channel.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/valid-expect */
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { ROLE_DROP_DOWN } from '../../support/b2b/utils.js'
import b2b from '../../support/b2b/constants.js'
import {
  verifySalesChannel,
  verifyBindings,
  addBindingsWhichHidesOrganization,
  addBindingsWhichShowsOrganization,
} from '../../support/b2b/graphql.js'
import { loginToStoreFront } from '../../support/b2b/login.js'

const { users, gmailCreds } = b2b.OrganizationB

describe('Add Binding which hides Organization in profile page', () => {
  loginViaCookies({ storeFrontCookie: false })

  addBindingsWhichHidesOrganization()

  verifySalesChannel(0)

  verifyBindings(users.OrganizationAdmin1, false)

  loginToStoreFront(
    users.OrganizationAdmin1,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )

  it('Verify Organization is not showing up', updateRetry(2), () => {
    cy.reloadOnLastNAttempts(1)
    cy.organizationShouldNotShowInProfile()
  })

  addBindingsWhichShowsOrganization()

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.1.2-multi_organizations_requests_from_organizationB.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { loginViaCookies } from '../../support/common/support.js'
import {
  createOrganizationTestCase,
  approveOrganization,
} from '../../support/b2b/organization_request.js'
import b2b from '../../support/b2b/constants.js'
import { deleteOrganization } from '../../support/b2b/graphql.js'

describe('Create, Decline OrganizationB', () => {
  before(() => {
    cy.clearLocalStorage()
  })
  loginViaCookies({ storeFrontCookie: false })
  const email = b2b.OrganizationB.users.OrganizationAdmin1
  const name = b2b.OrganizationB.organizationName
  const costCenterName = b2b.OrganizationB.costCenter1.name
  const [costCenterAddress] = b2b.OrganizationB.costCenter1.addresses

  const organization = { name, email }
  const costCenter = {
    costCenterName,
    costCenterAddress,
  }

  const { organizationName, costCenter1, users } = b2b.OrganizationB

  deleteOrganization(organizationName, true)
  deleteOrganization(organizationName)

  // Create and decline Organization B
  createOrganizationTestCase(
    {
      name: organizationName,
      email: users.OrganizationAdmin1,
    },
    {
      costCenterName: costCenter1.name,
      costCenterAddress: costCenter1.addresses[0],
      declined: true,
    }
  )

  describe('Create, Approve OrganizationB', () => {
    // Create Organization B request
    createOrganizationTestCase(organization, costCenter)

    // Approve Organization B
    approveOrganization(b2b.OrganizationB.organizationName)
  })
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.4.1-add-remaining-users.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/valid-expect */
import {
  loginViaCookies,
  updateRetry,
  preserveCookie,
} from '../../support/common/support.js'
import {
  ROLE_ID_EMAIL_MAPPING,
  OTHER_ROLES,
  ROLE_DROP_DOWN,
} from '../../support/b2b/utils.js'
import { addUserViaGraphql } from '../../support/b2b/add_users.js'
import { syncCheckoutUICustom } from '../../support/common/testcase.js'
import b2b from '../../support/b2b/constants.js'
import { loginToStoreFront } from '../../support/b2b/login.js'

const { users, gmailCreds } = b2b.OrganizationA

describe('Sync Checkout UI Custom & Add Sales Users via Graphql', () => {
  loginViaCookies({ storeFrontCookie: false })

  loginToStoreFront(
    users.OrganizationAdmin1,
    ROLE_DROP_DOWN.OrganizationAdmin,
    gmailCreds
  )

  it('Set roles in organization JSON', updateRetry(3), () => {
    cy.getVtexItems().then((vtex) => {
      const APP_NAME = 'vtex.storefront-permissions'
      const APP_VERSION = '1.x'
      const APP = `${APP_NAME}@${APP_VERSION}`

      const CUSTOM_URL = `${vtex.baseUrl}/_v/private/admin-graphql-ide/v0/${APP}`
      const GRAPHQL_LIST_ROLE_QUERY = 'query' + '{listRoles{id,name}}'

      cy.callGraphqlAndAddLogs({
        url: CUSTOM_URL,
        query: GRAPHQL_LIST_ROLE_QUERY,
      }).then((response) => {
        const rolesObject = response.body.data.listRoles.filter((r) =>
          OTHER_ROLES.includes(r.name)
        )

        expect(rolesObject.length).to.equal(3)
        rolesObject.map((r) => cy.setOrganizationItem(`${r.name}-id`, r.id))
      })
    })
  })

  syncCheckoutUICustom()

  const roles = Object.keys(ROLE_ID_EMAIL_MAPPING)

  roles.forEach((r) => {
    addUserViaGraphql(gmailCreds, r)
  })

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.10-approver_scenarios_orgA_costcenter2.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import {
  ROLE_DROP_DOWN,
  ROLE_DROP_DOWN_EMAIL_MAPPING as role,
} from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  verifySession,
  productShouldNotbeAvailableTestCase,
} from '../../support/b2b/common.js'
import {
  fillContactInfo,
  verifyAddress,
  verifyPayment,
} from '../../support/b2b/checkout.js'
import {
  searchQuote,
  quoteShouldbeVisibleTestCase,
  quoteShouldNotBeVisibleTestCase,
  useQuoteForPlacingTheOrder,
  verifyTotal,
} from '../../support/b2b/quotes.js'

describe('Organization A - Cost Center A2 - Approver Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    quotes,
    nonAvailableProduct,
    costCenter2,
    users,
    gmailCreds,
  } = b2b.OrganizationA

  const { organizationName: organizationB, quotes: organizationBquotes } =
    b2b.OrganizationB

  loginToStoreFront(users.Approver2, ROLE_DROP_DOWN.Approver, gmailCreds)
  verifySession(b2b.OrganizationA, costCenter2.name, ROLE_DROP_DOWN.Approver)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.Buyer2.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationBquotes.OrganizationAdmin.quotes1,
    organizationB
  )
  searchQuote(quotes.Approver2.updateQuote)
  useQuoteForPlacingTheOrder(
    quotes.Approver2.updateQuote,
    role.Approver2.dropDownText
  )
  verifyTotal(quotes.Approver2.updateQuote)
  fillContactInfo()
  verifyAddress(costCenter2.addresses)
  verifyPayment(false)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/b2b/2.7-buyer_scenarios_orgB_costB1.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import b2b from '../../support/b2b/constants.js'
import { ROLE_DROP_DOWN } from '../../support/b2b/utils.js'
import { loginToStoreFront } from '../../support/b2b/login.js'
import {
  productShouldNotbeAvailableTestCase,
  verifySession,
} from '../../support/b2b/common.js'
import {
  createQuote,
  quoteShouldbeVisibleTestCase,
  quoteShouldNotBeVisibleTestCase,
} from '../../support/b2b/quotes.js'

describe('Organization B - Cost Center B1 - Buyer Scenario', () => {
  loginViaCookies({ storeFrontCookie: false })

  const {
    organizationName,
    users,
    nonAvailableProduct,
    product,
    quotes,
    costCenter1,
    gmailCreds,
  } = b2b.OrganizationB

  const { organizationName: organizationA, quotes: organizationAQuotes } =
    b2b.OrganizationA

  loginToStoreFront(users.Buyer1, ROLE_DROP_DOWN.Buyer, gmailCreds)
  verifySession(b2b.OrganizationB, costCenter1.name, ROLE_DROP_DOWN.Buyer)
  productShouldNotbeAvailableTestCase(nonAvailableProduct)
  quoteShouldbeVisibleTestCase(
    organizationName,
    quotes.OrganizationAdmin.quotes1,
    organizationName
  )
  quoteShouldNotBeVisibleTestCase(
    organizationName,
    organizationAQuotes.OrganizationAdmin.quotes1,
    organizationA
  )
  createQuote({
    product,
    quoteEnv: quotes.Buyer.quotes1,
    role: ROLE_DROP_DOWN.Buyer,
  })

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/packing-optimization/2.1-rest-apis.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import { pack } from '../../support/packing-optimization/api_testcase'
import { packed } from '../../fixtures/pack.json'

describe('Rest-api-testcases', () => {
  loginViaCookies()

  pack(packed)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.4-discountProduct.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { discountProduct } from '../../support/affirm/outputvalidation'
import {
  cancelTheOrder,
  getTestVariables,
  verifyOrderStatus,
} from '../../support/common/testcase.js'
import { completeThePayment } from '../../support/affirm/testcase.js'

const { prefix, productName, postalCode, productQuantity } = discountProduct

describe(`${prefix} Scenarios`, () => {
  loginViaCookies()

  const discountProductEnvs = getTestVariables(prefix)

  discountProductEnvs.sendInvoice = false

  it(`In ${prefix} - Adding Product to Cart`, updateRetry(1), () => {
    // Search the product
    cy.searchProduct(productName)
    // Add product to cart
    cy.addProduct(productName, { proceedtoCheckout: true })
  })

  it(`In ${prefix} - Updating product quantity to 1`, updateRetry(4), () => {
    // Update Product quantity to 1
    cy.updateProductQuantity(productName, {
      quantity: productQuantity,
      verifySubTotal: false,
    })
  })

  it(`In ${prefix} - Updating Shipping Information`, updateRetry(4), () => {
    // Update Shipping Section
    cy.updateShippingInformation({ postalCode, phoneNumber: '(312) 310 3249' })
  })

  completeThePayment(discountProduct, discountProductEnvs)

  verifyOrderStatus({
    product: discountProduct,
    env: discountProductEnvs.orderIdEnv,
    status: /handling/,
    timeout: 30000,
  })

  cancelTheOrder(discountProductEnvs.orderIdEnv)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/wipe.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { loginViaCookies } from '../../support/common/support.js'
import {
  setWorkspaceAndGatewayAffiliations,
  deleteAddresses,
} from '../../support/common/testcase.js'

describe('Wipe affirm in dynamic environment', () => {
  loginViaCookies()

  setWorkspaceAndGatewayAffiliations({ wipe: true })
  deleteAddresses()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.8-fullRefund.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { singleProduct } from '../../support/affirm/outputvalidation.js'
import { refund } from '../../support/common/refund_apis.js'
import { getTestVariables } from '../../support/common/testcase.js'
import { loginViaCookies } from '../../support/common/support.js'
import { getRefundPayload } from '../../support/common/refund.js'
import { verifyTransactionInAffirm } from '../../support/affirm/api_testcase.js'

describe('Testing Affirm transaction API for full refund', () => {
  const singleProductEnvs = getTestVariables(singleProduct.prefix)
  const { orderIdEnv } = singleProductEnvs

  loginViaCookies()

  it('Verify whether we have an order to request for full refund', () => {
    cy.getOrderItems().then((order) => {
      if (!order[orderIdEnv]) {
        throw new Error('Order id is missing')
      }
    })
  })

  // Request full refund for the ordered product added in 2.2-singleProduct.spec.js & verify paypal transaction
  refund(
    {
      total: singleProduct.getFullRefundTotal, // Amount
      title: 'full', // Refund Type for test case title
      env: orderIdEnv, // variable name where we stored the orderid in node environment
    },
    getRefundPayload
  )

  verifyTransactionInAffirm(singleProduct, singleProductEnvs, true)
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.2-singleProduct.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { singleProduct } from '../../support/affirm/outputvalidation'
import { getTestVariables } from '../../support/common/testcase.js'
import { completeThePayment } from '../../support/affirm/testcase.js'

const { prefix, productName, postalCode, productQuantity } = singleProduct

const singleProductEnvs = getTestVariables(prefix)

describe(`${prefix} Scenarios`, () => {
  loginViaCookies()

  it(`In ${prefix} - Adding Product to Cart`, updateRetry(1), () => {
    // Search the product
    cy.searchProduct(productName)
    // Add product to cart
    cy.addProduct(productName, { proceedtoCheckout: true })
  })

  it(`In ${prefix} - Updating product quantity to 2`, updateRetry(4), () => {
    // Update Product quantity to 2
    cy.updateProductQuantity(productName, {
      quantity: productQuantity,
      verifySubTotal: false,
    })
  })

  it(`In ${prefix} - Updating Shipping Information`, updateRetry(4), () => {
    // Update Shipping Section
    cy.updateShippingInformation({
      postalCode,
      phoneNumber: '(312) 310 3249',
      timeout: 10000,
    })
  })

  completeThePayment(singleProduct, singleProductEnvs)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.9-partialRefund.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import { multiProduct } from '../../support/affirm/outputvalidation.js'
import { refund } from '../../support/common/refund_apis.js'
import { getTestVariables } from '../../support/common/testcase.js'
import { loginViaCookies } from '../../support/common/support.js'
import { getRefundPayload } from '../../support/common/refund.js'
import { verifyTransactionInAffirm } from '../../support/affirm/api_testcase.js'

describe('Testing Affirm transaction API for partial refund', () => {
  const multiProductEnvs = getTestVariables(multiProduct.prefix)
  const { orderIdEnv } = multiProductEnvs

  loginViaCookies()

  it('Verify whether we have an order to request for partial refund', () => {
    cy.getOrderItems().then((order) => {
      if (!order[orderIdEnv]) {
        throw new Error('Order id is missing')
      }
    })
  })

  // Request partial refund for the ordered product added in 2.3-multiProduct.spec.js
  refund(
    {
      total: multiProduct.refundedAmount, // Amount
      title: 'partial', // Refund Type for test case title
      env: orderIdEnv, // variable name where we stored the orderid in node environment
    },
    getRefundPayload
  )

  verifyTransactionInAffirm(multiProduct, multiProductEnvs, true)
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/post_setup.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
  scroll,
  updateRetry,
} from '../../support/common/support.js'
import {
  setWorkspaceAndGatewayAffiliations,
  startPaymentE2ETests,
  syncCheckoutUICustom,
} from '../../support/common/testcase.js'
import selectors from '../../support/common/selectors'

function verifyAffirmPromotion() {
  cy.get(selectors.AffirmPromoComponents, { timeout: 20000 }).should(
    'be.visible'
  )
  cy.get(selectors.AffirmModal).should('be.visible').first().click()
  cy.get(selectors.AffirmIFrame).should('be.visible')
  cy.getIframeBody(selectors.AffirmIFrame)
    .find(selectors.AffirmClosePopup)
    .should('be.visible')
    .click()
}

describe('Setting up affirm in dynamic environment', () => {
  loginViaCookies()

  startPaymentE2ETests()
  setWorkspaceAndGatewayAffiliations()
  syncCheckoutUICustom()

  it('Set public token in affirm settigs', () => {
    cy.getVtexItems().then((vtex) => {
      cy.visit('/admin/apps/vtex.affirm-payment/setup/')
      cy.getIframeBody(selectors.AdminConfigurationIFrame)
        .find(selectors.AffirmAdminPublicKey)
        .should('be.visible')
        .clear()
        .type(vtex.publicKeyForPromotionalComponents)
      cy.getIframeBody(selectors.AdminConfigurationIFrame)
        .find(selectors.AffirmSubmitConfiguration)
        .should('be.visible')
        .click()
    })
  })

  it('Verify promotions get displayed in storefront', updateRetry(1), () => {
    cy.visit('/')
    cy.waitForSession()
    cy.get(selectors.ProfileLabel, { timeout: 20000 })
      .should('be.visible')
      .should('have.contain', `Hello,`)
    scroll()
    verifyAffirmPromotion()
    cy.url().should('include', '/p')
    cy.get('div[class*=shippingContainer]').should('be.visible')
    verifyAffirmPromotion()
  })

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.5-validate-invalid-phonenumber-in-checkout-page.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import {
  preserveCookie,
  updateRetry,
  loginViaCookies,
} from '../../support/common/support'
import { getTestVariables } from '../../support/common/testcase'
import {
  completeThePayment,
  initiatePayment,
} from '../../support/affirm/testcase.js'
import selectors from '../../support/common/selectors'
import { discountShipping } from '../../support/affirm/outputvalidation'

const { productName, postalCode, prefix, productQuantity } = discountShipping
const discountShippingProductEnvs = getTestVariables(prefix)

describe(`${prefix} Scenarios`, () => {
  loginViaCookies()

  it(`In ${prefix} - Adding Product to Cart`, updateRetry(1), () => {
    // Search the product
    cy.searchProduct(productName)
    // Add product to cart
    cy.addProduct(productName)
  })

  it(`In ${prefix} - Updating product quantity to 1`, updateRetry(4), () => {
    // Update Product quantity to 1
    cy.updateProductQuantity(productName, {
      quantity: productQuantity,
      verifySubTotal: false,
    })
  })

  it(`In ${prefix} - Update Shipping Information`, updateRetry(4), () => {
    cy.updateShippingInformation({ postalCode })
  })

  initiatePayment({
    prefix,
    expectedPhoneNo: '(304) 123 4556',
    completePayment: false,
    retries: 2,
  })

  it(
    `In ${prefix} - Validate with invalid phone number`,
    updateRetry(3),
    () => {
      cy.intercept('POST', `https://sandbox.affirm.com/api/v2/checkout/`).as(
        'updateOrderFormShipping'
      )

      /* eslint-disable jest/valid-expect-in-promise */
      cy.wait('@updateOrderFormShipping')
        .its('response')
        .then((response) => {
          expect(response.body.message).includes('Please enter a valid mobile')
        })
    }
  )

  it(`In ${prefix} - close the pop up`, updateRetry(3), () => {
    cy.getIframeBody(selectors.popUpClose).should('be.visible')
    cy.getIframeBody(selectors.popUpClose)
      .find(selectors.invalidPopUpCloseBtn)
      .should('be.visible')
      .click()
    // eslint-disable-next-line cypress/no-unnecessary-waiting
    cy.wait(10000)
    cy.get(selectors.dataReviewCloseBtn).click()
  })

  completeThePayment(discountShipping, discountShippingProductEnvs)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.6-external-seller.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import { loginViaCookies, updateRetry } from '../../support/common/support.js'
import { externalSeller } from '../../support/affirm/outputvalidation.js'
import {
  getTestVariables,
  invoiceAPITestCase,
  sendInvoiceTestCase,
} from '../../support/common/testcase.js'
import { completeThePayment } from '../../support/affirm/testcase.js'

const { prefix, product1Name, product2Name, postalCode } = externalSeller
const externalSellerEnvs = getTestVariables(prefix)

externalSellerEnvs.sendInvoice = false

describe(`${prefix} Scenarios`, () => {
  loginViaCookies()

  it(`In ${prefix} - Adding Product to Cart`, updateRetry(1), () => {
    // Search the product
    cy.searchProduct(product1Name)
    // Add product to cart
    cy.addProduct(product1Name, {
      proceedtoCheckout: false,
    })
    // Search the product
    cy.searchProduct(product2Name)
    // Add product to cart
    cy.addProduct(product2Name, {
      proceedtoCheckout: true,
    })
  })

  it(`In ${prefix} - Updating Shipping Information`, updateRetry(4), () => {
    // Update Shipping Section
    cy.updateShippingInformation({
      postalCode,
      phoneNumber: '(312) 310 3249',
    })
  })

  completeThePayment(externalSeller, externalSellerEnvs, true)
})

describe('Testing Invoice API for Direct Sale', () => {
  it('Get Direct Sale orderId and update in Cypress env', () => {
    cy.getOrderItems().then((order) => {
      if (!order[externalSeller.directSaleEnv]) {
        throw new Error('Direct Sale Order id is missing')
      }
    })
  })

  sendInvoiceTestCase({
    product: externalSeller,
    orderIdEnv: externalSeller.directSaleEnv,
    externalSellerTestcase: true,
  })

  // Get transactionId from invoiceAPI and store in .orders.json
  invoiceAPITestCase({
    product: externalSeller,
    env: externalSeller.directSaleEnv,
    transactionIdEnv: externalSellerEnvs.transactionIdEnv,
  })
})

describe('Testing Invoice API for External Sale', () => {
  it('Get External Sale orderId and update in Cypress env', () => {
    cy.getOrderItems().then((order) => {
      if (!order[externalSeller.externalSaleEnv]) {
        throw new Error('External Sale Order id is missing')
      }
    })
  })

  sendInvoiceTestCase({
    product: externalSeller,
    orderIdEnv: externalSeller.externalSaleEnv,
    externalSellerTestcase: true,
  })

  // Get transactionId from invoiceAPI and store in .orders.json
  invoiceAPITestCase({
    product: externalSeller,
    env: externalSeller.externalSaleEnv,
    transactionIdEnv: externalSellerEnvs.transactionIdEnv,
  })
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.3-multiProduct.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { multiProduct } from '../../support/affirm/outputvalidation.js'
import { getTestVariables } from '../../support/common/testcase.js'
import { completeThePayment } from '../../support/affirm/testcase.js'

const { prefix, product1Name, product2Name, postalCode, productQuantity } =
  multiProduct

describe(`${prefix} Scenarios`, () => {
  loginViaCookies()

  const multiProductEnvs = getTestVariables(prefix)

  it(`In ${prefix} - Adding Product to Cart`, updateRetry(1), () => {
    // Search the product
    cy.searchProduct(product1Name)
    // Add product to cart
    cy.addProduct(product1Name, { proceedtoCheckout: false })
    // Search the product
    cy.searchProduct(product2Name)
    // Add product to cart
    cy.addProduct(product2Name, {
      proceedtoCheckout: true,
    })
  })

  it(`In ${prefix} - Updating product quantity to 2`, updateRetry(4), () => {
    // Update Product quantity to 2
    cy.updateProductQuantity(product1Name, {
      quantity: productQuantity,
      verifySubTotal: false,
    })
  })

  it(`In ${prefix} - Updating Shipping Information`, updateRetry(4), () => {
    // Update Shipping Section
    cy.updateShippingInformation({
      postalCode,
      phoneNumber: '(312) 310 3249',
      timeout: 10000,
    })
  })

  completeThePayment(multiProduct, multiProductEnvs)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.1-graphql.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { updateRetry, loginViaCookies } from '../../support/common/support'
import {
  graphql,
  version,
  affirmSettings,
  orderData,
  validateGetVersionResponse,
  validateAffirmSettingsResponse,
  validateOrderDataResponse,
} from '../../support/affirm/graphql_testcase'

const prefix = 'Graphql testcase'

describe('Affirm GraphQL Validation', () => {
  loginViaCookies()

  it(`${prefix} - Get Version`, updateRetry(3), () => {
    graphql(version(), validateGetVersionResponse)
  })

  it(`${prefix} - Affirm Settings`, updateRetry(3), () => {
    graphql(affirmSettings(), validateAffirmSettingsResponse)
  })

  it(`${prefix} - Get Order Data`, updateRetry(3), () => {
    graphql(orderData(), validateOrderDataResponse)
  })
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/affirm/2.7-transactions.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import { loginViaCookies } from '../../support/common/support.js'
import {
  singleProduct,
  multiProduct,
  discountShipping,
  discountProduct,
} from '../../support/affirm/outputvalidation'
import {
  getTestVariables,
  verifyTransactionPaymentsAPITestCase,
} from '../../support/common/testcase.js'
import { verifyTransactionInAffirm } from '../../support/affirm/api_testcase.js'

describe(`Transaction Scenarios`, () => {
  loginViaCookies()

  const singleProductEnvs = getTestVariables(singleProduct.prefix)
  const multiProductEnvs = getTestVariables(multiProduct.prefix)
  const discountShippingEnvs = getTestVariables(discountShipping.prefix)
  const discountProductEnvs = getTestVariables(discountProduct.prefix)

  verifyTransactionPaymentsAPITestCase(singleProduct, singleProductEnvs)
  verifyTransactionPaymentsAPITestCase(multiProduct, multiProductEnvs)
  verifyTransactionPaymentsAPITestCase(discountProduct, discountProductEnvs)
  verifyTransactionPaymentsAPITestCase(discountShipping, discountShippingEnvs)

  verifyTransactionInAffirm(singleProduct, singleProductEnvs)
  verifyTransactionInAffirm(multiProduct, multiProductEnvs)
  verifyTransactionInAffirm(discountProduct, discountProductEnvs, true) // Verify cancelled order amount is refunded
  verifyTransactionInAffirm(discountShipping, discountShippingEnvs)

  /*
  TODO: ExternalSeller shows popup randomly inside and outside the window
  So, for now we disabled this test
  Once it is fixed then will enable again
  https://www.loom.com/share/efe711c4883243058989a712a62dadb9
  const externalSellerEnvs = getTestVariables(externalSeller.prefix)
  verifyTransactionPaymentsAPITestCase(externalSeller, externalSellerEnvs)
  verifyTransactionInAffirm(externalSeller, externalSellerEnvs)
  */
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/wipe.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { loginViaCookies } from '../../support/common/support.js'
import { deleteAddresses } from '../../support/common/testcase.js'

describe('Wipe addresses in dynamic environment', () => {
  loginViaCookies()

  deleteAddresses()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.3.1-upload_csv.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { quickOrderByXLS } from '../../support/quick-order/testcase.js'

describe('Quickorder - Upload CSV testcase', () => {
  loginViaCookies()

  quickOrderByXLS(false)

  it(
    `In Upload CSV testcase - Verify quantity by price`,
    updateRetry(4),
    () => {
      cy.qe(
        'Verify the quantity in the quantity badge and the first item should contain 2 and last item should contain 50'
      )
      cy.get('.quantity.badge').first().should('have.text', '2')
      cy.get('.quantity.badge').last().should('have.text', '50')
    }
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.2.1-skucode_quantity.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { quickOrderBySkuAndQuantityTestCase1 } from '../../support/quick-order/testcase.js'
import { graphql } from '../../support/common/graphql_utils.js'
import {
  APP,
  getSkuFromRefIds,
  validateSkuFromRefIdsResponse,
} from '../../support/quick-order/graphql.js'

describe('Quickorder - SkuCode Quantity testcase', () => {
  loginViaCookies()

  quickOrderBySkuAndQuantityTestCase1('user', null)

  // eslint-disable-next-line jest/expect-expect
  it(
    `In SkuCode Quantity testcase - Verify quantity by price & getSkuFromRefIds graphql`,
    updateRetry(4),
    () => {
      cy.qe(`Verify the quantity to 2 in the checkout page`)
      cy.get('.quantity.badge').first().should('have.text', '2')
      cy.window().then(($win) => {
        cy.qe(`Get Sku's from orderformId using GraphQL
      `)
        graphql(
          APP,
          getSkuFromRefIds($win.vtexjs.checkout.orderForm.orderFormId),
          validateSkuFromRefIdsResponse
        )
      })
    }
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.2.2-skucode_quantity_negative_testcase.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import {
  quickOrderBySkuAndQuantityWithValidAndInValidSkuTestCase,
  quickOrderBySkuAnd51QuantityTestCase,
} from '../../support/quick-order/testcase.js'

describe('Quickorder - SkuCode Quantity Negative testcases', () => {
  loginViaCookies()

  quickOrderBySkuAndQuantityWithValidAndInValidSkuTestCase('user', null)
  quickOrderBySkuAnd51QuantityTestCase('user', null)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.3.3_download-spreadsheet_verify_data&extension.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
  updateRetry,
} from '../../support/common/support.js'
import { verifyExcelFile } from '../../support/quick-order/testcase'
import { products } from '../../support/quick-order/product.js'

const fileName = 'cypress-shared/downloads/model-quickorder.xls'

describe('Quickorder - Verify the data and extension in the spreadsheet', () => {
  loginViaCookies()

  it('Download the quickOrder spreadsheet', updateRetry(3), () => {
    cy.qe(`Visit the Quickorder Homepage and verify the profile is visible`)
    cy.qe('Verify the url should contain quickorder')
    cy.gotoQuickOrder()
    cy.contains('Click here to download a spreadsheet model').click()
  })

  verifyExcelFile(fileName, products)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.5-categories.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import {
  quickOrderByCategoryNegativeTestCase,
  quickOrderByCategory,
} from '../../support/quick-order/testcase.js'

describe('Quickorder - Category testcases', () => {
  loginViaCookies()

  quickOrderByCategory('user', null)
  quickOrderByCategoryNegativeTestCase('user', null)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.4-one_by_one.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import {
  quickOrderByOneByOneTestCase,
  quickOrderByOneByOneNegativeTestCase,
} from '../../support/quick-order/testcase.js'
import { PRODUCTS } from '../../support/common/utils.js'

describe('Quickorder - Category testcases', () => {
  loginViaCookies()

  quickOrderByOneByOneTestCase('user', PRODUCTS.coconut, null)
  quickOrderByOneByOneNegativeTestCase('user', PRODUCTS.coconut, null)

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/quick-order/1.1-graphql.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { graphql } from '../../support/common/graphql_utils.js'
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import {
  APP,
  getSellers,
  validateSellers,
} from '../../support/quick-order/graphql.js'

describe('Graphql testcase', () => {
  loginViaCookies()

  it('seller query', () => {
    cy.qe(`
    seller query - 'query' +
    '{sellers @context(provider: "vtex.quickorder")' +
    '{items{id,name}}}',
    `)
    graphql(APP, getSellers(), validateSellers)
  })

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/location-availability/2.4-location-not-available.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  preserveCookie,
  updateRetry,
  loginViaAPI,
} from '../../support/common/support'
import { canadaDetails } from '../../support/shopper-location/outputvalidation'
import selectors from '../../support/common/selectors'
import { addAddress } from '../../support/shopper-location/common'
import { PRODUCTS_LINK_MAPPING } from '../../support/common/utils'

const prefix = 'Pickup not available'

describe('Validate location non availability', () => {
  loginViaAPI()

  addAddress(prefix, { address: canadaDetails })

  // eslint-disable-next-line jest/expect-expect
  it(`${prefix} - Verify shipping content`, updateRetry(2), () => {
    cy.qe('Product image should be visible on the home page')
    cy.get(PRODUCTS_LINK_MAPPING.orange.link).should('be.visible')
    cy.qe('For the given shipping address the shipping is unavailable')
    cy.get(selectors.locationUnavailable)
      .should('be.visible')
      .contains('Shipping: Unavailable for')
  })

  // eslint-disable-next-line jest/expect-expect
  it(
    `${prefix} - Open product specfication page and verify`,
    updateRetry(2),
    () => {
      cy.openProduct(PRODUCTS_LINK_MAPPING.orange.name, true, true)
      cy.qe(
        'Verifying the given shipping address in specification page is not available for pickup near your location'
      )
      cy.get(selectors.storeUnavailabilityInformation)
        .should('be.visible')
        .contains(
          'The selected item is not available for pickup near your location.'
        )
    }
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/location-availability/wipe.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/valid-expect */
import {
  graphql,
  updateShippingPolicy,
} from '../../support/common/shipping-policy.graphql'
import data from '../../support/location-availability/shipping-policy.json'
import {
  loginViaCookies,
  preserveCookie,
} from '../../support/common/support.js'
import { deleteAllPickupPoints } from '../../support/location-availability/support'

describe('Wipe the pickup points', () => {
  loginViaCookies({ storeFrontCookie: false })

  deleteAllPickupPoints()

  // If we leave the shipping policy active then it is forcing us to use pickup points in checkout
  // So, make shipping policy as inactive
  it('Update shipping policy status to inactive', () => {
    cy.qe(
      'If we leave the shipping policy active then it is forcing us to use pickup points in checkout,So make shipping policy as inactive'
    )
    graphql(
      updateShippingPolicy(data.ship1, { status: false, pickup: false }),
      (response) => {
        expect(response.status).to.equal(200)
      }
    )
    graphql(
      updateShippingPolicy(data.ship2, { status: false, pickup: false }),
      (response) => {
        expect(response.status).to.equal(200)
      }
    )
  })
  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/location-availability/2.3-location-availability.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
/* eslint-disable jest/expect-expect */
import {
  preserveCookie,
  updateRetry,
  loginViaAPI,
} from '../../support/common/support'
import { UsDetails3 } from '../../support/shopper-location/outputvalidation'
import selectors from '../../support/common/selectors'
import { verifyHomePage } from '../../support/shopper-location/common'
import { PRODUCTS_LINK_MAPPING } from '../../support/common/utils'

const { country, postalCode, address, city } = UsDetails3

const prefix = 'Shipping not avaiable'

describe('Validate location availability', () => {
  loginViaAPI()

  // eslint-disable-next-line jest/expect-expect
  it(`${prefix} - Go to home and add location`, updateRetry(1), () => {
    cy.addNewLocation(country, postalCode, address, city)
    cy.get(PRODUCTS_LINK_MAPPING.orange.link).should('be.visible')
    verifyHomePage(city, postalCode)
  })

  it(
    `${prefix} - Open product specfication page and verify`,
    updateRetry(1),
    () => {
      cy.openProduct(PRODUCTS_LINK_MAPPING.orange.name, true)
      cy.qe('Postal code should be visible on the specification page')
      cy.get(selectors.AvailabilityHeader)
        .should('be.visible')
        .contains('33180')
    }
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/location-availability/2.5-Add-multiple-pickuppoint-and-update-shipping.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import {
  updateRetry,
  preserveCookie,
  loginViaAPI,
} from '../../support/common/support'
import { addPickUpPoint } from '../../support/location-availability/support'
import {
  graphql,
  updateShippingPolicy,
} from '../../support/common/shipping-policy.graphql'
import data from '../../support/location-availability/shipping-policy.json'

const prefix = 'Multiple pickup points'

describe('Adding Multiple pickup point & Update Shipping', () => {
  loginViaAPI()

  // eslint-disable-next-line jest/expect-expect
  it(`${prefix} - Add Multiple PickUp Point`, updateRetry(1), () => {
    cy.qe('Visit admin pickup points page')
    cy.visit('/admin/app/pickup-points')
    cy.qe('Adding 4 new pickup points')
    for (let id = 1; id <= 4; id++) {
      addPickUpPoint(`Location availability pickup Point ${id}`, id)
    }
  })

  it(`${prefix} - Add pickup points in shipping policy`, updateRetry(3), () => {
    data.ship1.shippingPolicy.pickupPointsSettings.pickupPointIds.push(
      '1',
      '2',
      '3'
    )
    cy.qe('Updating shipping policy via updateShippingPolicy graphql')
    graphql(
      updateShippingPolicy(data.ship1, { status: true, pickup: false }),
      (response) => {
        // eslint-disable-next-line jest/valid-expect
        expect(response.status).to.equal(200)
      }
    )
  })

  it(
    'Add pickup points in Location Availability shipping policy',
    updateRetry(3),
    () => {
      data.ship2.shippingPolicy.pickupPointsSettings.pickupPointIds.push('4')
      graphql(
        updateShippingPolicy(data.ship2, { status: true, pickup: false }),
        (response) => {
          // eslint-disable-next-line jest/valid-expect
          expect(response.status).to.equal(200)
        }
      )
    }
  )

  preserveCookie()
})

```


[System] You are an expert VTEX IO developer. You specialize in building VTEX Store Framework apps, React components, GraphQL APIs, and Node.js services for e-commerce platforms.

[User] Show me the implementation of cy-runner/cypress-shared/integration/location-availability/2.6-Verify-location-availability props.spec.js from the cy-runner VTEX app.

[Assistant]
Here's the implementation:

```javascript
import { UsDetails3 } from '../../support/shopper-location/outputvalidation'
import {
  addLocation,
  verifyHomePage,
} from '../../support/shopper-location/common'
import {
  updateRetry,
  preserveCookie,
  loginViaAPI,
} from '../../support/common/support'
import selectors from '../../support/common/selectors'
import { PRODUCTS_LINK_MAPPING } from '../../support/common/utils'

const { country, postalCode, city } = UsDetails3

const prefix = 'Location availability props'

describe('Verify location availability props', () => {
  loginViaAPI()

  // eslint-disable-next-line jest/no-disabled-tests
  it(
    `${prefix} - Adding Location & Verify location Availability`,
    updateRetry(1),
    () => {
      addLocation({ country, postalCode })
      verifyHomePage(city, postalCode)
    }
  )

  // eslint-disable-next-line jest/no-disabled-tests
  it(
    `${prefix} - Search results & product specification`,
    updateRetry(3),
    () => {
      cy.openProduct(PRODUCTS_LINK_MAPPING.orange.name, true)
      // eslint-disable-next-line jest/valid-expect-in-promise
      cy.get('body').then(($body) => {
        expect(
          $body.find(selectors.VerifyMaxItem).length
          // eslint-disable-next-line jest/valid-expect
        ).to.equal(3)
      })
      cy.get(selectors.OrderByFaster).should('be.visible')
    }
  )

  preserveCookie()
})

```