Initial commit
This commit is contained in:
126
users-manage/tests/store/services.test.js
Normal file
126
users-manage/tests/store/services.test.js
Normal file
@@ -0,0 +1,126 @@
|
||||
import { expect, test, describe, vi, beforeEach} from "vitest";
|
||||
|
||||
import { createStore } from 'vuex'
|
||||
import {store as services} from "@/store/modules/services"
|
||||
import axios from "axios";
|
||||
|
||||
vi.mock('axios')
|
||||
|
||||
describe("tests services store with vuex", () => {
|
||||
const store = createStore({
|
||||
plugins: [],
|
||||
modules: {
|
||||
services
|
||||
},
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
store.dispatch('services/resetStore')
|
||||
})
|
||||
|
||||
test('upload sites data', async () => {
|
||||
const mockData = [
|
||||
{
|
||||
"id": 1,
|
||||
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
||||
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
||||
"deleted_at": null,
|
||||
"name": "jsonplaceholder.typicode.com",
|
||||
"port": 9965,
|
||||
"proxy_ip": "172.25.78.153",
|
||||
"site_ip": "172.25.78.153",
|
||||
"internet_uri": "localhost",
|
||||
"description": "localhost",
|
||||
"is_online": true
|
||||
}
|
||||
]
|
||||
|
||||
const expectedData = [
|
||||
{
|
||||
"id": 1,
|
||||
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
||||
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
||||
"deleted_at": null,
|
||||
"name": "jsonplaceholder.typicode.com",
|
||||
"port": 9965,
|
||||
"proxy_ip": "172.25.78.153",
|
||||
"device_ip": "172.25.78.153",
|
||||
"internet_uri": "localhost",
|
||||
"description": "localhost",
|
||||
"is_online": true
|
||||
}
|
||||
]
|
||||
|
||||
axios.get.mockResolvedValue({
|
||||
data: mockData,
|
||||
})
|
||||
|
||||
await store.dispatch('services/uploadSites')
|
||||
const sites = store.getters['services/sites']
|
||||
|
||||
expect(sites).toEqual(expectedData)
|
||||
})
|
||||
|
||||
test('test addNewSiteLayout function', async () => {
|
||||
const expectedSiteData = {"port": "", "name": "", id: -1}
|
||||
|
||||
store.dispatch('services/addNewSiteLayout')
|
||||
const selectedSite = store.getters['services/selectedSite']
|
||||
const sites = store.getters['services/sites']
|
||||
|
||||
expect(
|
||||
{
|
||||
selectedSite,
|
||||
sites
|
||||
}
|
||||
).toEqual({
|
||||
selectedSite: expectedSiteData,
|
||||
sites: [expectedSiteData]
|
||||
})
|
||||
})
|
||||
|
||||
test("test uploadAndSelectService function", async () => {
|
||||
const mockData = [
|
||||
{
|
||||
"id": 1,
|
||||
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
||||
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
||||
"deleted_at": null,
|
||||
"name": "jsonplaceholder.typicode.com",
|
||||
"port": 9965,
|
||||
"proxy_ip": "172.25.78.153",
|
||||
"site_ip": "172.25.78.153",
|
||||
"internet_uri": "localhost",
|
||||
"description": "localhost",
|
||||
"is_online": true
|
||||
}
|
||||
]
|
||||
|
||||
axios.get.mockResolvedValue({
|
||||
data: mockData,
|
||||
})
|
||||
|
||||
await store.dispatch('services/uploadSites')
|
||||
store.dispatch('services/uploadAndSelectService', 1)
|
||||
|
||||
const selectedSite = store.getters['services/selectedSite']
|
||||
const selectedSiteState = store.getters['services/selectedSiteState']
|
||||
|
||||
expect(selectedSite).toEqual({
|
||||
"id": 1,
|
||||
"created_at": "2024-02-22T17:08:37.715772388+03:00",
|
||||
"updated_at": "2024-02-26T14:11:38.64094899+03:00",
|
||||
"deleted_at": null,
|
||||
"name": "jsonplaceholder.typicode.com",
|
||||
"port": 9965,
|
||||
"proxy_ip": "172.25.78.153",
|
||||
"device_ip": "172.25.78.153",
|
||||
"internet_uri": "localhost",
|
||||
"description": "localhost",
|
||||
"is_online": true
|
||||
})
|
||||
expect(selectedSiteState).toEqual('active')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
56
users-manage/tests/store/users.test.js
Normal file
56
users-manage/tests/store/users.test.js
Normal file
@@ -0,0 +1,56 @@
|
||||
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)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user