import {describe, expect, test, vi} from "vitest";
import AdapterOfUsers from '@adapters/adapterOfUsers/Users'
import axios from "axios";
import {apiUser, appUser} from '@mocks/users.js'

vi.mock('axios')

describe('test for AdapterOfUsers', () => {
  const adapterOfUsers = new AdapterOfUsers('http://localhost:8080')

  test('init', () => {
    expect(adapterOfUsers).toBeDefined()
  })

  test('getUsersBySiteId', async () => {
    axios.get.mockResolvedValue({
      data: [apiUser],
    })

    const users = await adapterOfUsers.getUsersByServiceId(1)
    expect(users).toEqual([appUser])
  })

  test('getUsers', async () => {
    axios.get.mockResolvedValue({
      data: [apiUser],
    })

    const users = await adapterOfUsers.getUsers()
    expect(users).toEqual([appUser])
  })

  test('updateUser', async () => {
    axios.put.mockResolvedValue({
      data: apiUser,
    })

    const user = await adapterOfUsers.updateUser(appUser)
    expect(user).toEqual(appUser)
  })

  test('createUser', async () => {
    axios.post.mockResolvedValue({
      data: apiUser,
    })

    const user = await adapterOfUsers.createUser()
    expect(user).toEqual(appUser)
  })

  test('removeUser', async () => {
    axios.delete.mockResolvedValue({
      data: apiUser,
    })

    const user = await adapterOfUsers.removeUser(appUser.id)
    expect(user).toEqual(appUser)
  })
})
