Skip to content

Commit fb6530a

Browse files
feat: add missing tests
1 parent c76d6c0 commit fb6530a

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
})

packages/field-plugin/src/messaging/pluginMessage/containerToPluginMessage/PromptAIResponseMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const isPromptAIMessage = (
1212
data: unknown,
1313
): data is PromptAIResponseMessage =>
1414
isMessageToPlugin(data) &&
15+
data.action === 'prompt-ai' &&
1516
hasKey(data, 'output') &&
1617
typeof data.output === 'string'
1718

0 commit comments

Comments
 (0)