Skip to content
代码片段 群组 项目
gen-matter-3-1.test.js 21.2 KB
更新 更旧
  • 了解如何忽略特定修订
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
    /**
     *
     *    Copyright (c) 2021 Silicon Labs
     *
     *    Licensed under the Apache License, Version 2.0 (the "License");
     *    you may not use this file except in compliance with the License.
     *    You may obtain a copy of the License at
     *
     *        http://www.apache.org/licenses/LICENSE-2.0
     *
     *    Unless required by applicable law or agreed to in writing, software
     *    distributed under the License is distributed on an "AS IS" BASIS,
     *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     *    See the License for the specific language governing permissions and
     *    limitations under the License.
     *
     *
     * @jest-environment node
     */
    
    const path = require('path')
    const genEngine = require('../src-electron/generator/generation-engine')
    const env = require('../src-electron/util/env')
    const dbApi = require('../src-electron/db/db-api')
    const querySession = require('../src-electron/db/query-session')
    const zclLoader = require('../src-electron/zcl/zcl-loader')
    const importJs = require('../src-electron/importexport/import')
    const testUtil = require('./test-util')
    const queryEndpoint = require('../src-electron/db/query-endpoint')
    const queryEndpointType = require('../src-electron/db/query-endpoint-type')
    const queryConfig = require('../src-electron/db/query-config')
    const queryDeviceType = require('../src-electron/db/query-device-type')
    const util = require('../src-electron/util/util')
    
    let db
    let templateContext
    let zclPackageId
    
    const testFile = testUtil.matterTestFile.allClusters
    const testFile2 = testUtil.matterTestFile.allClustersFileFormat2
    const multipleDeviceTypePerEndpointTestFile =
      testUtil.matterTestFile.multipleDeviceTypesPerEndpoint
    const templateCount = testUtil.testTemplate.matter3Count
    
    beforeAll(async () => {
      env.setDevelopmentEnv()
      let file = env.sqliteTestFile('gen-matter-4')
      db = await dbApi.initDatabaseAndLoadSchema(
        file,
        env.schemaFile(),
        env.zapVersion()
      )
      let ctx = await zclLoader.loadZcl(db, env.builtinMatterZclMetafile())
      zclPackageId = ctx.packageId
    }, testUtil.timeout.medium())
    
    afterAll(() => dbApi.closeDatabase(db), testUtil.timeout.short())
    
    test(
      'Basic gen template parsing and generation',
      async () => {
        templateContext = await genEngine.loadTemplates(
          db,
          testUtil.testTemplate.matter3
        )
    
        expect(templateContext.crc).not.toBeNull()
        expect(templateContext.templateData).not.toBeNull()
        expect(templateContext.templateData.name).toEqual('Matter 3 test templates')
        expect(templateContext.templateData.version).toEqual('matter-3')
        expect(templateContext.templateData.templates.length).toEqual(templateCount)
        expect(templateContext.packageId).not.toBeNull()
      },
      testUtil.timeout.medium()
    )
    
    test(
      `Zap file generation: ${path.relative(__dirname, testFile)}`,
      async () => {
        let sessionId = await querySession.createBlankSession(db)
    
        await importJs.importDataFromFile(db, testFile, {
          sessionId: sessionId,
        })
    
        let genResult = await genEngine.generate(
          db,
          sessionId,
          templateContext.packageId,
          {},
          { disableDeprecationWarnings: true }
        )
        expect(genResult.hasErrors).toEqual(false)
    
        // Note: A lot of these tests here are for sake of backwards
        // compatibility. Latest ZAP must be able to generate content for
        // the old SDKs, so if you changed something that generates
        // endpoint_config differently, please be very very careful and
        // make sure you can answer positively the following question:
        //   after my changes, will zap still be able to generate content
        //   that works with an older SDK.
        //
        let ept = genResult.content['endpoint_config.h']
        expect(ept).toContain(`{ \\
          /* Endpoint: 65534, Cluster: Network Commissioning (server) */ \\
          .clusterId = 0x00000031, \\
          .attributes = ZAP_ATTRIBUTE_INDEX(729), \\
          .attributeCount = 10, \\
          .clusterSize = 0, \\
          .mask = ZAP_CLUSTER_MASK(SERVER), \\
          .functions = NULL, \\
          .acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 244 ), \\
          .generatedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 251 ), \\
        },\\`)
    
        expect(ept).toContain(`#define GENERATED_ENDPOINT_TYPES { \\
      { ZAP_CLUSTER_INDEX(0), 29, 367 }, \\
      { ZAP_CLUSTER_INDEX(29), 46, 3516 }, \\
      { ZAP_CLUSTER_INDEX(75), 5, 105 }, \\
      { ZAP_CLUSTER_INDEX(80), 1, 0 }, \\
    }`)
        expect(ept).toContain(
          `{ 0x00000005, ZAP_TYPE(ENUM8), 1, ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) | ZAP_ATTRIBUTE_MASK(NULLABLE), ZAP_EMPTY_DEFAULT() }, /* LastNetworkingStatus */`
        )
        expect(ept).toContain(
          '{ (uint16_t)0xFF, (uint16_t)0x64, (uint16_t)0xFFFF }, /* BallastFactorAdjustment */'
        )
        expect(ept).toContain(`6, 'C', 'o', 'f', 'f', 'e', 'e', \\`)
        expect(ept).toContain(
          '{ (uint16_t)-0x64, (uint16_t)-0x96, (uint16_t)0xC8 }'
        )
        expect(ept).toContain('#define GENERATED_MIN_MAX_DEFAULT_COUNT 51')
        expect(ept).toContain('#define GENERATED_ATTRIBUTE_COUNT 739')
        expect(ept).toContain(`/* EventList (index=8) */ \\
      0x00000000, /* HardwareFaultChange */ \\
      0x00000001, /* RadioFaultChange */ \\
      0x00000002, /* NetworkFaultChange */ \\
      0x00000003, /* BootReason */ \\
      `)
        expect(ept)
          .toContain(`const EmberAfGenericClusterFunction chipFuncArrayFanControlServer[] = {\\
      (EmberAfGenericClusterFunction) MatterFanControlClusterServerAttributeChangedCallback,\\
      (EmberAfGenericClusterFunction) MatterFanControlClusterServerPreAttributeChangedCallback,\\
    };`)
        expect(ept).toContain(`/*   AcceptedCommandList (index=240) */ \\
      0x00000000 /* Off */, \\
      0x00000001 /* On */, \\
      0x00000002 /* Toggle */, \\
      chip::kInvalidCommandId /* end of list */,`)
        expect(ept).toContain('#define GENERATED_CLUSTER_COUNT 81')
        expect(ept).toContain('#define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 79')
        expect(ept).toContain('#define ATTRIBUTE_SINGLETONS_SIZE (37)')
        expect(ept).toContain('#define ATTRIBUTE_MAX_SIZE (3988)')
        expect(ept).toContain('#define FIXED_ENDPOINT_COUNT (4)')
        expect(ept).toContain(
          '#define FIXED_ENDPOINT_ARRAY { 0x0000, 0x0001, 0x0002, 0xFFFE }'
        )
        expect(ept).toContain(
          '#define FIXED_PROFILE_IDS { 0x0103, 0x0103, 0x0103, 0x0103 }'
        )
        expect(ept).toContain(
          '#define FIXED_PARENT_IDS { kInvalidEndpointId, 0, 1, kInvalidEndpointId }'
        )
        expect(ept).toContain(
          '#define FIXED_DEVICE_TYPES {{0x00000016,1},{0x00000100,1},{0x00000100,1},{0x0000F002,1}}'
        )
        expect(ept).toContain(
          '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x00000016,1,0},{0x00000100,1,1},{0x00000100,1,2},{0x0000F002,1,65534}}'
        )
        expect(ept).toContain('#define FIXED_DEVICE_TYPE_OFFSETS { 0,1,2,3}')
        expect(ept).toContain('#define FIXED_DEVICE_TYPE_LENGTHS { 1,1,1,1}')
        expect(ept).toContain('#define FIXED_ENDPOINT_TYPES { 0, 1, 2, 3 }')
        expect(ept).toContain('#define FIXED_NETWORKS { 0, 0, 0, 0 }')
    
        // Some odd ordering
        expect(ept).toContain(`{ \\
          /* Endpoint: 0, Cluster: Basic Information (server) */ \\
          .mask = ZAP_CLUSTER_MASK(SERVER), \\
          .attributeCount = 22, \\
          .clusterId = 0x00000028, \\
        },\\`)
      },
      testUtil.timeout.long()
    )
    
    test(
      `Zap file generation: ${path.relative(__dirname, testFile2)}`,
      async () => {
        let sessionId = await querySession.createBlankSession(db)
    
        await importJs.importDataFromFile(db, testFile2, {
          sessionId: sessionId,
        })
    
        let genResult = await genEngine.generate(
          db,
          sessionId,
          templateContext.packageId,
          {},
          { disableDeprecationWarnings: true }
        )
        expect(genResult.hasErrors).toEqual(false)
    
        // Note: A lot of these tests here are for sake of backwards
        // compatibility. Latest ZAP must be able to generate content for
        // the old SDKs, so if you changed something that generates
        // endpoint_config differently, please be very very careful and
        // make sure you can answer positively the following question:
        //   after my changes, will zap still be able to generate content
        //   that works with an older SDK.
        //
        let ept = genResult.content['endpoint_config.h']
        expect(ept).toContain(`{ \\
          /* Endpoint: 65534, Cluster: Network Commissioning (server) */ \\
          .clusterId = 0x00000031, \\
          .attributes = ZAP_ATTRIBUTE_INDEX(729), \\
          .attributeCount = 10, \\
          .clusterSize = 0, \\
          .mask = ZAP_CLUSTER_MASK(SERVER), \\
          .functions = NULL, \\
          .acceptedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 244 ), \\
          .generatedCommandList = ZAP_GENERATED_COMMANDS_INDEX( 251 ), \\
        },\\`)
    
        expect(ept).toContain(`#define GENERATED_ENDPOINT_TYPES { \\
      { ZAP_CLUSTER_INDEX(0), 29, 367 }, \\
      { ZAP_CLUSTER_INDEX(29), 46, 3516 }, \\
      { ZAP_CLUSTER_INDEX(75), 5, 105 }, \\
      { ZAP_CLUSTER_INDEX(80), 1, 0 }, \\
    }`)
        expect(ept).toContain(
          `{ 0x00000005, ZAP_TYPE(ENUM8), 1, ZAP_ATTRIBUTE_MASK(EXTERNAL_STORAGE) | ZAP_ATTRIBUTE_MASK(NULLABLE), ZAP_EMPTY_DEFAULT() }, /* LastNetworkingStatus */`
        )
        expect(ept).toContain(
          '  { 0x00000000, ZAP_TYPE(TEMPERATURE), 2, ZAP_ATTRIBUTE_MASK(NULLABLE), ZAP_SIMPLE_DEFAULT(0x8000) },'
        )
        expect(ept).toContain(
          '{ (uint16_t)0xFF, (uint16_t)0x64, (uint16_t)0xFFFF }, /* BallastFactorAdjustment */'
        )
        expect(ept).toContain(`6, 'C', 'o', 'f', 'f', 'e', 'e', \\`)
        expect(ept).toContain(
          '{ (uint16_t)-0x64, (uint16_t)-0x96, (uint16_t)0xC8 }'
        )
        expect(ept).toContain('#define GENERATED_MIN_MAX_DEFAULT_COUNT 51')
        expect(ept).toContain('#define GENERATED_ATTRIBUTE_COUNT 739')
        expect(ept).toContain(`/* EventList (index=8) */ \\
      0x00000000, /* HardwareFaultChange */ \\
      0x00000001, /* RadioFaultChange */ \\
      0x00000002, /* NetworkFaultChange */ \\
      0x00000003, /* BootReason */ \\
      `)
        expect(ept)
          .toContain(`const EmberAfGenericClusterFunction chipFuncArrayFanControlServer[] = {\\
      (EmberAfGenericClusterFunction) MatterFanControlClusterServerAttributeChangedCallback,\\
      (EmberAfGenericClusterFunction) MatterFanControlClusterServerPreAttributeChangedCallback,\\
    };`)
        expect(ept).toContain(`/*   AcceptedCommandList (index=240) */ \\
      0x00000000 /* Off */, \\
      0x00000001 /* On */, \\
      0x00000002 /* Toggle */, \\
      chip::kInvalidCommandId /* end of list */,`)
        expect(ept).toContain('#define GENERATED_CLUSTER_COUNT 81')
        expect(ept).toContain('#define ZAP_FIXED_ENDPOINT_DATA_VERSION_COUNT 79')
        expect(ept).toContain('#define ATTRIBUTE_SINGLETONS_SIZE (37)')
        expect(ept).toContain('#define ATTRIBUTE_MAX_SIZE (3988)')
        expect(ept).toContain('#define FIXED_ENDPOINT_COUNT (4)')
        expect(ept).toContain(
          '#define FIXED_ENDPOINT_ARRAY { 0x0000, 0x0001, 0x0002, 0xFFFE }'
        )
        expect(ept).toContain(
          '#define FIXED_PROFILE_IDS { 0x0103, 0x0103, 0x0103, 0x0103 }'
        )
        expect(ept).toContain(
          '#define FIXED_PARENT_IDS { kInvalidEndpointId, kInvalidEndpointId, kInvalidEndpointId, kInvalidEndpointId }'
        )
        expect(ept).toContain(
          '#define FIXED_DEVICE_TYPES {{0x00000016,1},{0x00000100,1},{0x00000100,1},{0x0000F002,1}}'
        )
        expect(ept).toContain(
          '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x00000016,1,0},{0x00000100,1,1},{0x00000100,1,2},{0x0000F002,1,65534}}'
        )
        expect(ept).toContain('#define FIXED_DEVICE_TYPE_OFFSETS { 0,1,2,3}')
        expect(ept).toContain('#define FIXED_DEVICE_TYPE_LENGTHS { 1,1,1,1}')
        expect(ept).toContain('#define FIXED_ENDPOINT_TYPES { 0, 1, 2, 3 }')
        expect(ept).toContain('#define FIXED_NETWORKS { 0, 0, 0, 0 }')
    
        // Some odd ordering
        expect(ept).toContain(`{ \\
          /* Endpoint: 0, Cluster: Basic Information (server) */ \\
          .mask = ZAP_CLUSTER_MASK(SERVER), \\
          .attributeCount = 22, \\
          .clusterId = 0x00000028, \\
        },\\`)
      },
      testUtil.timeout.long()
    )
    
    test(
      `Zap multiple device type per endpoint file generation: ${path.relative(
        __dirname,
        multipleDeviceTypePerEndpointTestFile
      )}`,
      async () => {
        let sessionId = await querySession.createBlankSession(db)
    
        await importJs.importDataFromFile(
          db,
          multipleDeviceTypePerEndpointTestFile,
          {
            sessionId: sessionId,
          }
        )
    
        let genResult = await genEngine.generate(
          db,
          sessionId,
          templateContext.packageId,
          {},
          { disableDeprecationWarnings: true }
        )
        expect(genResult.hasErrors).toEqual(false)
    
        let ept = genResult.content['endpoint_config.h']
    
        expect(ept).toContain(
          '#define FIXED_DEVICE_TYPES {{0x00000016,1},{0x00000101,2},{0x00000100,1},{0x00000101,1},{0x00000100,1},{0x0000F002,1}}'
        )
        expect(ept).toContain(
          '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x00000016,1,0},{0x00000101,2,1},{0x00000100,1,1},{0x00000101,1,2},{0x00000100,1,2},{0x0000F002,1,65534}}'
        )
        expect(ept).toContain('#define FIXED_DEVICE_TYPE_OFFSETS { 0,1,3,5}')
        expect(ept).toContain('#define FIXED_DEVICE_TYPE_LENGTHS { 1,2,2,1}')
        expect(ept).toContain('#define FIXED_ENDPOINT_TYPES { 0, 1, 2, 3 }')
    
        // Test user_device_types helper within user_endpoints
        expect(ept).toContain('Endpoint 0, DeviceId: 22, DeviceVersion: 1')
        expect(ept).toContain('Endpoint 1, DeviceId: 256, DeviceVersion: 1')
        expect(ept).toContain('Endpoint 1, DeviceId: 257, DeviceVersion: 2')
        expect(ept).toContain('Endpoint 2, DeviceId: 256, DeviceVersion: 1')
        expect(ept).toContain('Endpoint 2, DeviceId: 257, DeviceVersion: 1')
        expect(ept).toContain('Endpoint 65534, DeviceId: 61442, DeviceVersion: 1')
      },
      testUtil.timeout.long()
    )
    
    test(
      `Zap testing miscellaneouos type specific helpers: ${path.relative(
        __dirname,
        testFile
      )}`,
      async () => {
        let sessionId = await querySession.createBlankSession(db)
    
        await importJs.importDataFromFile(db, testFile, {
          sessionId: sessionId,
        })
    
        let genResult = await genEngine.generate(
          db,
          sessionId,
          templateContext.packageId,
          {},
          { disableDeprecationWarnings: true }
        )
        expect(genResult.hasErrors).toEqual(false)
    
        // Note: A lot of these tests here are for sake of backwards
        // compatibility. Latest ZAP must be able to generate content for
        // the old SDKs, so if you changed something that generates
        // endpoint_config differently, please be very very careful and
        // make sure you can answer positively the following question:
        //   will after my changes, zap still be able to generate content
        //   that will work with an older SDK.
        //
        let ept = genResult.content['miscellaneous_helper_tests.out']
    
        // Testing if_unsupported_attribute_callback helper
        expect(ept).toContain(
          'attribute callback for OnOff of boolean type is supported in java'
        )
        expect(ept).toContain(
          'attribute callback for GlobalSceneControl of boolean type is supported in java'
        )
        expect(ept).toContain(
          'attribute callback for GeneratedCommandList of command_id type is supported in java'
        )
    
        // Testing if_basic_attribute helper
        expect(ept).toContain(
          'attribute OnTime of int16u type is basic type in java'
        )
        expect(ept).toContain(
          'attribute EventList of event_id type is not basic type in java'
        )
        expect(ept).toContain(
          'attribute StartUpOnOff of OnOffStartUpOnOff type is not basic type in java'
        )
    
        // Testing as_underlying_java_zcl_type helper
        expect(ept).toContain(
          'Underlying Java type for attribute OnOff of boolean type: Boolean'
        )
        expect(ept).toContain(
          'Underlying Java type for attribute OnTime of int16u type: Integer'
        )
        expect(ept).toContain(
          'Underlying Java type for attribute GeneratedCommandList of command_id type: Long'
        )
    
        // Testing as_underlying_python_zcl_type helper
        expect(ept).toContain(
          'Underlying Python type for attribute OnOff of boolean type: bool'
        )
        expect(ept).toContain(
          'Underlying Python type for attribute OnTime of int16u type: int'
        )
        expect(ept).toContain(
          'Underlying Python type for attribute GeneratedCommandList of command_id type: int'
        )
    
        // Testing if_is_data_type_signed and as_zcl_data_type_size
        expect(ept).toContain(
          'attribute OnOff of type boolean is unsigned. The size of this attribute is: 8 bits'
        )
        expect(ept).toContain(
          'attribute OnTime of type int16u is unsigned. The size of this attribute is: 16 bits'
        )
        expect(ept).toContain(
          'attribute StartUpOnOff of type OnOffStartUpOnOff is unsigned. The size of this attribute is: 8 bits'
        )
        expect(ept).toContain(
          'attribute GeneratedCommandList of type command_id is unsigned. The size of this attribute is: 32 bits'
        )
    
        // Testing cluster specific structs
        expect(ept).toContain(
          'TargetStruct item 0 from Access Control cluster: Cluster'
        )
        expect(ept).toContain(
          'TargetStruct item 1 from Access Control cluster: Endpoint'
        )
        expect(ept).toContain(
          'TargetStruct item 2 from Access Control cluster: DeviceType'
        )
        expect(ept).toContain('TargetStruct item 0 from Binding cluster: Node')
        expect(ept).toContain('TargetStruct item 1 from Binding cluster: Group')
        expect(ept).toContain('TargetStruct item 2 from Binding cluster: Endpoint')
        expect(ept).toContain('TargetStruct item 3 from Binding cluster: Cluster')
        expect(ept).toContain(
          'TargetStruct item 4 from Binding cluster: FabricIndex'
        )
      },
      testUtil.timeout.long()
    )
    
    test(
      `Zap file generation for multiple zcl device types per endpoint: ${path.relative(
        __dirname,
        testFile
      )}`,
      async () => {
        // Creating a session with matter specific session packages
        let userSession = await querySession.ensureZapUserAndSession(
          db,
          'USER',
          'SESSION'
        )
        let sid = userSession.sessionId
        await util.ensurePackagesAndPopulateSessionOptions(
          db,
          sid,
          {
            zcl: env.builtinMatterZclMetafile(),
            template: testUtil.testTemplate.matter3,
            partitions: 2,
          },
          null,
          [templateContext.packageId]
        )
    
        // Extract device types for insertion into an endpoint
        let allDeviceTypes = await queryDeviceType.selectAllDeviceTypes(
          db,
          zclPackageId
        )
        let matterLightDevices = allDeviceTypes.filter(
          (data) =>
            data.label === 'MA-onofflight' || data.label === 'MA-dimmablelight'
        )
        let matterLightDeviceRefs = matterLightDevices.map((dt) => dt.id)
        let matterLightDeviceIds = matterLightDevices.map((dt) => dt.code)
    
        // insert the device types above into an endpoint type
        let sessionPartitionInfo =
          await querySession.selectSessionPartitionInfoFromDeviceType(
            db,
            sid,
            matterLightDeviceRefs[0]
          )
        await queryConfig.insertEndpointType(
          db,
          sessionPartitionInfo[0],
          'testEndpointType',
          matterLightDeviceRefs,
          matterLightDeviceIds,
          [1, 2], //device type version
          true
        )
    
        // Getting the endpoint cluster information and making sure clusters from both
        // device types are added.
        let epts = await queryEndpointType.selectAllEndpointTypes(db, sid)
        expect(epts[0].deviceTypeRef.length).toEqual(2)
        let clusters = await queryEndpoint.selectEndpointClusters(db, epts[0].id)
        let clusterNames = clusters.map((cl) => cl.name)
        expect(clusterNames.length).toEqual(6)
        expect(clusterNames.includes('Identify')).toEqual(true)
        expect(clusterNames.includes('Groups')).toEqual(true)
        expect(clusterNames.includes('Scenes')).toEqual(true)
        expect(clusterNames.includes('On/Off')).toEqual(true)
        expect(clusterNames.includes('Descriptor')).toEqual(true)
    
        // Cluster coming from just MA-dimmablelight and not MA-onofflight
        expect(clusterNames.includes('Level Control')).toEqual(true)
    
        // Test to make sure the featureMap attribute value for level control cluster
        // is set correctly when a device type is added as per its device type cluster
        // feature compliance
        let levelControlCluster = clusters.find((cl) => cl.name == 'Level Control')
        let levelControlClusterFeatureMapAttribute =
          await queryEndpointType.selectEndpointTypeAttributeFromEndpointTypeClusterId(
            db,
            levelControlCluster.endpointTypeClusterId,
            '0xFFFC',
            null
          )
        expect(levelControlClusterFeatureMapAttribute.defaultValue).toEqual('3')
    
        // Edit the endpoint type and add another device type and test the update
        let additionalMatterLightDevice = allDeviceTypes.filter(
          (data) => data.label === 'MA-colortemperaturelight'
        )
    
        let matterLightDevicesExtended = matterLightDeviceRefs.concat(
          additionalMatterLightDevice.map((dt) => dt.id)
        )
        let matterLightDeviceIdsExtended = matterLightDeviceIds.concat(
          additionalMatterLightDevice.map((dt) => dt.code)
        )
        let changesArray = [
          { key: 'deviceTypeRef', value: matterLightDevicesExtended },
          { key: 'deviceVersion', value: [1, 1, 1] },
          { key: 'deviceId', value: matterLightDeviceIdsExtended },
        ]
        await queryConfig.updateEndpointType(db, sid, epts[0].id, changesArray)
    
        epts = await queryEndpointType.selectAllEndpointTypes(db, sid)
        expect(epts[0].deviceTypeRef.length).toEqual(3)
        clusters = await queryEndpoint.selectEndpointClusters(db, epts[0].id)
        clusterNames = clusters.map((cl) => cl.name)
        expect(clusterNames.length).toEqual(7)
        // Cluster coming from just MA-colortemperaturelight
        expect(clusterNames.includes('Color Control')).toEqual(true)
      },
      testUtil.timeout.long()
    )