Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Think about API abstraction #15

Open
bahmutov opened this issue Jul 29, 2019 · 0 comments
Open

Think about API abstraction #15

bahmutov opened this issue Jul 29, 2019 · 0 comments
Assignees

Comments

@bahmutov
Copy link
Owner

Common use case: need to login, then perform authorized API calls

  it('user cannot follow themselves', () => {
    const user = Cypress.env('user')
    cy.getLoginToken(user).then(token => {
      const apiUrl = Cypress.env('apiUrl')
      cy.api({
        method: 'POST',
        url: `${apiUrl}/api/profiles/${user.username}/follow`,
        headers: {
          authorization: `Token ${token}`
        },
        failOnStatusCode: false // we expect failure
      })

It would be nice if we could create the API client once (using before) and then could make the calls. Something like

let apiClient
before(() => {
  const user = Cypress.env('user')
  cy.getLoginToken(user).then(token => {
    const apiUrl = Cypress.env('apiUrl')
    apiClient = cy.apiClient({
      baseUrl: `${apiUrl}/api`,
      headers: {
        authorization: `Token ${token}`
      }
    })
  })
})

it('user cannot follow themselves', () => {
  apiClient({
    method: 'POST',
    url: `/profiles/${user.username}/follow`,
    failOnStatusCode: false // we expect failure
  })
})
@LeJeanbono LeJeanbono self-assigned this Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants