2024-03-05 11:36:21 +03:00

57 lines
1.1 KiB
JavaScript

import { expect, test, describe, vi, beforeEach} from "vitest";
import { createStore } from 'vuex'
import {store as users} from "@/store/modules/users"
import axios from "axios";
vi.mock('axios')
describe("tests services store with vuex", () => {
const store = createStore({
plugins: [],
modules: {
users
},
})
beforeEach(() => {
store.dispatch('users/resetStore')
})
test('test fetchUsersList function', async () => {
const mockData = [
{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}
]
axios.get.mockResolvedValue({
data: mockData,
})
const expectedData = [
{
"id": 1,
"first_name": "Leanne",
"last_name": "Graham",
"email": "test@mail.ru",
"role": "admin",
"is_active": true
}
]
await store.dispatch('users/fetchUsersList', {siteId: 1, mode: "prod"})
const sites = store.getters['users/usersList']
expect(sites).toEqual(expectedData)
})
})