<commit_before>import {
  NotificationEndpoint,
  SlackNotificationEndpoint,
  Organization,
} from '../../src/types'

describe('Notification Endpoints', () => {
  const endpoint: NotificationEndpoint = {
    orgID: '',
    name: 'Pre-Created Endpoint',
    userID: '',
    description: 'interrupt everyone at work',
    status: 'active',
    type: 'slack',
    url: 'insert.slack.url.here',
    token: '<PASSWORD>',
  }

  beforeEach(() => {
    cy.flush()

    cy.signin().then(({body}) => {
      const {
        org: {id},
      } = body
      cy.wrap(body.org).as('org')
      cy.fixture('routes').then(({orgs, alerting}) => {
        cy.createEndpoint({...endpoint, orgID: id}).then(({body}) => {
          cy.wrap(body).as('endpoint')
        })
        cy.visit(`${orgs}/${id}${alerting}`)
      })
    })
  })

  it('can create a notification endpoint', () => {
    const name = 'An Endpoint Has No Name'
    const description =
      'A minute, an hour, a month. Notification Endpoint is certain. The time is not.'

    cy.getByTestID('create-endpoint').click()

    cy.getByTestID('endpoint-name--input')
      .clear()
      .type(name)
      .should('have.value', name)

    cy.getByTestID('endpoint-description--textarea')
      .clear()
      .type(description)
      .should('have.value', description)

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Slack')
        })

        cy.getByTestID('endpoint--dropdown-item pagerduty').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Pagerduty')
        })
      })

    cy.getByTestID('pagerduty-url')
      .clear()
      .type('many-faced-god.gov')
      .should('have.value', 'many-faced-god.gov')

    cy.getByTestID('pagerduty-routing-key')
      .type('<KEY>')
      .should('have.value', '<KEY>')

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Pagerduty')
        })

        cy.getByTestID('endpoint--dropdown-item http').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('HTTP')
        })
      })

    cy.getByTestID('http-url')
      .clear()
      .type('http.url.us')
      .should('have.value', 'http.url.us')

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('HTTP')
        })

        cy.getByTestID('endpoint--dropdown-item slack').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Slack')
        })
      })

    cy.getByTestID('slack-url')
      .clear()
      .type('slack.url.us')
      .should('have.value', 'slack.url.us')

    cy.getByTestID('endpoint-save--button').click()

    cy.getByTestID(`endpoint-card ${name}`).should('exist')
    cy.getByTestID('endpoint--overlay').should('not.be.visible')
  })

  it('can edit a notification endpoint', () => {
    cy.get<SlackNotificationEndpoint>('@endpoint').then(endpoint => {
      const {name, description, url} = endpoint
      const newName = 'An Endpoint Has No Name'<commit_msg>(fix) Client URL optional PagerDuty<commit_after>import {
  NotificationEndpoint,
  SlackNotificationEndpoint,
  Organization,
} from '../../src/types'

describe('Notification Endpoints', () => {
  const endpoint: NotificationEndpoint = {
    orgID: '',
    name: 'Pre-Created Endpoint',
    userID: '',
    description: 'interrupt everyone at work',
    status: 'active',
    type: 'slack',
    url: 'insert.slack.url.here',
    token: '<PASSWORD>',
  }

  beforeEach(() => {
    cy.flush()

    cy.signin().then(({body}) => {
      const {
        org: {id},
      } = body
      cy.wrap(body.org).as('org')
      cy.fixture('routes').then(({orgs, alerting}) => {
        cy.createEndpoint({...endpoint, orgID: id}).then(({body}) => {
          cy.wrap(body).as('endpoint')
        })
        cy.visit(`${orgs}/${id}${alerting}`)
      })
    })
  })

  it('can create a notification endpoint', () => {
    const name = 'An Endpoint Has No Name'
    const description =
      'A minute, an hour, a month. Notification Endpoint is certain. The time is not.'

    cy.getByTestID('create-endpoint').click()

    cy.getByTestID('endpoint-name--input')
      .clear()
      .type(name)
      .should('have.value', name)

    cy.getByTestID('endpoint-description--textarea')
      .clear()
      .type(description)
      .should('have.value', description)

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Slack')
        })

        cy.getByTestID('endpoint--dropdown-item http').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('HTTP')
        })
      })

    cy.getByTestID('http-url')
      .clear()
      .type('http.url.us')
      .should('have.value', 'http.url.us')

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('HTTP')
        })

        cy.getByTestID('endpoint--dropdown-item slack').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Slack')
        })
      })

    cy.getByTestID('slack-url')
      .clear()
      .type('slack.url.us')
      .should('have.value', 'slack.url.us')

    cy.getByTestID('endpoint-save--button').click()

    cy.getByTestID(`endpoint-card ${name}`).should('exist')
    cy.getByTestID('endpoint--overlay').should('not.be.visible')
  })

  it('can create a notification endpoint pager duty with client url', () => {
    const name = 'Pagerduty example'

    cy.getByTestID('create-endpoint').click()

    cy.getByTestID('endpoint-name--input')
      .clear()
      .type(name)
      .should('have.value', name)

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Slack')
        })

        cy.getByTestID('endpoint--dropdown-item pagerduty').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Pagerduty')
        })
      })

    cy.getByTestID('pagerduty-url')
      .clear()
      .type('many-faced-god.gov')
      .should('have.value', 'many-faced-god.gov')

    cy.getByTestID('pagerduty-routing-key')
      .type('<KEY>')
      .should('have.value', '<KEY>')

    cy.getByTestID('endpoint-save--button').click()

    cy.getByTestID(`endpoint-card ${name}`).should('exist')
    cy.getByTestID('endpoint--overlay').should('not.be.visible')
  })

  it.only('can create a notification endpoint pager duty without client url', () => {
    const name = 'Pagerduty url none'

    cy.getByTestID('create-endpoint').click()

    cy.getByTestID('endpoint-name--input')
      .clear()
      .type(name)
      .should('have.value', name)

    cy.getByTestID('endpoint-change--dropdown')
      .click()
      .within(() => {
        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Slack')
        })

        cy.getByTestID('endpoint--dropdown-item pagerduty').click()

        cy.getByTestID('endpoint--dropdown--button').within(() => {
          cy.contains('Pagerduty')
        })
      })

    cy.getByTestID('pagerduty-url').clear()

    cy.getByTestID('pagerduty-routing-key')
      .type('<KEY>')
      .should('have.value', '<KEY>')

    cy.getByTestID('endpoint-save--button').click()

    cy.getByTestID(`endpoint-card ${name}`).should('exist')
    cy.getByTestID('endpoint--overlay').should('not.be.visible')
  })

  it('can edit a notification endpoint', () => {
    cy.get<SlackNotificationEndpoint>('@endpoint').then(endpoint => {
      const {name, description, url} = endpoint
      const newName = 'An Endpoint Has No Name'
{'fraction_non_alphanumeric': 0.1930680986087381, 'fraction_numerical': 0.0, 'mean_word_length': 2.527765820060267, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2392391', 'n_tokens_mistral': 2668, 'n_tokens_neox': 2575, 'n_words': 368}