import {describe, expect, test, beforeEach} from "vitest";
import ServiceOfUsers from '@services/serviceOfUsers/Users.js'
import {adapterOfUsers, store} from './MockData.js'
import {appUser} from '@mocks/users.js'

describe('test for ServiceOfUsers', () => {
  const serviceOfUsers = new ServiceOfUsers(adapterOfUsers, store)

  beforeEach( async() => {
    await store.dispatch('users/resetStore')
  })

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

  test('saveSiteUsers', async () => {
    await serviceOfUsers.saveSiteUsers([appUser])
    const storeUsers = store.getters['users/siteUsers']
    expect(storeUsers).toEqual([appUser])
  })

  test('saveUsersWithoutSite', async () => {
    await serviceOfUsers.saveUsersWithoutSite([appUser])
    const storeUsers = store.getters['users/usersWithoutSite']
    expect(storeUsers).toEqual([appUser])
  })

  test('fetchUsersByService', async () => {
    const serviceId = 1
    await serviceOfUsers.fetchUsersByService(serviceId)
    const storeUsers = store.getters['users/siteUsers']
    expect(storeUsers).toEqual([appUser])
  })
})

