Skip to content

Commit

Permalink
feat: add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
demetriusfeijoo committed Jan 3, 2025
1 parent c76d6c0 commit fb6530a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
type PromptAIResponseMessage,
isPromptAIMessage,
} from './PromptAIResponseMessage'

const stub: PromptAIResponseMessage = {
action: 'prompt-ai',
uid: '-preview',
callbackId: 'test-callback-id',
output: 'test-output',
}

describe('PromptAIResponseMessage', function () {
it('is a message to plugin', () => {
expect(isPromptAIMessage(stub)).toEqual(true)
})
describe('the action property', () => {
it('equals "prompt-ai"', () => {
expect(
isPromptAIMessage({
...stub,
action: 'prompt-ai',
}),
).toEqual(true)
expect(
isPromptAIMessage({
...stub,
action: 'something-else',
}),
).toEqual(false)
})
})
describe('the output property', () => {
it('cannot be undefined', () => {
expect(
isPromptAIMessage({
...stub,
output: undefined,
}),
).toEqual(false)
})
it('is a string', () => {
expect(
isPromptAIMessage({
...stub,
output: 'any-string',
}),
).toEqual(true)
expect(
isPromptAIMessage({
...stub,
output: 123,
}),
).toEqual(false)
expect(
isPromptAIMessage({
...stub,
output: null,
}),
).toEqual(false)
expect(
isPromptAIMessage({
...stub,
output: [],
}),
).toEqual(false)
expect(
isPromptAIMessage({
...stub,
output: {},
}),
).toEqual(false)
expect(
isPromptAIMessage({
...stub,
output: false,
}),
).toEqual(false)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const isPromptAIMessage = (
data: unknown,
): data is PromptAIResponseMessage =>
isMessageToPlugin(data) &&
data.action === 'prompt-ai' &&
hasKey(data, 'output') &&
typeof data.output === 'string'

Expand Down

0 comments on commit fb6530a

Please sign in to comment.