File size: 2,571 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
import sinon from 'sinon'

import BaseProperty from '../../../src/backend/adapters/property/base-property.js'
import BaseResource from '../../../src/backend/adapters/resource/base-resource.js'
import ResourceDecorator from '../../../src/backend/decorators/resource/resource-decorator.js'

/**
 * returns properties with following absolute paths:
 * - normal: number
 * - nested: mixed
 * - nested.normal: string
 * - nested.nested: mixed
 * - nested.nested.normalInner: string
 * - arrayed: string (array)
 * - arrayedMixed: mixed (array)
 * - arrayedMixed.arrayParam: string
 *
 * @private
 */
const buildProperties = (): Array<BaseProperty> => {
  const normalProperty = new BaseProperty({ path: 'normal', type: 'number' }) as any
  const nestedProperty = new BaseProperty({ path: 'nested', type: 'mixed' }) as any
  const nested2Property = new BaseProperty({ path: 'nested', type: 'mixed' }) as any
  const arrayProperty = new BaseProperty({ path: 'arrayed', type: 'string' }) as any
  const arrayMixedProperty = new BaseProperty({ path: 'arrayedMixed', type: 'mixed' }) as any
  arrayProperty.isArray = (): boolean => true
  arrayMixedProperty.isArray = (): boolean => true

  nestedProperty.subProperties = (): Array<BaseProperty> => [
    new BaseProperty({ path: 'normal', type: 'string' }),
    nested2Property,
  ]
  nested2Property.subProperties = (): Array<BaseProperty> => [
    new BaseProperty({ path: 'normalInner', type: 'string' }),
  ]
  arrayMixedProperty.subProperties = (): Array<BaseProperty> => [
    new BaseProperty({ path: 'arrayParam', type: 'string' }),
  ]

  return [normalProperty, nestedProperty, arrayProperty, arrayMixedProperty]
}

export const expectedResult = {
  id: 'someID',
  properties: buildProperties(),
  resourceName: 'resourceName',
  databaseName: 'databaseName',
  databaseType: 'mongodb',
  parent: {
    name: 'databaseName',
    icon: 'icon-mongodb',
  },
}

export default (): BaseResource => ({
  _decorated: {} as ResourceDecorator,
  id: sinon.stub().returns(expectedResult.id),
  properties: sinon.stub().returns(expectedResult.properties),
  property: sinon.stub().returns(new BaseProperty({ path: 'prop', type: 'string' })),
  databaseName: sinon.stub().returns(expectedResult.databaseName),
  databaseType: sinon.stub().returns(expectedResult.databaseType),
  count: sinon.stub(),
  find: sinon.stub(),
  findOne: sinon.stub(),
  findMany: sinon.stub(),
  build: sinon.stub(),
  create: sinon.stub(),
  update: sinon.stub(),
  delete: sinon.stub(),
  assignDecorator: sinon.stub(),
  decorate: sinon.stub(),
})