{"size": 3318, "ext": "js", "max_stars_repo_path": "test/resources/Users.spec.js", "max_stars_repo_name": "stelace/stelace-js-sdk", "max_stars_repo_stars_event_min_datetime": "2019-08-02T00:43:02.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-27T19:29:45.000Z", "max_issues_repo_path": "test/resources/Users.spec.js", "max_issues_repo_name": "stelace/stelace-js-sdk", "max_issues_repo_issues_event_min_datetime": "2019-07-12T18:30:11.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T04:05:50.000Z", "max_forks_repo_path": "test/resources/Users.spec.js", "max_forks_repo_name": "stelace/stelace-js-sdk", "max_forks_repo_forks_event_min_datetime": "2020-12-16T18:55:27.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-29T13:35:35.000Z"}
{"max_stars_count": 4, "max_issues_count": 111, "max_forks_count": 2, "avg_line_length": 26.7580645161, "max_line_length": 102, "alphanum_fraction": 0.5530440024}
import test from 'blue-tape'

import { getSpyableStelace } from '../../testUtils'

const stelace = getSpyableStelace()

test('checkAvailability: sends the correct request', (t) => {
  return stelace.users.checkAvailability({ username: 'foo@bar.com' })
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'GET',
        path: '/users/check-availability',
        data: {},
        queryParams: { username: 'foo@bar.com' },
        headers: {}
      })
    })
})

test('list: sends the correct request', (t) => {
  return stelace.users.list({ page: 2, nbResultsPerPage: 10 })
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'GET',
        path: '/users',
        data: {},
        queryParams: { page: 2, nbResultsPerPage: 10 },
        headers: {}
      })
    })
})

test('read: sends the correct request', (t) => {
  return stelace.users.read('user_1')
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'GET',
        path: '/users/user_1',
        data: {},
        queryParams: {},
        headers: {}
      })
    })
})

test('create: sends the correct request', (t) => {
  return stelace.users.create({ username: 'Foo', password: 'secretPassword' })
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'POST',
        path: '/users',
        data: { username: 'Foo', password: 'secretPassword' },
        queryParams: {},
        headers: {}
      })
    })
})

test('update: sends the correct request', (t) => {
  return stelace.users.update('user_1', { displayName: 'FooBar' })
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'PATCH',
        path: '/users/user_1',
        data: { displayName: 'FooBar' },
        queryParams: {},
        headers: {}
      })
    })
})

test('remove: sends the correct request', (t) => {
  return stelace.users.remove('user_1')
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'DELETE',
        path: '/users/user_1',
        data: {},
        queryParams: {},
        headers: {}
      })
    })
})

// DEPRECATED
test('updateOrganization: sends the correct request', (t) => {
  return stelace.users.updateOrganization('user_1', 'organization_1', { roles: ['user'] })
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'PUT',
        path: '/users/user_1/organizations/organization_1',
        data: { roles: ['user'] },
        queryParams: {},
        headers: {}
      })
    })
})
// DEPRECATED:END
test('joinOrganizationOrUpdateRights: sends the correct request', (t) => {
  return stelace.users.joinOrganizationOrUpdateRights('user_1', 'organization_1', { roles: ['user'] })
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'PUT',
        path: '/users/user_1/organizations/organization_1',
        data: { roles: ['user'] },
        queryParams: {},
        headers: {}
      })
    })
})

test('removeFromOrganization: sends the correct request', (t) => {
  return stelace.users.removeFromOrganization('user_1', 'organization_1')
    .then(() => {
      t.deepEqual(stelace.LAST_REQUEST, {
        method: 'DELETE',
        path: '/users/user_1/organizations/organization_1',
        data: {},
        queryParams: {},
        headers: {}
      })
    })
})
