PHP 8.2.30
Preview: convert-nested-param.spec.ts Size: 1.91 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/src/utils/param-converter/convert-nested-param.spec.ts

import { expect } from 'chai'

import { convertNestedParam } from './convert-nested-param.js'

const jsonField = {
  number: '123',
  date: '2020-11-08',
  nested: {
    number: '456',
  },
  nestedList: [{
    number: '789',
  }, {
    number: '111',
  }],
}

describe('module:paramConverter.convertNestedParam', () => {
  it('should convert number property of a JSON to actual number', () => {
    const property = {
      type: 'number',
      propertyPath: 'jsonField.number',
      subProperties: [],
    }

    const convertedJson = convertNestedParam(jsonField, property as any)

    expect(convertedJson.number).to.equal(123)
  })

  it('should convert date property of a JSON to actual number', () => {
    const property = {
      type: 'datetime',
      propertyPath: 'jsonField.date',
      subProperties: [],
    }

    const convertedJson = convertNestedParam(jsonField, property as any)

    expect(convertedJson.date.getTime()).to.equal(new Date('2020-11-08').getTime())
  })

  it('should convert a nested json property\'s number string to actual number', () => {
    const property = {
      type: 'mixed',
      propertyPath: 'jsonField.nested',
      isArray: false,
      subProperties: [{
        propertyPath: 'jsonField.nested.number',
        type: 'number',
      }],
    }

    const convertedJson = convertNestedParam(jsonField, property as any)

    expect(convertedJson.nested.number).to.equal(456)
  })

  it('should convert a nested json array property\'s number string to actual number', () => {
    const property = {
      type: 'mixed',
      propertyPath: 'jsonField.nestedList',
      isArray: true,
      subProperties: [{
        propertyPath: 'jsonField.nestedList.number',
        type: 'number',
      }],
    }

    const convertedJson = convertNestedParam(jsonField, property as any)

    expect(convertedJson.nestedList[0].number).to.equal(789)
    expect(convertedJson.nestedList[1].number).to.equal(111)
  })
})

Directory Contents

Dirs: 0 × Files: 9

Name Size Perms Modified Actions
44 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
1.91 KB lrw-r--r-- 2026-02-28 00:32:02
Edit Download
990 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
819 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
403 B lrw-r--r-- 2026-02-28 00:32:02
Edit Download
44 B lrw-r--r-- 2026-02-28 00:32:28
Edit Download
537 B lrw-r--r-- 2026-02-28 00:32:40
Edit Download
1.47 KB lrw-r--r-- 2026-02-28 00:32:40
Edit Download
1.18 KB lrw-r--r-- 2026-02-28 00:32:46
Edit Download

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