Repository: shardeum/shardeum
File: test/unit/src/utils/keyUtils.test.ts (TypeScript)

Code before:
    it('should transform a list of keys into an object with security levels', () => {
      // Arrange
      const keyList = ['key1', 'key2', 'key3']
      const securityLevel = 2

      // Act
      const result = keyListAsLeveledKeys(keyList, securityLevel)

      // Assert
      expect(result).toEqual({
        key1: 2,
        key2: 2,
        key3: 2,
      })
    })

    /**
     * Tests that different security levels can be assigned
     */
    it('should assign the specified security level to each key', () => {
      // Arrange
      const keyList = ['keyA', 'keyB']
      const securityLevel = 5

      // Act
      const result = keyListAsLeveledKeys(keyList, securityLevel)

      // Assert
      expect(result).toEqual({
        keyA: 5,
        keyB: 5,
      })
    })

    /**
     * Tests handling of an empty key list
     */
    it('should return an empty object when given an empty array', () => {
      // Arrange
      const keyList: string[] = []
      const securityLevel = 3

      // Act
      const result = keyListAsLeveledKeys(keyList, securityLevel)

      // Assert
      expect(result).toEqual({})
      expect(Object.keys(result).length).toBe(0)
    })

    /**

Review comment (security):
This shouldn't be possible right? we have 0, 1, 2, 3 as values in `DevSecurityLevel` enum? 
This is debatable, but if we are not supporting a certain level in our enum, then we shouldn't be able to assign it.
It's possible that it's prevented somewhere early in the flow and this util never receives 5 as security level. 
My suggestion would be comment this out with a note that, this needs to be handled in main business logic if not done already. 
cc @BelfordZ @afostr 

Code after:
    it('should transform a list of keys into an object with security levels', () => {
      // Arrange
      const keyList = ['key1', 'key2', 'key3']
      const securityLevel = 2

      // Act
      const result = keyListAsLeveledKeys(keyList, securityLevel)

      // Assert
      expect(result).toEqual({
        key1: 2,
        key2: 2,
        key3: 2,
      })
    })

    // TODO : fix the issue with the test
    /*
      This shouldn't be possible right? we have 0, 1, 2, 3 as values in DevSecurityLevel enum?
      This is debatable, but if we are not supporting a certain level in our enum, then we shouldn't be able to assign it.
      It's possible that it's prevented somewhere early in the flow and this util never receives 5 as security level.
      My suggestion would be comment this out with a note that, this needs to be handled in main business logic if not done already.    
    */
    // /**
    //  * Tests that different security levels can be assigned
    //  */
    // it('should assign the specified security level to each key', () => {
    //   // Arrange
    //   const keyList = ['keyA', 'keyB']
    //   const securityLevel = 5

    //   // Act
    //   const result = keyListAsLeveledKeys(keyList, securityLevel)

    //   // Assert
    //   expect(result).toEqual({
    //     keyA: 5,
    //     keyB: 5,
    //   })
    // })

    /**
     * Tests handling of an empty key list
     */
    it('should return an empty object when given an empty array', () => {
      // Arrange
      const keyList: string[] = []
      const securityLevel = 3

      // Act
      const result = keyListAsLeveledKeys(keyList, securityLevel)