File size: 1,690 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
import { factory } from 'factory-girl'

import './property-json.factory.js'
import { PropertyJSON, ResourceJSON } from '../../interfaces/index.js'

const propertyJson = await factory.build('PropertyJSON') as PropertyJSON

factory.define<ResourceJSON>('ResourceJSON', Object, {
  id: factory.sequence('ResourceJSON.id', (i) => `resource${i}`),
  name: factory.sequence('ResourceJSON.name', (i) => `resource ${i}`),
  href: '/admin/resourceName',
  titleProperty: () => propertyJson,
  navigation: {
    name: 'someName',
    icon: 'someIcon',
    show: true,
  },
  actions: [],
  resourceActions: [],
  listProperties: [],
  properties: {},
  showProperties: [],
  filterProperties: [],
  editProperties: [],
})

factory.extend('ResourceJSON', 'ResourceJSON.full', {}, {
  afterBuild: async (model) => {
    const properties = [
      await factory.build<PropertyJSON>('PropertyJSON', { name: 'name', isTitle: true }),
      await factory.build<PropertyJSON>('PropertyJSON', { name: 'surname' }),
      await factory.build<PropertyJSON>('PropertyJSON', { name: 'content', type: 'string' }),
      await factory.build<PropertyJSON>('PropertyJSON', { name: 'longerData', type: 'textarea' }),
      // await factory.build<PropertyJSON>('PropertyJSON', { name: 'publishedAt', type: 'date' }),
      await factory.build<PropertyJSON>('PropertyJSON', { name: 'gender',
        availableValues: [{
          label: 'male', value: 'MALE',
        }, {
          label: 'female', value: 'FEMALE',
        }] }),
    ]
    return {
      ...model,
      listProperties: properties,
      showProperties: properties,
      editProperties: properties,
      filterProperties: properties,
    }
  },
})