Skip to content

Commit

Permalink
Add return messages for missing fields and split the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-szlapa committed May 29, 2024
1 parent 60f1472 commit 647e23a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 84 deletions.
13 changes: 7 additions & 6 deletions packages/updatePrescriptionStatus/src/validation/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,21 @@ export function businessStatus(task: Task): string | undefined {
export function statuses(task: Task): string | undefined {
const status = task.status
const businessStatus: CodeableConcept | undefined = task.businessStatus

if (!businessStatus) {
return
return "Task.businessStatus is required."
}

const coding: Coding = businessStatus.coding![0]
const code = coding.code
const coding: Coding | undefined = businessStatus.coding && businessStatus.coding[0]
if (!coding) {
return "Task.businessStatus.coding is required."
}

const code: string | undefined = coding.code
if (!code) {
return
return "Task.businessStatus.coding.code is required."
}

const lowercaseCode = code.toLowerCase()

if (status === "completed" && IN_PROGRESS_BUSINESS_STATUSES.includes(lowercaseCode)) {
return (
"Task.status field set to 'completed' but Task.businessStatus value of '" + code + "' requires follow up action."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import {
expect,
describe,
Expand Down Expand Up @@ -216,83 +214,99 @@ describe("Unit tests for validation of status against business status", () => {
businessStatus,
expected
})
const testCases = [
generateTestCase(
"completed",
"With Pharmacy",
"Task.status field set to 'completed' but Task.businessStatus value of 'With Pharmacy' " +
"requires follow up action."
),
generateTestCase(
"completed",
"With Pharmacy - preparing remainder",
"Task.status field set to 'completed' but Task.businessStatus value of 'With Pharmacy - preparing remainder' " +
"requires follow up action."
),
generateTestCase(
"completed",
"Ready to collect",
"Task.status field set to 'completed' but Task.businessStatus value of 'Ready to collect' " +
"requires follow up action."
),
generateTestCase(
"completed",
"ReAdY tO cOlLeCt",
"Task.status field set to 'completed' but Task.businessStatus value of 'ReAdY tO cOlLeCt' " +
"requires follow up action."
),
generateTestCase(
"completed",
"Ready to collect - partial",
"Task.status field set to 'completed' but Task.businessStatus value of 'Ready to collect - partial' " +
"requires follow up action."
),
generateTestCase(
"completed",
"rEaDy To ColLEcT - pArtIAl",
"Task.status field set to 'completed' but Task.businessStatus value of 'rEaDy To ColLEcT - pArtIAl' " +
"requires follow up action."
),
generateTestCase("in-progress", "With Pharmacy", undefined),
generateTestCase("in-progress", "With Pharmacy - preparing remainder", undefined),
generateTestCase("in-progress", "Ready to collect", undefined),
generateTestCase("in-progress", "Ready to collect - partial", undefined),
generateTestCase(
"in-progress",
"Collected",
"Task.status field set to 'in-progress' but Task.businessStatus value of 'Collected' " +
"has no possible follow up action."
),
generateTestCase(
"in-progress",
"Not dispensed",
"Task.status field set to 'in-progress' but Task.businessStatus value of 'Not dispensed' " +
"has no possible follow up action."
),
generateTestCase(
"in-progress",
"Dispatched",
"Task.status field set to 'in-progress' but Task.businessStatus value of 'Dispatched' " +
"has no possible follow up action."
),
generateTestCase("completed", "Collected", undefined),
generateTestCase("completed", "Not dispensed", undefined),
generateTestCase("completed", "Dispatched", undefined),
generateTestCase("in-progress", "Ready to dispatch", undefined),
generateTestCase("in-progress", "Ready to dispatch - partial", undefined),
generateTestCase("completed", "Ready to dispatch", undefined),
generateTestCase("completed", "Ready to dispatch - partial", undefined)
]
it.each(testCases)(
"When status is '$taskStatus' and business status is '$businessStatus', should return expected issue.",
async ({taskStatus, businessStatus, expected}) => {
const task = {status: taskStatus, businessStatus: {coding: [{code: businessStatus}]}}

const actual = statuses(task as Task)

expect(actual).toEqual(expected)
}
)
describe("When task status is 'completed'", () => {
const completedTestCases = [
generateTestCase(
"completed",
"With Pharmacy",
"Task.status field set to 'completed' but Task.businessStatus value of 'With Pharmacy' " +
"requires follow up action."
),
generateTestCase(
"completed",
"With Pharmacy - preparing remainder",
"Task.status field set to 'completed' but Task.businessStatus value of 'With Pharmacy - preparing remainder' " +
"requires follow up action."
),
generateTestCase(
"completed",
"Ready to collect",
"Task.status field set to 'completed' but Task.businessStatus value of 'Ready to collect' " +
"requires follow up action."
),
generateTestCase(
"completed",
"ReAdY tO cOlLeCt",
"Task.status field set to 'completed' but Task.businessStatus value of 'ReAdY tO cOlLeCt' " +
"requires follow up action."
),
generateTestCase(
"completed",
"Ready to collect - partial",
"Task.status field set to 'completed' but Task.businessStatus value of 'Ready to collect - partial' " +
"requires follow up action."
),
generateTestCase(
"completed",
"rEaDy To ColLEcT - pArtIAl",
"Task.status field set to 'completed' but Task.businessStatus value of 'rEaDy To ColLEcT - pArtIAl' " +
"requires follow up action."
),
generateTestCase("completed", "Collected", undefined),
generateTestCase("completed", "Not dispensed", undefined),
generateTestCase("completed", "Dispatched", undefined),
generateTestCase("completed", "Ready to dispatch", undefined),
generateTestCase("completed", "Ready to dispatch - partial", undefined)
]

it.each(completedTestCases)(
"When status is '$taskStatus' and business status is '$businessStatus', should return expected issue.",
async ({taskStatus, businessStatus, expected}) => {
const task = {status: taskStatus, businessStatus: {coding: [{code: businessStatus}]}}
const actual = statuses(task as Task)
expect(actual).toEqual(expected)
}
)
})

describe("When task status is 'in-progress'", () => {
const inProgressTestCases = [
generateTestCase("in-progress", "With Pharmacy", undefined),
generateTestCase("in-progress", "With Pharmacy - preparing remainder", undefined),
generateTestCase("in-progress", "Ready to collect", undefined),
generateTestCase("in-progress", "Ready to collect - partial", undefined),
generateTestCase(
"in-progress",
"Collected",
"Task.status field set to 'in-progress' but Task.businessStatus value of 'Collected' " +
"has no possible follow up action."
),
generateTestCase(
"in-progress",
"Not dispensed",
"Task.status field set to 'in-progress' but Task.businessStatus value of 'Not dispensed' " +
"has no possible follow up action."
),
generateTestCase(
"in-progress",
"Dispatched",
"Task.status field set to 'in-progress' but Task.businessStatus value of 'Dispatched' " +
"has no possible follow up action."
),
generateTestCase("in-progress", "Ready to dispatch", undefined),
generateTestCase("in-progress", "Ready to dispatch - partial", undefined)
]

it.each(inProgressTestCases)(
"When status is '$taskStatus' and business status is '$businessStatus', should return expected issue.",
async ({taskStatus, businessStatus, expected}) => {
const task = {status: taskStatus, businessStatus: {coding: [{code: businessStatus}]}}
const actual = statuses(task as Task)
expect(actual).toEqual(expected)
}
)
})
})

describe("Unit tests for validation of resourceType", () => {
Expand Down

0 comments on commit 647e23a

Please sign in to comment.