forked from medplum/medplum-demo-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0fc6e9
commit 516185b
Showing
6 changed files
with
89 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,26 @@ | |
"description": "Medplum Demo Bots", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "vitest run", | ||
"test:coverage": "vitest run --coverage", | ||
"deploy:hello-world": "medplum deploy-bot dist/hello-world.js e54fa800-02ab-41be-8d48-8c027dd85f0c" | ||
}, | ||
"author": "Medplum <[email protected]>", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@medplum/cli": "^0.9.4", | ||
"@medplum/core": "^0.9.4", | ||
"@medplum/fhirtypes": "^0.9.4", | ||
"@types/node": "^17.0.31", | ||
"eslint": "8.14.0", | ||
"@medplum/cli": "0.9.5", | ||
"@medplum/core": "0.9.5", | ||
"@medplum/fhirtypes": "0.9.5", | ||
"@medplum/mock": "0.9.5", | ||
"@types/node": "17.0.33", | ||
"c8": "7.11.2", | ||
"eslint": "8.15.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"node-fetch": "^3.2.4", | ||
"node-fetch": "3.2.4", | ||
"prettier": "2.6.2", | ||
"typescript": "^4.6.4" | ||
"typescript": "4.6.4", | ||
"vitest": "0.12.6" | ||
}, | ||
"eslintConfig": { | ||
"parser": "@typescript-eslint/parser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { MockClient } from '@medplum/mock'; | ||
import { expect, test } from 'vitest'; | ||
import { handler } from './hello-world'; | ||
|
||
const medplum = new MockClient(); | ||
|
||
test('Hello world', () => { | ||
const input = 'Hello'; | ||
const contentType = 'text/plain'; | ||
expect(handler(medplum, { input, contentType })).resolves.toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { MedplumClient } from '@medplum/core'; | ||
import { Resource } from '@medplum/fhirtypes'; | ||
import { BotEvent, MedplumClient } from '@medplum/core'; | ||
|
||
export async function handler(medplum: MedplumClient, input: Resource): Promise<any> { | ||
export async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> { | ||
console.log('Hello world'); | ||
console.log(JSON.stringify(input, undefined, 2)); | ||
console.log(JSON.stringify(event, undefined, 2)); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { QuestionnaireResponse } from '@medplum/fhirtypes'; | ||
import { MockClient } from '@medplum/mock'; | ||
import { expect, test, vi } from 'vitest'; | ||
import { handler } from './patient-intake'; | ||
|
||
const medplum = new MockClient(); | ||
const contentType = 'application/fhir+json'; | ||
|
||
test('Success', async () => { | ||
const input: QuestionnaireResponse = { | ||
resourceType: 'QuestionnaireResponse', | ||
item: [ | ||
{ linkId: 'firstName', answer: [{ valueString: 'John' }] }, | ||
{ linkId: 'lastName', answer: [{ valueString: 'Smith' }] }, | ||
{ linkId: 'comment', answer: [{ valueString: 'Please review urgently' }] }, | ||
], | ||
}; | ||
const result = await handler(medplum, { input, contentType }); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
test('Missing first name', async () => { | ||
console.log = vi.fn(); | ||
const input: QuestionnaireResponse = { | ||
resourceType: 'QuestionnaireResponse', | ||
item: [ | ||
{ linkId: 'firstName', answer: [{ valueString: '' }] }, | ||
{ linkId: 'lastName', answer: [{ valueString: 'Smith' }] }, | ||
], | ||
}; | ||
const result = await handler(medplum, { input, contentType }); | ||
expect(result).toBe(false); | ||
expect(console.log).toBeCalledWith('Missing first name'); | ||
}); | ||
|
||
test('Missing last name', async () => { | ||
console.log = vi.fn(); | ||
const input: QuestionnaireResponse = { | ||
resourceType: 'QuestionnaireResponse', | ||
item: [ | ||
{ linkId: 'firstName', answer: [{ valueString: 'John' }] }, | ||
{ linkId: 'lastName', answer: [{ valueString: '' }] }, | ||
], | ||
}; | ||
const result = await handler(medplum, { input, contentType }); | ||
expect(result).toBe(false); | ||
expect(console.log).toBeCalledWith('Missing last name'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
}, | ||
}); |