Skip to content
代码片段 群组 项目
提交 da83c9b6 编辑于 作者: Thuc Tran's avatar Thuc Tran
浏览文件

ZAPP-146 Update query-config tests

上级 8dda83ce
No related branches found
No related tags found
无相关合并请求
......@@ -199,7 +199,15 @@ export const dbMap = {
networkId: x.NETWORK_IDENTIFIER,
}
},
endpointType: (x) => {
if (x == null) return undefined
return {
endpointTypeId: x.ENDPOINT_TYPE_ID,
sessionRef: x.SESSION_REF,
name: x.NAME,
deviceTypeRef: x.DEVICE_TYPE_REF,
}
},
endpointTypeCluster: (x) => {
if (x == null) return undefined
return {
......
......@@ -302,7 +302,7 @@ export function insertEndpoint(
) {
return DbApi.dbInsert(
db,
'INSERT OR REPLACE INTO ENDPOINT ( SESSION_REF, ENDPOINT_IDENTIFIER, ENDPOINT_TYPE_REF, NETWORK_IDENTIFIER ) VALUES ( ?, ?, ?, ?)',
'INSERT OR REPLACE INTO ENDPOINT ( SESSION_REF, ENDPOINT_IDENTIFIER, ENDPOINT_TYPE_REF, NETWORK_IDENTIFIER, PROFILE) VALUES ( ?, ?, ?, ?, SELECT DEVICE_TYPE.PROFILE_ID FROM DEVICE_TYPE, ENDPOINT_TYPE WHERE ENDPOINT_TYPE.ENDPOINT_TYPE_ID = ENDPOINT_TYPE_REF AND ENDPOINT_TYPE.DEVICE_TYPE_REF = DEVICE_TYPE.DEVICE_TYPE_ID)',
[sessionId, endpointIdentifier, endpointTypeRef, networkIdentifier]
)
}
......
......@@ -285,6 +285,14 @@ export function selectAllCommandArguments(db) {
).then((rows) => rows.map(DbMapping.dbMap.commandArgument))
}
export function selectEndpointType(db, id) {
return DbApi.dbGet(
db,
`SELECT ENDPOINT_TYPE_ID, SESSION_REF, NAME, DEVICE_TYPE_REF FROM ENDPOINT_TYPE WHERE ENDPOINT_TYPE_ID = ?`,
[id]
).then(DbMapping.dbMap.endpointType)
}
export function selectEndpointTypeClustersByEndpointTypeId(db, endpointTypeId) {
return DbApi.dbAll(
db,
......
......@@ -56,6 +56,8 @@ import {
getSessionKeyValue,
getAllEndpointTypes,
} from '../src-electron/db/query-config'
import * as QueryZcl from '../src-electron/db/query-zcl.js'
import * as QueryConfig from '../src-electron/db/query-config.js'
import {
insertFileLocation,
selectFileLocation,
......@@ -201,6 +203,10 @@ describe('Session specific queries', () => {
.then((value) => {
expect(value).toBe('value2')
})
.then(() => getSessionKeyValue(db, sid, 'nonexistent'))
.then((value) => {
expect(value).toBeUndefined()
})
})
test('Make sure session is dirty', () => {
......@@ -302,3 +308,103 @@ describe('Session specific queries', () => {
})
})
})
describe('Endpoint Type Config Queries', () => {
beforeAll(() => {
return ensureZapSessionId(db, 'SESSION', 666).then((id) => {
sid = id
})
})
var endpointTypeIdOnOff
var haOnOffDeviceType, zllOnOffLightDevice
test('Insert EndpointType and test various states', () => {
return QueryZcl.selectAllDeviceTypes(db).then((rows) => {
let haOnOffDeviceTypeArray = rows.filter(
(data) => data.label === 'HA-onoff'
)
let zllOnOffLightDeviceTypeArray = rows.filter(
(data) => data.label === 'ZLL-onofflight'
)
expect(haOnOffDeviceTypeArray.length > 0).toBeTruthy()
expect(zllOnOffLightDeviceTypeArray.length > 0).toBeTruthy()
haOnOffDeviceType = haOnOffDeviceTypeArray[0]
zllOnOffLightDevice = zllOnOffLightDeviceTypeArray[0]
expect(typeof haOnOffDeviceType).toBe('object')
expect(typeof zllOnOffLightDevice).toBe('object')
return Promise.resolve()
})
})
test('Insert Endpoint Type', () => {
return QueryConfig.insertEndpointType(
db,
sid,
'testEndpointType',
haOnOffDeviceType.id
)
.then((rowId) => {
endpointTypeIdOnOff = rowId
return QueryZcl.selectEndpointType(db, rowId)
})
.then((endpointType) => {
expect(endpointType.deviceTypeRef).toBe(haOnOffDeviceType.id)
expect(endpointType.name).toBe('testEndpointType')
})
})
test('Test get all cluster states', () => {
return QueryConfig.getAllEndpointTypeClusterState(db, endpointTypeIdOnOff)
.then((clusters) => {
expect(clusters.length).toBe(6)
return Promise.resolve()
})
.then(() => {
return QueryConfig.insertOrReplaceClusterState(
db,
endpointTypeIdOnOff,
7,
'CLIENT',
true
)
.then((rowId) => {
expect(typeof rowId).toBe('number')
})
.then(() => {
return QueryConfig.getAllEndpointTypeClusterState(
db,
endpointTypeIdOnOff
)
})
.then((clusters) => {
expect(clusters.length).toBe(7)
return Promise.resolve()
})
})
})
test('Test get all attribute states', () => {
return QueryConfig.getEndpointTypeAttributes(db, endpointTypeIdOnOff).then(
(attributes) => {
expect(attributes.length).toBe(10)
}
)
})
test('Get all cluster commands', () => {
return QueryConfig.getEndpointTypeCommands(db, endpointTypeIdOnOff).then(
(commands) => {
expect(commands.length).toBe(6)
}
)
})
test('Delete Endpoint Type', () => {
return QueryConfig.deleteEndpointType(db, endpointTypeIdOnOff)
.then(QueryConfig.deleteEndpointTypeData(db, endpointTypeIdOnOff))
.then(QueryConfig.getAllEndpointTypeClusterState(db, endpointTypeIdOnOff))
.then((clusters) => {
expect(clusters.length).toBe(undefined)
return Promise.resolve()
})
})
})
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册