lm-piplines/tests/adapters/AdapterOfMachines.test.js
2024-04-24 11:13:56 +03:00

39 lines
1.3 KiB
JavaScript

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])
})
})