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

43 lines
1.4 KiB
JavaScript

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