@davra/ui-core 1.0.0-alpha.2 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +1 -2
  2. package/src/assets/fonts/myfont.woff +0 -0
  3. package/src/assets/main.scss +0 -17
  4. package/src/auto-imports.d.ts +0 -200
  5. package/src/components/ComponentA.vue +0 -13
  6. package/src/components/ComponentB.vue +0 -26
  7. package/src/components/index.ts +0 -7
  8. package/src/constants/MyConstants.ts +0 -1
  9. package/src/constants/index.ts +0 -5
  10. package/src/env.d.ts +0 -8
  11. package/src/index.ts +0 -23
  12. package/src/services/davraApi.ts +0 -18
  13. package/src/services/devicesCountersService.test.ts +0 -209
  14. package/src/services/devicesCountersService.ts +0 -117
  15. package/src/services/devicesService.test.ts +0 -207
  16. package/src/services/devicesService.ts +0 -110
  17. package/src/services/index.ts +0 -22
  18. package/src/services/labelsService.test.ts +0 -124
  19. package/src/services/labelsService.ts +0 -71
  20. package/src/services/metricsCountersService.test.ts +0 -44
  21. package/src/services/metricsCountersService.ts +0 -24
  22. package/src/services/metricsService.test.ts +0 -97
  23. package/src/services/metricsService.ts +0 -54
  24. package/src/services/timeseriesService.test.ts +0 -86
  25. package/src/services/timeseriesService.ts +0 -24
  26. package/src/services/twinTypesService.test.ts +0 -74
  27. package/src/services/twinTypesService.ts +0 -24
  28. package/src/services/twinsCountersService.test.ts +0 -72
  29. package/src/services/twinsCountersService.ts +0 -40
  30. package/src/services/twinsService.test.ts +0 -228
  31. package/src/services/twinsService.ts +0 -137
  32. package/src/services/userSessionService.test.ts +0 -74
  33. package/src/services/userSessionService.ts +0 -82
  34. package/src/stores/alertMessages.test.ts +0 -27
  35. package/src/stores/alertMessages.ts +0 -26
  36. package/src/stores/devices.test.ts +0 -149
  37. package/src/stores/devices.ts +0 -78
  38. package/src/stores/index.ts +0 -12
  39. package/src/stores/labels.test.ts +0 -72
  40. package/src/stores/labels.ts +0 -39
  41. package/src/stores/metrics.test.ts +0 -116
  42. package/src/stores/metrics.ts +0 -71
  43. package/src/stores/twinTypes.test.ts +0 -71
  44. package/src/stores/twinTypes.ts +0 -36
  45. package/src/stores/twins.test.ts +0 -148
  46. package/src/stores/twins.ts +0 -78
  47. package/src/stores/userSession.test.ts +0 -107
  48. package/src/stores/userSession.ts +0 -57
  49. package/src/types.ts +0 -173
  50. package/src/utils/MyUtil.ts +0 -7
  51. package/src/utils/index.ts +0 -5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@davra/ui-core",
3
3
  "types": "./dist/types/index.d.ts",
4
- "version": "1.0.0-alpha.2",
4
+ "version": "1.0.0-alpha.3",
5
5
  "scripts": {
6
6
  "build": "rimraf dist && vue-tsc && vite build",
7
7
  "build:watch": "rimraf dist && vue-tsc && vite build --watch",
@@ -31,7 +31,6 @@
31
31
  "unplugin-auto-import": "^0.16.7"
32
32
  },
33
33
  "files": [
34
- "src",
35
34
  "dist"
36
35
  ],
37
36
  "module": "./dist/ui-core.es.js",
