PHP 8.2.30
Preview: get.spec.ts Size: 2.84 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/utils/flat/get.spec.ts

import { expect } from 'chai'

import { FlattenParams } from './flat.types.js'
import { get } from './get.js'

describe('module:flat.get', () => {
  let params: FlattenParams

  beforeEach(() => {
    params = {
      name: 'Wojtek',
      surname: 'Krysiak',
      age: 36,
      'interest.OfMe.0': 'javascript',
      'interest.OfMe.1': 'typescript',
      'interest.OfMe.2': 'brainTumor',
      interests: 'Generally everything',
      'meta.position': 'CTO',
      'meta.workingHours': '9:00-17:00',
      'meta.duties': 'everything',
      'meta.fun': '8/10',
      nulled: null,
      emptyArray: [],
      emptyObject: {},
      'nested.0.el.0.value': 'val0.0',
      'nested.0.el.1.value': 'val0.1',
      'nested.1.el.0.value': 'val1',
      'nested.1.el.1.value': 'val2',
    }
  })

  it('returns regular string', () => {
    expect(get(params, 'name')).to.eq(params.name)
  })

  it('returns undefined for non existing property', () => {
    expect(get(params, 'nameNotExisting')).to.be.undefined
  })

  it('returns undefined for property set to undefined', () => {
    expect(get({
      property: undefined as any,
    }, 'property')).to.be.undefined
  })

  it('returns nested array', () => {
    expect(get(params, 'interest.OfMe')).to.deep.equal([
      'javascript',
      'typescript',
      'brainTumor',
    ])
  })

  it('returns object with nested array', () => {
    expect(get(params, 'interest')).to.deep.equal({
      OfMe: [
        'javascript',
        'typescript',
        'brainTumor',
      ],
    })
  })

  it('returns undefined when not exact property is given', () => {
    expect(get(params, 'interest.Of')).to.be.undefined
  })

  it('returns null for null values', () => {
    expect(get(params, 'nulled')).to.eq(null)
  })

  it('returns nested arrays', () => {
    expect(get(params, 'nested.0.el')).to.deep.equal([
      { value: 'val0.0' },
      { value: 'val0.1' },
    ])
  })

  it('returns nested arrays with siblings when `includeAllSiblings` is set', () => {
    expect(get(params, 'nested.el', { includeAllSiblings: true })).to.deep.equal([
      { value: 'val0.0' },
      { value: 'val0.1' },
      { value: 'val1' },
      { value: 'val2' },
    ])
  })

  context('gets nested reference id', () => {
    const referenceId = '5f7462621eb3495ea0f0edd9'

    beforeEach(() => {
      params = {
        'Skills._id': '5f925f58016eab056c8c35a7',
        'Skills.softShills': [],
        'Skills.hardSkills.0._id': '5f925f58016eab056c8c35a8',
        'Skills.hardSkills.0.name': '123',
        'Skills.hardSkills.0.level': 'junior',
        'Skills.hardSkills.0.Profession': referenceId,
      }
    })

    it('returns referenceId when propertyPath is given', () => {
      const propertyPath = 'Skills.hardSkills.Profession'
      expect(get(params, propertyPath, { includeAllSiblings: true })).to.deep.equal(
        [referenceId],
      )
    })
  })
})

Directory Contents

Dirs: 0 × Files: 26

Name Size Perms Modified Actions
44 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
448 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.42 KB lrw-r--r-- 2026-02-28 00:32:10
Edit Download
906 B lrw-r--r-- 2026-02-28 00:32:10
Edit Download
1.24 KB lrw-r--r-- 2026-02-28 00:32:14
Edit Download
2.74 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
965 B lrw-r--r-- 2026-02-28 00:32:14
Edit Download
587 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.84 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
2.51 KB lrw-r--r-- 2026-02-28 00:32:20
Edit Download
65 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
2.01 KB lrw-r--r-- 2026-02-28 00:32:34
Edit Download
686 B lrw-r--r-- 2026-02-28 00:32:36
Edit Download
38 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
730 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
976 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
890 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
1.21 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.47 KB lrw-r--r-- 2026-02-28 00:32:40
Edit Download
1.41 KB lrw-r--r-- 2026-02-28 00:32:40
Edit Download
504 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.49 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download
1.11 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download
639 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
4.70 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download
2.03 KB lrw-r--r-- 2026-02-28 00:32:44
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).