import { beforeEach, describe, expect, it, vi } from 'vitest'

const getMock = vi.fn()
const postMock = vi.fn()
const putMock = vi.fn()
const delMock = vi.fn()

vi.mock('@/lib/http/client', () => ({
  get: getMock,
  post: postMock,
  put: putMock,
  del: delMock,
}))

describe('users service', () => {
  beforeEach(() => {
    getMock.mockReset()
    postMock.mockReset()
    putMock.mockReset()
    delMock.mockReset()
  })

  it('creates a user through the protected users endpoint', async () => {
    const payload = {
      username: 'new-user',
      password: 'Pass123!@#',
      role_ids: [2],
    }

    const { createUser } = await import('./users')
    await createUser(payload)

    expect(postMock).toHaveBeenCalledWith('/users', payload)
  })
})
