File tree Expand file tree Collapse file tree 2 files changed +82
-0
lines changed
packages/field-plugin/src/messaging/pluginMessage/containerToPluginMessage Expand file tree Collapse file tree 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ import {
2
+ type PromptAIResponseMessage ,
3
+ isPromptAIMessage ,
4
+ } from './PromptAIResponseMessage'
5
+
6
+ const stub : PromptAIResponseMessage = {
7
+ action : 'prompt-ai' ,
8
+ uid : '-preview' ,
9
+ callbackId : 'test-callback-id' ,
10
+ output : 'test-output' ,
11
+ }
12
+
13
+ describe ( 'PromptAIResponseMessage' , function ( ) {
14
+ it ( 'is a message to plugin' , ( ) => {
15
+ expect ( isPromptAIMessage ( stub ) ) . toEqual ( true )
16
+ } )
17
+ describe ( 'the action property' , ( ) => {
18
+ it ( 'equals "prompt-ai"' , ( ) => {
19
+ expect (
20
+ isPromptAIMessage ( {
21
+ ...stub ,
22
+ action : 'prompt-ai' ,
23
+ } ) ,
24
+ ) . toEqual ( true )
25
+ expect (
26
+ isPromptAIMessage ( {
27
+ ...stub ,
28
+ action : 'something-else' ,
29
+ } ) ,
30
+ ) . toEqual ( false )
31
+ } )
32
+ } )
33
+ describe ( 'the output property' , ( ) => {
34
+ it ( 'cannot be undefined' , ( ) => {
35
+ expect (
36
+ isPromptAIMessage ( {
37
+ ...stub ,
38
+ output : undefined ,
39
+ } ) ,
40
+ ) . toEqual ( false )
41
+ } )
42
+ it ( 'is a string' , ( ) => {
43
+ expect (
44
+ isPromptAIMessage ( {
45
+ ...stub ,
46
+ output : 'any-string' ,
47
+ } ) ,
48
+ ) . toEqual ( true )
49
+ expect (
50
+ isPromptAIMessage ( {
51
+ ...stub ,
52
+ output : 123 ,
53
+ } ) ,
54
+ ) . toEqual ( false )
55
+ expect (
56
+ isPromptAIMessage ( {
57
+ ...stub ,
58
+ output : null ,
59
+ } ) ,
60
+ ) . toEqual ( false )
61
+ expect (
62
+ isPromptAIMessage ( {
63
+ ...stub ,
64
+ output : [ ] ,
65
+ } ) ,
66
+ ) . toEqual ( false )
67
+ expect (
68
+ isPromptAIMessage ( {
69
+ ...stub ,
70
+ output : { } ,
71
+ } ) ,
72
+ ) . toEqual ( false )
73
+ expect (
74
+ isPromptAIMessage ( {
75
+ ...stub ,
76
+ output : false ,
77
+ } ) ,
78
+ ) . toEqual ( false )
79
+ } )
80
+ } )
81
+ } )
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export const isPromptAIMessage = (
12
12
data : unknown ,
13
13
) : data is PromptAIResponseMessage =>
14
14
isMessageToPlugin ( data ) &&
15
+ data . action === 'prompt-ai' &&
15
16
hasKey ( data , 'output' ) &&
16
17
typeof data . output === 'string'
17
18
You can’t perform that action at this time.
0 commit comments