PHP 8.2.30
Preview: merge.spec.js Size: 2.11 KB
//proc/thread-self/root/home/byroehnu/.trash/node_modules11/adminjs/lib/utils/flat/merge.spec.js

import { expect } from 'chai';
import { merge } from './merge.js';
describe('merge', () => {
  it('removes nulled arrays when nested items were found', () => {
    const object1 = {
      status: 'draft',
      postImage: null,
      blogImageSizes: null
    };
    const object2 = {
      'blogImageSizes.0': 4130,
      'blogImageMimeTypes.0': 'image/jpeg'
    };
    expect(merge(object1, object2)).to.deep.equal({
      status: 'draft',
      postImage: null,
      'blogImageSizes.0': 4130,
      'blogImageMimeTypes.0': 'image/jpeg'
    });
  });
  context('object with nested fields are given in the first argument', () => {
    const object1 = {
      status: {
        type: 'draft',
        updated: 'yesterday',
        tags: ['super']
      }
    };
    it('flattens everything and changes just nested property when it was given nested', () => {
      const object2 = {
        'status.type': 'newDraft'
      };
      expect(merge(object1, object2)).to.deep.equal({
        'status.type': object2['status.type'],
        'status.updated': 'yesterday',
        'status.tags.0': 'super'
      });
    });
    it('changes entire record when 2 objects are given', () => {
      const object2 = {
        status: {
          type: 'newType',
          updated: 'today'
        }
      };
      expect(merge(object1, object2)).to.deep.equal({
        'status.type': object2.status.type,
        'status.updated': 'today'
      });
    });
  });
  describe('multiple parameters', () => {
    const object1 = {
      status: {
        type: 'draft'
      }
    };
    it('returns flatten object when one other argument is given', () => {
      expect(merge(object1)).to.deep.equal({
        'status.type': 'draft'
      });
    });
    it('merges more then 2 arguments', () => {
      const object2 = {
        'status.type': 'status2',
        'status.age': '1 day'
      };
      const object3 = {
        'status.type': 'status3',
        names: ['Wojtek']
      };
      expect(merge(object1, object2, object3)).to.deep.equal({
        'status.type': 'status2',
        'status.age': '1 day',
        'names.0': 'Wojtek'
      });
    });
  });
});

Directory Contents

Dirs: 0 × Files: 26

Name Size Perms Modified Actions
44 B lrw-r--r-- 2026-02-28 00:31:26
Edit Download
448 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
722 B lrw-r--r-- 2026-02-28 00:31:30
Edit Download
1.40 KB lrw-r--r-- 2026-02-28 00:31:30
Edit Download
906 B lrw-r--r-- 2026-02-28 00:31:32
Edit Download
2.74 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
10 B lrw-r--r-- 2026-02-28 00:31:34
Edit Download
587 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
2.35 KB lrw-r--r-- 2026-02-28 00:31:34
Edit Download
2.75 KB lrw-r--r-- 2026-02-28 00:31:34
Edit Download
66 B lrw-r--r-- 2026-02-28 00:31:44
Edit Download
567 B lrw-r--r-- 2026-02-28 00:31:46
Edit Download
2.11 KB lrw-r--r-- 2026-02-28 00:31:46
Edit Download
10 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
730 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
701 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
814 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.21 KB lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.34 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
2.47 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
504 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
904 B lrw-r--r-- 2026-02-28 00:31:48
Edit Download
1.48 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
639 B lrw-r--r-- 2026-02-28 00:31:56
Edit Download
1.85 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download
4.64 KB lrw-r--r-- 2026-02-28 00:31:48
Edit Download

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