feat(feat(init): serviceOfMachines):

This commit is contained in:
2024-03-26 16:03:24 +03:00
parent 6eb9973b61
commit f6ca446f92
22 changed files with 4644 additions and 458 deletions

View File

@@ -1,2 +1,22 @@
import {describe, test, expect} from 'vitest'
import AdapterOfMachines from "@adapters/AdapterOfMachines.js"
import {de} from 'vitest'
import axios from 'axios'
import {apiModalListMachines, appModalListMachines} from "@mocks/machines.js"
vi.mock('axios')
describe('AdapterOfMachines', () => {
axios.post.mockResolvedValue({data: apiModalListMachines})
test('AdapterOfMachines should be a object', () => {
const adapterOfMachines = new AdapterOfMachines('')
expect(typeof adapterOfMachines).toBe('object')
})
test('test of fetchMachines', async () => {
const adapterOfMachines = new AdapterOfMachines('http://localhost:5444')
const result = await adapterOfMachines.getModalMachines()
expect(result).toEqual(appModalListMachines)
})
})

View File

@@ -0,0 +1,19 @@
import axios from 'axios'
import {describe, test, expect, vi} from 'vitest'
import {apiModalListMachines} from "@mocks/machines.js"
import {scandApiRequest} from "@helpers/apiHelpers.js"
vi.mock('axios')
describe('scandApiRequest', () => {
test('scandApiRequest should be a function', () => {
expect(typeof scandApiRequest).toBe('function')
})
test('scandApiRequest should return a promise', async () => {
axios.post.mockResolvedValue({data: apiModalListMachines})
const result = await scandApiRequest('ScandApi.LiveMonitor.Machines', 'select_machines', [])
expect(result).toEqual(apiModalListMachines)
})
})

View File

@@ -0,0 +1,41 @@
import {vi} from 'vitest'
const apiModalMachine = {
"zav_nomer": "007",
"type": "АВФ-1М.2",
"railway_name": "РЖД",
"org_name": "ДКРЭ",
"nomer_zn8": 19413152,
"machine_type": "АВФ-1М.2 № 007",
"machine_id": 5862,
"imei": 868136032634217,
"device_number": "КР190617",
"device_id": 6248
}
const appModalMachine = {
"zavNomer": "007",
"type": "АВФ-1М.2",
"railwayName": "РЖД",
"orgName": "ДКРЭ",
"nomerZn8": 19413152,
"machineType": "АВФ-1М.2 № 007",
"machineId": 5862,
"imei": 868136032634217,
"deviceNumber": "КР190617",
"deviceId": 6248
}
const apiModalListMachines = [apiModalMachine]
const appModalListMachines = [appModalMachine]
class AdapterOfMachines {
constructor(url) {
this.url = url
}
getModalMachines (){
return appModalListMachines
}
}
export { apiModalMachine, appModalMachine, apiModalListMachines, appModalListMachines, AdapterOfMachines}

View File

@@ -0,0 +1,38 @@
import {expect, describe, vi, test, beforeEach} from 'vitest'
import ServiceOfMachines from "@services/ServiceOfMachines.js"
import {AdapterOfMachines, appModalListMachines} from "@mocks/machines.js"
import { createStore } from "vuex"
import { store as machines } from '@/store/modules/machines';
describe('test ServiceOfMachines', () => {
const adapterOfMachines = new AdapterOfMachines('')
const store = createStore({
modules: {
machines
}
})
beforeEach(() => {
store.dispatch('machines/resetStore')
})
const serviceOfMachines = new ServiceOfMachines(adapterOfMachines, store)
test('test fetchModalMachines', async () => {
const result = await serviceOfMachines.fetchModalMachines()
expect(result).toEqual(appModalListMachines)
})
test('test putModalMachines', async () => {
await serviceOfMachines.putModalMachines(appModalListMachines)
const result = store.getters['machines/modalMachines']
expect(result).toEqual(appModalListMachines)
})
test('test makeFetchAndPutModalMachines', async () => {
const funcResult = await serviceOfMachines.makeFetchAndPutModalMachines()
const storeResult = store.getters['machines/modalMachines']
expect(funcResult).toEqual(appModalListMachines)
expect(storeResult).toEqual(appModalListMachines)
})
})

View File

@@ -0,0 +1,24 @@
import {describe, test, expect, beforeEach} from 'vitest'
import {createStore} from "vuex"
import { store as machines } from '@/store/modules/machines';
describe('machines store', () => {
const store = createStore({
modules: {
machines
}
})
beforeEach(() => {
store.dispatch('machines/resetStore')
})
test('machines should be a object', () => {
expect(typeof machines).toBe('object')
})
test('modalMachines should be a array', () => {
expect(store.getters['machines/modalMachines']).toEqual([])
store.dispatch('machines/saveModalMachines', [1, 2, 3])
expect(store.getters['machines/modalMachines']).toEqual([1, 2, 3])
})
})