Initial commit
This commit is contained in:
39
tests/adapters/AdapterOfMachines.test.js
Normal file
39
tests/adapters/AdapterOfMachines.test.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import {describe, test, expect, vi} from 'vitest'
|
||||
import AdapterOfMachines from "@adapters/AdapterOfMachines.js"
|
||||
import axios from 'axios'
|
||||
import {apiModalListMachines, appModalListMachines, defaultLastMachines, resLastMachines} from "@mocks/machines.js"
|
||||
|
||||
vi.mock('axios')
|
||||
|
||||
|
||||
describe('AdapterOfMachines', () => {
|
||||
|
||||
test('AdapterOfMachines should be a object', () => {
|
||||
const adapterOfMachines = new AdapterOfMachines('')
|
||||
expect(typeof adapterOfMachines).toBe('object')
|
||||
})
|
||||
|
||||
test('test of fetchMachines', async () => {
|
||||
|
||||
axios.post.mockResolvedValue({data: apiModalListMachines})
|
||||
|
||||
const adapterOfMachines = new AdapterOfMachines('http://localhost:5444')
|
||||
const result = await adapterOfMachines.fetchModalMachines()
|
||||
expect(result).toEqual(appModalListMachines)
|
||||
})
|
||||
|
||||
test('Get last machines by pack number', async () => {
|
||||
|
||||
axios.post.mockResolvedValue({data: defaultLastMachines})
|
||||
const params = [7683]
|
||||
|
||||
const adapterOfPacks = new AdapterOfMachines('http://localhost:5444')
|
||||
const storeMachines = await adapterOfPacks.fetchLastMachinesByPackNum(params)
|
||||
|
||||
expect(storeMachines.length).toBeGreaterThan(0)
|
||||
expect(storeMachines.length).toBe(3)
|
||||
expect(storeMachines[0].packNumber).toBe(7683)
|
||||
expect(storeMachines[0]).toEqual(resLastMachines[0])
|
||||
})
|
||||
|
||||
})
|
||||
43
tests/adapters/ApiOfPacks.test.js
Normal file
43
tests/adapters/ApiOfPacks.test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import {describe, test, expect, vi} from 'vitest'
|
||||
import ApiOfPacks from "@api/ApiOfPacks.js"
|
||||
import { defaultLastPacks, defaultFreePacks, defaultParams, freePacksParams } from '@mocks/packs'
|
||||
import axios from 'axios'
|
||||
|
||||
vi.mock('axios')
|
||||
|
||||
describe('ApiOfPacks', () => {
|
||||
|
||||
test('ApiOfPacks should be a object', () => {
|
||||
const apiOfPacks = new ApiOfPacks('')
|
||||
expect(typeof apiOfPacks).toBe('object')
|
||||
})
|
||||
|
||||
test('Get last packs', async () => {
|
||||
|
||||
axios.post.mockResolvedValue({data: defaultLastPacks})
|
||||
const params = [defaultParams.imei, defaultParams.dtStart, defaultParams.dtFinish]
|
||||
|
||||
const apiOfPacks = new ApiOfPacks('http://localhost:5444')
|
||||
const storePacks = await apiOfPacks.fetchLastPacks(params)
|
||||
|
||||
expect(storePacks.length).toBeGreaterThan(0)
|
||||
expect(storePacks.length).toBe(6)
|
||||
expect(storePacks[0].pack_number).toBe(1)
|
||||
expect(storePacks).toEqual(defaultLastPacks)
|
||||
})
|
||||
|
||||
test('Get free packs', async () => {
|
||||
|
||||
axios.post.mockResolvedValue({data: defaultFreePacks})
|
||||
const params = [freePacksParams[0]]
|
||||
|
||||
const apiOfPacks = new ApiOfPacks('http://localhost:5444')
|
||||
const storeFreePacks = await apiOfPacks.fetchFreePacks(params)
|
||||
|
||||
expect(storeFreePacks.logs.length).toBeGreaterThan(0)
|
||||
expect(storeFreePacks.logs.length).toBe(2)
|
||||
expect(storeFreePacks.maxDataLength).toEqual(defaultFreePacks.maxDataLength)
|
||||
expect(storeFreePacks).toEqual(defaultFreePacks)
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user