File size: 2,545 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/* eslint-disable @typescript-eslint/no-empty-function */
import { expect } from 'chai'
import { mergeResourceOptions } from './build-feature.js'
import { Before, After, ActionResponse, ActionHandler } from '../../actions/action.interface.js'

describe('mergeResourceOptions', function () {
  it('chaines before hooks', function () {
    const existingOptions = {
      actions: {
        new: {
          before: function firstBeforeHook() {} as unknown as Before,
          handler: null,
        },
        edit: {
          after: [function firstAfterHook() {} as unknown as After<ActionResponse>],
        },
      },
    }
    const newOptions = {
      actions: {
        new: {
          before: function lastBeforeHook() {} as unknown as Before,
          handler: function lastHandler() {} as unknown as ActionHandler<ActionResponse>,
        },
        edit: {
          after: function lastAfterHook() {} as unknown as After<ActionResponse>,
        },
        newAction: {
          handler: function newHandler() {} as unknown as ActionHandler<ActionResponse>,
        },
      },
    }

    expect(mergeResourceOptions(existingOptions, newOptions)).to.deep.eq({
      actions: {
        new: {
          before: [
            existingOptions.actions.new.before,
            newOptions.actions.new.before,
          ],
          handler: [
            newOptions.actions.new.handler,
          ],
        },
        edit: {
          after: [
            existingOptions.actions.edit.after[0],
            newOptions.actions.edit.after,
          ],
        },
        newAction: {
          handler: [
            newOptions.actions.newAction.handler,
          ],
        },
      },
    })
  })

  it('chaines properties', function () {
    const existingOptions = {
      properties: {
        password: {
          isVisible: true,
          component: 'ala',
        },
      },
    }
    const newOptions = {
      properties: {
        password2: {
          isVisible: false,
          component: 'ela',
        },
      },
    }

    expect(mergeResourceOptions(existingOptions, newOptions)).to.deep.eq({
      properties: {
        ...existingOptions.properties,
        ...newOptions.properties,
      },
    })
  })

  it('merges falsey options', function () {
    const existingOptions = {
      navigation: {
        name: 'db',
      },
    }
    const newOptions = {
      navigation: false,
    }

    expect(mergeResourceOptions(existingOptions, newOptions)).to.deep.eq({
      navigation: false,
    })
  })
})