{"size": 1319, "ext": "js", "max_stars_repo_path": "cypress/integration/API-TESTS/UserSpec.js", "max_stars_repo_name": "MrPierre1/CypressTests", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "cypress/integration/API-TESTS/UserSpec.js", "max_issues_repo_name": "MrPierre1/CypressTests", "max_issues_repo_issues_event_min_datetime": "2020-07-16T12:28:32.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-22T18:15:51.000Z", "max_forks_repo_path": "cypress/cypress/integration/API TESTS/UserSpec.js", "max_forks_repo_name": "MrPierre1/cypress_meetup", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 10, "max_forks_count": null, "avg_line_length": 24.8867924528, "max_line_length": 75, "alphanum_fraction": 0.5625473844}
// var faker = require('faker')

import faker from 'faker'

describe('Users API', () => {

  var user = {
    username: faker.internet.userName(),
    password: faker.internet.password()
  }

  it('Can get all users', () => {
    cy.request('GET', `${Cypress.env("api_server")}users`)
      .then((resp) => {
        expect(resp.status).to.eq(201)
        expect(resp.body.length).to.eq(3)
        expect(resp.body[0]).to.have.all.keys('id', 'username', 'password')
      })
  })

  // add a user using object params
  it('Can signup a new user', () => {
    const randomId = Cypress._.random(0, 10000)
    cy.request({
      url: `${Cypress.env("api_server")}users`,
      method: 'POST',
      body: {
        username: user.username,
        password: user.password
      }
    }).then((resp) => {
      expect(resp.status).to.eq(201)
      expect(resp.body.id_token).to.exist
      expect(resp.body.id_token).to.not.be.empty
    })
  })

  it('Can login', () => {
    cy.request({
      url: `${Cypress.env("api_server")}sessions/create`,
      method: 'POST',
      body: {
        username: user.username,
        password: user.password
      }
    }).then((resp) => {
      expect(resp.status).to.eq(201)
      expect(resp.body.id_token).to.exist
      expect(resp.body.id_token).to.not.be.empty
    })
  })
})
