@@ -16,7 +16,7 @@ import { ClsService } from 'nestjs-cls';
16
16
import { ApiKeyService } from '@/customer/api-key/api-key.service' ;
17
17
import { ApiKeyRepository } from '@/customer/api-key/api-key.repository' ;
18
18
19
- const buildWorkflowDefinition = ( sequenceNum : number , projectId ?: string ) => {
19
+ const buildWorkflowDefinition = ( sequenceNum : number , projectId ?: string , isPublic = false ) => {
20
20
return {
21
21
id : sequenceNum . toString ( ) ,
22
22
name : `name ${ sequenceNum } ` ,
@@ -42,7 +42,7 @@ const buildWorkflowDefinition = (sequenceNum: number, projectId?: string) => {
42
42
schema : { } ,
43
43
} ,
44
44
projectId : projectId ,
45
- isPublic : false ,
45
+ isPublic : isPublic ,
46
46
} ;
47
47
} ;
48
48
@@ -83,7 +83,7 @@ describe('WorkflowDefinitionService', () => {
83
83
84
84
beforeEach ( async ( ) => {
85
85
await prismaService . workflowDefinition . create ( {
86
- data : buildWorkflowDefinition ( 1 ) ,
86
+ data : buildWorkflowDefinition ( Math . floor ( Math . random ( ) * 1000 ) + 1 ) ,
87
87
} ) ;
88
88
89
89
const customer = await createCustomer (
@@ -242,4 +242,41 @@ describe('WorkflowDefinitionService', () => {
242
242
expect ( latestWorkflowVersion . id ) . toEqual ( updatedWorkflowDefintiion . id ) ;
243
243
} ) ;
244
244
} ) ;
245
+
246
+ describe ( 'Public records (templates)' , ( ) => {
247
+ it ( 'should not allow editing of public records' , async ( ) => {
248
+ // Arrange
249
+ const publicWorkflowDefinition = await prismaService . workflowDefinition . create ( {
250
+ data : buildWorkflowDefinition ( 11 , undefined , true ) ,
251
+ } ) ;
252
+
253
+ const updateArgs = {
254
+ definition : { some : 'new definition' } ,
255
+ } ;
256
+
257
+ // Act & Assert
258
+ await expect (
259
+ workflowDefinitionService . updateById ( publicWorkflowDefinition . id , updateArgs as any , [
260
+ project . id ,
261
+ ] ) ,
262
+ ) . rejects . toThrow ( 'Cannot update public workflow definition templates' ) ;
263
+ } ) ;
264
+
265
+ it ( 'should allow reading of public records' , async ( ) => {
266
+ // Arrange
267
+ const publicWorkflowDefinition = await prismaService . workflowDefinition . create ( {
268
+ data : buildWorkflowDefinition ( 23 , undefined , true ) ,
269
+ } ) ;
270
+
271
+ // Act
272
+ const result = await workflowDefinitionService . getLatestVersion ( publicWorkflowDefinition . id , [
273
+ project . id ,
274
+ ] ) ;
275
+
276
+ // Assert
277
+ expect ( result ) . toBeDefined ( ) ;
278
+ expect ( result . id ) . toEqual ( publicWorkflowDefinition . id ) ;
279
+ expect ( result . isPublic ) . toBe ( true ) ;
280
+ } ) ;
281
+ } ) ;
245
282
} ) ;
0 commit comments