Think about API abstraction
- Dominant language
- TypeScript
- Stars
- 210
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Description
Common use case: need to login, then perform authorized API calls
```js
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
```js
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
})
})
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.