@@ -10,87 +10,93 @@ import {
10
10
generateMockTableRowData ,
11
11
} from '@/graphql/__tests__/mutations/tiles/table.mock'
12
12
import TableMetadata from '@/models/table-metadata'
13
+ import { DatabaseType } from '@/models/tiles/types'
13
14
import User from '@/models/user'
14
15
import Context from '@/types/express/context'
15
16
16
17
import tiles from '../..'
17
18
import createRowAction from '../../actions/create-row'
18
19
19
- describe ( 'tiles create row action' , ( ) => {
20
- let context : Context
21
- let dummyTable : TableMetadata
22
- let dummyColumnIds : string [ ]
23
- let editor : User
24
- let viewer : User
25
- let $ : IGlobalVariable
20
+ describe . each ( [ [ 'ddb' ] , [ 'pg' ] ] ) (
21
+ 'tiles create row action: %s' ,
22
+ ( databaseType : DatabaseType ) => {
23
+ let context : Context
24
+ let dummyTable : TableMetadata
25
+ let dummyColumnIds : string [ ]
26
+ let editor : User
27
+ let viewer : User
28
+ let $ : IGlobalVariable
26
29
27
- beforeEach ( async ( ) => {
28
- context = await generateMockContext ( )
30
+ beforeEach ( async ( ) => {
31
+ context = await generateMockContext ( )
29
32
30
- const mockTable = await generateMockTable ( {
31
- userId : context . currentUser . id ,
32
- } )
33
- dummyTable = mockTable . table
34
- editor = mockTable . editor
35
- viewer = mockTable . viewer
33
+ const mockTable = await generateMockTable ( {
34
+ userId : context . currentUser . id ,
35
+ databaseType,
36
+ } )
37
+ dummyTable = mockTable . table
38
+ editor = mockTable . editor
39
+ viewer = mockTable . viewer
36
40
37
- dummyColumnIds = await generateMockTableColumns ( {
38
- tableId : dummyTable . id ,
39
- numColumns : 5 ,
40
- } )
41
+ dummyColumnIds = await generateMockTableColumns ( {
42
+ tableId : dummyTable . id ,
43
+ numColumns : 5 ,
44
+ databaseType,
45
+ } )
41
46
42
- const validData = generateMockTableRowData ( { columnIds : dummyColumnIds } )
43
- const rowData = Object . keys ( validData ) . map ( ( columnId ) => ( {
44
- columnId,
45
- cellValue : validData [ columnId ] ,
46
- } ) )
47
+ const validData = generateMockTableRowData ( { columnIds : dummyColumnIds } )
48
+ const rowData = Object . keys ( validData ) . map ( ( columnId ) => ( {
49
+ columnId,
50
+ cellValue : validData [ columnId ] ,
51
+ } ) )
47
52
48
- $ = {
49
- user : context . currentUser ,
50
- flow : {
51
- id : '123' ,
52
- userId : context . currentUser . id ,
53
- } ,
54
- step : {
55
- id : '456' ,
56
- appKey : tiles . name ,
57
- key : createRowAction . key ,
58
- position : 2 ,
59
- parameters : {
60
- tableId : dummyTable . id ,
61
- rowData,
53
+ $ = {
54
+ user : context . currentUser ,
55
+ flow : {
56
+ id : '123' ,
57
+ userId : context . currentUser . id ,
58
+ } ,
59
+ step : {
60
+ id : '456' ,
61
+ appKey : tiles . name ,
62
+ key : createRowAction . key ,
63
+ position : 2 ,
64
+ parameters : {
65
+ tableId : dummyTable . id ,
66
+ rowData,
67
+ } ,
62
68
} ,
63
- } ,
64
- app : {
65
- name : tiles . name ,
66
- } ,
67
- setActionItem : vi . fn ( ) ,
68
- } as unknown as IGlobalVariable
69
- } )
69
+ app : {
70
+ name : tiles . name ,
71
+ } ,
72
+ setActionItem : vi . fn ( ) ,
73
+ } as unknown as IGlobalVariable
74
+ } )
70
75
71
- it ( 'should allow owners to create row' , async ( ) => {
72
- await expect ( createRowAction . run ( $ ) ) . resolves . toBeUndefined ( )
73
- expect ( $ . setActionItem ) . toBeCalled ( )
74
- } )
76
+ it ( 'should allow owners to create row' , async ( ) => {
77
+ await expect ( createRowAction . run ( $ ) ) . resolves . toBeUndefined ( )
78
+ expect ( $ . setActionItem ) . toBeCalled ( )
79
+ } )
75
80
76
- it ( 'should allow editors to create row' , async ( ) => {
77
- $ . user = editor
78
- await expect ( createRowAction . run ( $ ) ) . resolves . toBeUndefined ( )
79
- expect ( $ . setActionItem ) . toBeCalled ( )
80
- } )
81
+ it ( 'should allow editors to create row' , async ( ) => {
82
+ $ . user = editor
83
+ await expect ( createRowAction . run ( $ ) ) . resolves . toBeUndefined ( )
84
+ expect ( $ . setActionItem ) . toBeCalled ( )
85
+ } )
81
86
82
- it ( 'should not allow viewers to create row' , async ( ) => {
83
- $ . user = viewer
84
- await expect ( createRowAction . run ( $ ) ) . rejects . toThrow ( StepError )
85
- } )
87
+ it ( 'should not allow viewers to create row' , async ( ) => {
88
+ $ . user = viewer
89
+ await expect ( createRowAction . run ( $ ) ) . rejects . toThrow ( StepError )
90
+ } )
86
91
87
- it ( 'should throw correct error if Tile deleted' , async ( ) => {
88
- $ . user = editor
89
- await TableMetadata . query ( )
90
- . patch ( {
91
- deletedAt : new Date ( ) . toISOString ( ) ,
92
- } )
93
- . where ( { id : $ . step . parameters . tableId } )
94
- await expect ( createRowAction . run ( $ ) ) . rejects . toThrow ( StepError )
95
- } )
96
- } )
92
+ it ( 'should throw correct error if Tile deleted' , async ( ) => {
93
+ $ . user = editor
94
+ await TableMetadata . query ( )
95
+ . patch ( {
96
+ deletedAt : new Date ( ) . toISOString ( ) ,
97
+ } )
98
+ . where ( { id : $ . step . parameters . tableId } )
99
+ await expect ( createRowAction . run ( $ ) ) . rejects . toThrow ( StepError )
100
+ } )
101
+ } ,
102
+ )
0 commit comments