{"size": 913, "ext": "js", "max_stars_repo_path": "src/use-cases/add-user/add-user.spec.js", "max_stars_repo_name": "gebhartn/user-service", "max_stars_repo_stars_event_min_datetime": "2020-08-24T14:45:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-15T04:08:42.000Z", "max_issues_repo_path": "src/use-cases/add-user/add-user.spec.js", "max_issues_repo_name": "gebhartn/user-service", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/use-cases/add-user/add-user.spec.js", "max_forks_repo_name": "gebhartn/user-service", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.4102564103, "max_line_length": 63, "alphanum_fraction": 0.6155531216}
import { makeAddUser } from './'
import { makeUsersDb } from '../../data-access/users-db'
import { makeFakeUser } from '../../../__tests__/fixtures/user'
import { makeDb } from '../../../__tests__/fixtures/db'

describe('add user', () => {
  let usersDb

  beforeAll(() => {
    usersDb = makeUsersDb({ makeDb })
  })

  afterEach(async () => {
    await makeDb().clear()
  })

  it('inserts a user to the database', async () => {
    const newUser = makeFakeUser()
    const addUser = makeAddUser({ usersDb })

    const inserted = await addUser(newUser)

    return expect(inserted.email).toBe(newUser.email)
  })

  it('throws if a user already exists', async () => {
    const newUser = makeFakeUser()
    const addUser = makeAddUser({ usersDb })

    await addUser(newUser)

    try {
      await addUser(newUser)
    } catch (e) {
      return expect(e.message).toMatch('User already exists')
    }
  })
})