Binary file
@@ -1,17 +0,0 @@
1
- @font-face {
2
- font-family: 'myfont';
3
- src: url('fonts/myfont.woff');
4
- }
5
-
6
- [class^='icon-'],
7
- [class*=' icon-'] {
8
- font-family: 'myfont' !important;
9
- }
10
-
11
- .icon-heart:before {
12
- content: '\e9da';
13
- }
14
-
15
- .global-example {
16
- color: red;
17
- }
@@ -1,200 +0,0 @@
1
- /* eslint-disable */
2
- /* prettier-ignore */
3
- // @ts-nocheck
4
- // noinspection JSUnusedGlobalSymbols
5
- // Generated by unplugin-auto-import
6
- export {}
7
- declare global {
8
- const EffectScope: typeof import('vue')['EffectScope']
9
- const computed: typeof import('vue')['computed']
10
- const createApp: typeof import('vue')['createApp']
11
- const customRef: typeof import('vue')['customRef']
12
- const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
13
- const defineComponent: typeof import('vue')['defineComponent']
14
- const effectScope: typeof import('vue')['effectScope']
15
- const getCurrentInstance: typeof import('vue')['getCurrentInstance']
16
- const getCurrentScope: typeof import('vue')['getCurrentScope']
17
- const h: typeof import('vue')['h']
18
- const inject: typeof import('vue')['inject']
19
- const isProxy: typeof import('vue')['isProxy']
20
- const isReactive: typeof import('vue')['isReactive']
21
- const isReadonly: typeof import('vue')['isReadonly']
22
- const isRef: typeof import('vue')['isRef']
23
- const markRaw: typeof import('vue')['markRaw']
24
- const nextTick: typeof import('vue')['nextTick']
25
- const onActivated: typeof import('vue')['onActivated']
26
- const onBeforeMount: typeof import('vue')['onBeforeMount']
27
- const onBeforeUnmount: typeof import('vue')['onBeforeUnmount']
28
- const onBeforeUpdate: typeof import('vue')['onBeforeUpdate']
29
- const onDeactivated: typeof import('vue')['onDeactivated']
30
- const onErrorCaptured: typeof import('vue')['onErrorCaptured']
31
- const onMounted: typeof import('vue')['onMounted']
32
- const onRenderTracked: typeof import('vue')['onRenderTracked']
33
- const onRenderTriggered: typeof import('vue')['onRenderTriggered']
34
- const onScopeDispose: typeof import('vue')['onScopeDispose']
35
- const onServerPrefetch: typeof import('vue')['onServerPrefetch']
36
- const onUnmounted: typeof import('vue')['onUnmounted']
37
- const onUpdated: typeof import('vue')['onUpdated']
38
- const provide: typeof import('vue')['provide']
39
- const reactive: typeof import('vue')['reactive']
40
- const readonly: typeof import('vue')['readonly']
41
- const ref: typeof import('vue')['ref']
42
- const resolveComponent: typeof import('vue')['resolveComponent']
43
- const shallowReactive: typeof import('vue')['shallowReactive']
44
- const shallowReadonly: typeof import('vue')['shallowReadonly']
45
- const shallowRef: typeof import('vue')['shallowRef']
46
- const toRaw: typeof import('vue')['toRaw']
47
- const toRef: typeof import('vue')['toRef']
48
- const toRefs: typeof import('vue')['toRefs']
49
- const toValue: typeof import('vue')['toValue']
50
- const triggerRef: typeof import('vue')['triggerRef']
51
- const unref: typeof import('vue')['unref']
52
- const useAlertMessagesStore: typeof import('./stores/index')['useAlertMessagesStore']
53
- const useAttrs: typeof import('vue')['useAttrs']
54
- const useCssModule: typeof import('vue')['useCssModule']
55
- const useCssVars: typeof import('vue')['useCssVars']
56
- const useDevicesStore: typeof import('./stores/index')['useDevicesStore']
57
- const useLabelsStore: typeof import('./stores/labels')['useLabelsStore']
58
- const useMetricsStore: typeof import('./stores/metrics')['useMetricsStore']
59
- const useSlots: typeof import('vue')['useSlots']
60
- const useTwinTypesStore: typeof import('./stores/twinTypes')['useTwinTypesStore']
61
- const useTwinsStore: typeof import('./stores/twins')['useTwinsStore']
62
- const useUserSessionStore: typeof import('./stores/userSession')['useUserSessionStore']
63
- const watch: typeof import('vue')['watch']
64
- const watchEffect: typeof import('vue')['watchEffect']
65
- const watchPostEffect: typeof import('vue')['watchPostEffect']
66
- const watchSyncEffect: typeof import('vue')['watchSyncEffect']
67
- }
68
- // for type re-export
69
- declare global {
70
- // @ts-ignore
71
- export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue'
72
- }
73
- // for vue template auto import
74
- import { UnwrapRef } from 'vue'
75
- declare module 'vue' {
76
- interface ComponentCustomProperties {
77
- readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
78
- readonly computed: UnwrapRef<typeof import('vue')['computed']>
79
- readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
80
- readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
81
- readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
82
- readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
83
- readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
84
- readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
85
- readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
86
- readonly h: UnwrapRef<typeof import('vue')['h']>
87
- readonly inject: UnwrapRef<typeof import('vue')['inject']>
88
- readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
89
- readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
90
- readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']>
91
- readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
92
- readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
93
- readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
94
- readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
95
- readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
96
- readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
97
- readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
98
- readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
99
- readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']>
100
- readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']>
101
- readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']>
102
- readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']>
103
- readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']>
104
- readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']>
105
- readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
106
- readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
107
- readonly provide: UnwrapRef<typeof import('vue')['provide']>
108
- readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
109
- readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
110
- readonly ref: UnwrapRef<typeof import('vue')['ref']>
111
- readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
112
- readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
113
- readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
114
- readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
115
- readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']>
116
- readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
117
- readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
118
- readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
119
- readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
120
- readonly unref: UnwrapRef<typeof import('vue')['unref']>
121
- readonly useAlertMessagesStore: UnwrapRef<typeof import('./stores/index')['useAlertMessagesStore']>
122
- readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
123
- readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
124
- readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
125
- readonly useDevicesStore: UnwrapRef<typeof import('./stores/index')['useDevicesStore']>
126
- readonly useLabelsStore: UnwrapRef<typeof import('./stores/labels')['useLabelsStore']>
127
- readonly useMetricsStore: UnwrapRef<typeof import('./stores/metrics')['useMetricsStore']>
128
- readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
129
- readonly useTwinTypesStore: UnwrapRef<typeof import('./stores/twinTypes')['useTwinTypesStore']>
130
- readonly useTwinsStore: UnwrapRef<typeof import('./stores/twins')['useTwinsStore']>
131
- readonly useUserSessionStore: UnwrapRef<typeof import('./stores/userSession')['useUserSessionStore']>
132
- readonly watch: UnwrapRef<typeof import('vue')['watch']>
133
- readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>
134
- readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']>
135
- readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']>
136
- }
137
- }
138
- declare module '@vue/runtime-core' {
139
- interface ComponentCustomProperties {
140
- readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
141
- readonly computed: UnwrapRef<typeof import('vue')['computed']>
142
- readonly createApp: UnwrapRef<typeof import('vue')['createApp']>
143
- readonly customRef: UnwrapRef<typeof import('vue')['customRef']>
144
- readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
145
- readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
146
- readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
147
- readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
148
- readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
149
- readonly h: UnwrapRef<typeof import('vue')['h']>
150
- readonly inject: UnwrapRef<typeof import('vue')['inject']>
151
- readonly isProxy: UnwrapRef<typeof import('vue')['isProxy']>
152
- readonly isReactive: UnwrapRef<typeof import('vue')['isReactive']>
153
- readonly isReadonly: UnwrapRef<typeof import('vue')['isReadonly']>
154
- readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
155
- readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
156
- readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
157
- readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
158
- readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
159
- readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
160
- readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
161
- readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
162
- readonly onErrorCaptured: UnwrapRef<typeof import('vue')['onErrorCaptured']>
163
- readonly onMounted: UnwrapRef<typeof import('vue')['onMounted']>
164
- readonly onRenderTracked: UnwrapRef<typeof import('vue')['onRenderTracked']>
165
- readonly onRenderTriggered: UnwrapRef<typeof import('vue')['onRenderTriggered']>
166
- readonly onScopeDispose: UnwrapRef<typeof import('vue')['onScopeDispose']>
167
- readonly onServerPrefetch: UnwrapRef<typeof import('vue')['onServerPrefetch']>
168
- readonly onUnmounted: UnwrapRef<typeof import('vue')['onUnmounted']>
169
- readonly onUpdated: UnwrapRef<typeof import('vue')['onUpdated']>
170
- readonly provide: UnwrapRef<typeof import('vue')['provide']>
171
- readonly reactive: UnwrapRef<typeof import('vue')['reactive']>
172
- readonly readonly: UnwrapRef<typeof import('vue')['readonly']>
173
- readonly ref: UnwrapRef<typeof import('vue')['ref']>
174
- readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
175
- readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
176
- readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
177
- readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
178
- readonly toRaw: UnwrapRef<typeof import('vue')['toRaw']>
179
- readonly toRef: UnwrapRef<typeof import('vue')['toRef']>
180
- readonly toRefs: UnwrapRef<typeof import('vue')['toRefs']>
181
- readonly toValue: UnwrapRef<typeof import('vue')['toValue']>
182
- readonly triggerRef: UnwrapRef<typeof import('vue')['triggerRef']>
183
- readonly unref: UnwrapRef<typeof import('vue')['unref']>
184
- readonly useAlertMessagesStore: UnwrapRef<typeof import('./stores/index')['useAlertMessagesStore']>
185
- readonly useAttrs: UnwrapRef<typeof import('vue')['useAttrs']>
186
- readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
187
- readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
188
- readonly useDevicesStore: UnwrapRef<typeof import('./stores/index')['useDevicesStore']>
189
- readonly useLabelsStore: UnwrapRef<typeof import('./stores/labels')['useLabelsStore']>
190
- readonly useMetricsStore: UnwrapRef<typeof import('./stores/metrics')['useMetricsStore']>
191
- readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
192
- readonly useTwinTypesStore: UnwrapRef<typeof import('./stores/twinTypes')['useTwinTypesStore']>
193
- readonly useTwinsStore: UnwrapRef<typeof import('./stores/twins')['useTwinsStore']>
194
- readonly useUserSessionStore: UnwrapRef<typeof import('./stores/userSession')['useUserSessionStore']>
195
- readonly watch: UnwrapRef<typeof import('vue')['watch']>
196
- readonly watchEffect: UnwrapRef<typeof import('vue')['watchEffect']>
197
- readonly watchPostEffect: UnwrapRef<typeof import('vue')['watchPostEffect']>
198
- readonly watchSyncEffect: UnwrapRef<typeof import('vue')['watchSyncEffect']>
199
- }
200
- }
@@ -1,13 +0,0 @@
1
- <script setup lang="ts">
2
- interface Props {
3
- msg: string
4
- }
5
-
6
- const props = defineProps<Props>()
7
- </script>
8
-
9
- <template>
10
- <div>
11
- Hello {{ msg }}! <span class="icon-heart" style="color:tomato"></span>
12
- </div>
13
- </template>
@@ -1,26 +0,0 @@
1
- <script setup lang="ts">
2
- import { ref } from 'vue'
3
- import Button from 'primevue/button'
4
- const count = ref(0)
5
- </script>
6
-
7
- <template>
8
- <div class="flex align-content-center flex-wrap counter">
9
- <label class="flex align-items-center justify-content-center">Counter:</label>
10
- <Button icon="pi pi-plus" class="p-button-sm flex align-items-center justify-content-center" @click="count++"></Button>
11
- <span class="flex align-items-center justify-content-center count">{{ count }}</span>
12
- <Button icon="pi pi-minus" class="p-button-sm flex align-items-center justify-content-center" @click="count--"></Button>
13
- </div>
14
- </template>
15
-
16
- <style lang="scss" scoped>
17
- .counter {
18
- label {
19
- padding-right: 10px;
20
- font-weight: bold;
21
- }
22
- .count {
23
- padding: 0 10px;
24
- }
25
- }
26
- </style>
@@ -1,7 +0,0 @@
1
- import ComponentA from './ComponentA.vue'
2
- import ComponentB from './ComponentB.vue'
3
-
4
- export {
5
- ComponentA,
6
- ComponentB
7
- }
@@ -1 +0,0 @@
1
- export const MAGIC_NUM = 100
@@ -1,5 +0,0 @@
1
- import * as MyConstants from './MyConstants'
2
-
3
- export {
4
- MyConstants
5
- }
package/src/env.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /// <reference types="vite/client" />
2
-
3
- declare module '*.vue' {
4
- import { DefineComponent } from 'vue'
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
6
- const component: DefineComponent<{}, {}, any>
7
- export default component
8
- }
package/src/index.ts DELETED
@@ -1,23 +0,0 @@
1
- import { App } from 'vue'
2
- import * as components from './components'
3
-
4
- function install (app: App) {
5
- for (const key in components) {
6
- // @ts-expect-error
7
- app.component(key, components[key])
8
- }
9
- }
10
-
11
- import './assets/main.scss'
12
-
13
- export { install }
14
-
15
- export * from './components'
16
- export * from './constants'
17
- export * from './utils'
18
-
19
- export * from './services'
20
-
21
- export * from './stores'
22
-
23
- export * from './types'
@@ -1,18 +0,0 @@
1
- import axios from 'axios'
2
-
3
- const DavraApiConfig = {
4
- baseURL: '',
5
- }
6
- const DavraApiClient = (defaultUrl = '') => {
7
- const axiosInstance = axios.create({
8
- ...DavraApiConfig,
9
- baseURL: defaultUrl || DavraApiConfig.baseURL,
10
- })
11
-
12
- return axiosInstance
13
- }
14
-
15
- export {
16
- DavraApiConfig,
17
- DavraApiClient
18
- }
@@ -1,209 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2
- import DevicesCountersService from '~/services/devicesCountersService'
3
- import type { DeviceCounterMetric } from '~/types'
4
- const mockGet = vi.fn()
5
- const mockPost = vi.fn()
6
-
7
- describe('DeviceCounters Service', () => {
8
- describe('getDevices', () => {
9
- const mockDevices: DeviceCounterMetric[] = [
10
- { id: '1', name: 'Device 1', totals: {}, values: {} },
11
- { id: '2', name: 'Device 2', totals: {}, values: {} },
12
- { id: '3', name: 'Device 3', totals: {}, values: {} },
13
- ] as any
14
-
15
- beforeEach(() => {
16
- vi.mock('./davraApi', () => {
17
- return {
18
- default: vi.fn(() => ({
19
- get: mockGet,
20
- post: mockPost,
21
- })),
22
- }
23
- })
24
- })
25
- afterEach(() => {
26
- vi.restoreAllMocks()
27
- })
28
-
29
- it('should return devices with default params', async () => {
30
- // Arrange
31
- const expectedUrl = '/api/v1/iotdata/devices/counters/metrics?'
32
- const expectedHeaders = { Accept: 'application/json' }
33
- const mockResponse = { data: mockDevices }
34
-
35
- const filters = undefined
36
- mockGet.mockResolvedValueOnce(mockResponse)
37
-
38
- // Act
39
- const result = await DevicesCountersService.getDevicesCountersMetric(filters)
40
-
41
- // Assert
42
- expect(mockGet).toHaveBeenCalledTimes(1)
43
- expect(mockGet).toHaveBeenCalledWith(expectedUrl, { headers: expectedHeaders })
44
- expect(result).toEqual(mockDevices)
45
- })
46
-
47
- it('should return devices with custom params', async () => {
48
- // Arrange
49
- const expectedUrl = '/api/v1/iotdata/devices/counters/metrics?filter=type:camera'
50
- const expectedHeaders = { Accept: 'application/json' }
51
- const mockResponse = { data: mockDevices }
52
-
53
- const filters = 'filter=type:camera'
54
- mockGet.mockResolvedValueOnce(mockResponse)
55
-
56
- // Act
57
- const result = await DevicesCountersService.getDevicesCountersMetric(filters)
58
-
59
- // Assert
60
- expect(mockGet).toHaveBeenCalledWith(expectedUrl, { headers: expectedHeaders })
61
- expect(result).toEqual(mockDevices)
62
- })
63
-
64
- it('should throw an error if the API call fails', async () => {
65
- // Arrange
66
- const expectedError = new Error('Devices Counters API Error')
67
-
68
- const filters = undefined
69
- mockGet.mockRejectedValueOnce(expectedError)
70
-
71
- // Act + Assert
72
- await expect(DevicesCountersService.getDevicesCountersMetric(filters)).rejects.toThrow(expectedError)
73
- })
74
-
75
- describe('getDevicesCountersMetricByUUIDs', () => {
76
- it('should return an empty array when uuids is empty', async () => {
77
- mockGet.mockResolvedValueOnce({ data: [] })
78
-
79
- const result = await DevicesCountersService.getDevicesCountersMetricByUUIDs([])
80
- expect(result).toEqual([])
81
- })
82
-
83
- it('should return an array of devices when uuids are provided', async () => {
84
- mockGet.mockResolvedValueOnce({ data: [{ id: 1, name: 'DeviceCounter 1' }, { id: 2, name: 'DeviceCounter 2' }] })
85
-
86
- const result = await DevicesCountersService.getDevicesCountersMetricByUUIDs(['uuid1', 'uuid2'])
87
- expect(result).toEqual([{ id: 1, name: 'DeviceCounter 1' }, { id: 2, name: 'DeviceCounter 2' }])
88
- })
89
-
90
- it('should call with the correct URL and headers', async () => {
91
- const uuids = ['uuid1', 'uuid2']
92
- mockGet.mockResolvedValueOnce({ data: [] })
93
-
94
- await DevicesCountersService.getDevicesCountersMetricByUUIDs(uuids)
95
- expect(mockGet).toHaveBeenCalledWith(`/api/v1/iotdata/devices/counters/metrics?arrayUUIDs=${uuids.join(',')}`, {
96
- headers: {
97
- Accept: 'application/json',
98
- },
99
- })
100
- })
101
-
102
- it('should return an empty array when an error occurs', async () => {
103
- const expectedError = new Error('Devices Counters API Error')
104
- mockGet.mockRejectedValueOnce(new Error('qweqwe API Error'))
105
- await expect(DevicesCountersService.getDevicesCountersMetricByUUIDs(['uuid1', 'uuid2'])).rejects.toThrow(expectedError)
106
- })
107
- })
108
-
109
- describe('getDevicesCountersMetricByUUID', () => {
110
- it('returns the device record for a valid UUID', async () => {
111
- const uuid = '12345'
112
- const expectedDevice: DeviceCounterMetric = { id: 1, name: 'Device 1', total: {}, values: {} } as any
113
- const mockedResponse = { data: [expectedDevice] }
114
- mockGet.mockResolvedValueOnce(mockedResponse)
115
-
116
- const result = await DevicesCountersService.getDevicesCountersMetricByUUID(uuid)
117
-
118
- expect(mockGet).toHaveBeenCalledWith(`/api/v1/iotdata/devices/counters/metrics/${uuid}`, { headers: { Accept: 'application/json' } })
119
- expect(result).toEqual([expectedDevice])
120
- })
121
-
122
- it('should throw an error if the API call fails', async () => {
123
- const uuid = 'invalid'
124
- const expectedError = new Error('Devices Counters API Error')
125
- mockGet.mockRejectedValueOnce(expectedError)
126
-
127
- await expect(DevicesCountersService.getDevicesCountersMetricByUUID(uuid)).rejects.toThrow(expectedError)
128
- })
129
- })
130
-
131
- describe('getDevicesCountersByUUID', () => {
132
- it('returns the device record for a valid UUID', async () => {
133
- const uuid = '12345'
134
- const expectedDevice: DeviceCounterMetric = { id: 1, name: 'Device 1', total: {}, values: {} } as any
135
- const mockedResponse = { data: [expectedDevice] }
136
- mockGet.mockResolvedValueOnce(mockedResponse)
137
-
138
- const result = await DevicesCountersService.getDevicesCountersByUUID(uuid)
139
-
140
- expect(mockGet).toHaveBeenCalledWith(`/api/v1/iotdata/devices/counters/${uuid}`, { headers: { Accept: 'application/json' } })
141
- expect(result).toEqual([expectedDevice])
142
- })
143
-
144
- it('should throw an error if the API call fails', async () => {
145
- const uuid = 'invalid'
146
- const expectedError = new Error('Devices Counters API Error')
147
- mockGet.mockRejectedValueOnce(expectedError)
148
-
149
- await expect(DevicesCountersService.getDevicesCountersByUUID(uuid)).rejects.toThrow(expectedError)
150
- })
151
- })
152
-
153
- describe('getDevicesCountersLatestByUUID', () => {
154
- it('returns the device record for a valid UUID', async () => {
155
- const uuid = '12345'
156
- const expectedDevice: DeviceCounterMetric = { id: 1, name: 'Device 1', total: {}, values: {} } as any
157
- const mockedResponse = { data: [expectedDevice] }
158
- mockGet.mockResolvedValueOnce(mockedResponse)
159
-
160
- const result = await DevicesCountersService.getDevicesCountersLatestByUUID(uuid)
161
-
162
- expect(mockGet).toHaveBeenCalledWith(`/api/v1/iotdata/devices/counters/latest/${uuid}`, { headers: { Accept: 'application/json' } })
163
- expect(result).toEqual(expectedDevice)
164
- })
165
-
166
- it('should throw an error if the API call fails', async () => {
167
- const uuid = 'invalid'
168
- const expectedError = new Error('Devices Counters API Error')
169
- mockGet.mockRejectedValueOnce(expectedError)
170
-
171
- await expect(DevicesCountersService.getDevicesCountersLatestByUUID(uuid)).rejects.toThrow(expectedError)
172
- })
173
- })
174
-
175
- describe('getDevicesCountersLatestByUUIDs', () => {
176
- it('should return an empty array when uuids is empty', async () => {
177
- mockGet.mockResolvedValueOnce({ data: [] })
178
-
179
- const result = await DevicesCountersService.getDevicesCountersLatestByUUIDs([])
180
- expect(result).toEqual([])
181
- })
182
-
183
- it('should return an array of devices when uuids are provided', async () => {
184
- mockGet.mockResolvedValueOnce({ data: [{ id: 1, name: 'DeviceCounter 1' }, { id: 2, name: 'DeviceCounter 2' }] })
185
-
186
- const result = await DevicesCountersService.getDevicesCountersLatestByUUIDs(['uuid1', 'uuid2'])
187
- expect(result).toEqual([{ id: 1, name: 'DeviceCounter 1' }, { id: 2, name: 'DeviceCounter 2' }])
188
- })
189
-
190
- it('should call with the correct URL and headers', async () => {
191
- const uuids = ['uuid1', 'uuid2']
192
- mockGet.mockResolvedValueOnce({ data: [] })
193
-
194
- await DevicesCountersService.getDevicesCountersLatestByUUIDs(uuids)
195
- expect(mockGet).toHaveBeenCalledWith(`/api/v1/iotdata/devices/counters/latest?arrayUUIDs=${uuids.join(',')}`, {
196
- headers: {
197
- Accept: 'application/json',
198
- },
199
- })
200
- })
201
-
202
- it('should return an empty array when an error occurs', async () => {
203
- const expectedError = new Error('Devices Counters API Error')
204
- mockGet.mockRejectedValueOnce(new Error('qweqwe API Error'))
205
- await expect(DevicesCountersService.getDevicesCountersLatestByUUIDs(['uuid1', 'uuid2'])).rejects.toThrow(expectedError)
206
- })
207
- })
208
- })
209
- })