Skip to content

Commit

Permalink
test: unit testing fixes (#75)
Browse files Browse the repository at this point in the history
- moved to node 20
- moved to vitest
- updated ci
  • Loading branch information
Bugs5382 authored Feb 4, 2024
2 parents c0e7cdf + f9345c0 commit 0bb8565
Show file tree
Hide file tree
Showing 32 changed files with 855 additions and 1,202 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ jobs:
id-token: write
strategy:
matrix:
node-version: [ 18.x, 20.x, 'lts/*' ]
node-version: [ 20.x, 'lts/*' ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install --ignore-scripts
- name: Run Lint Fix
run: npm run lint:fix
- name: Run Unit Tests
run: npm run test:ci
run: npm run test
Release:
runs-on: ubuntu-latest
needs: [ 'Test' ]
Expand All @@ -37,11 +37,11 @@ jobs:
pull-requests: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 'lts/*'
- name: NPM Install
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# [1.2.0-beta.1](https://github.com/Bugs5382/node-hl7-client/compare/v1.1.3...v1.2.0-beta.1) (2024-01-22)


### Features

* better error reporting ([#73](https://github.com/Bugs5382/node-hl7-client/issues/73)) ([f5707ae](https://github.com/Bugs5382/node-hl7-client/commit/f5707aed9c2bed71dd783f6a632f791ce4203127))
* fix error reporting issue ([414276a](https://github.com/Bugs5382/node-hl7-client/commit/414276af1a207b4d781d0a0b277d0808251fc83d))

## [1.1.3](https://github.com/Bugs5382/node-hl7-client/compare/v1.1.2...v1.1.3) (2024-01-11)


Expand Down
21 changes: 0 additions & 21 deletions __tests__/__utils__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,3 @@ export const sleep = async (ms: number): Promise<unknown> => {
export const expectEvent = async <T=any>(emitter: EventEmitter, name: string | symbol): Promise<T> => {
return await new Promise<T>((resolve) => { emitter.once(name, resolve) })
}

/** @internal */
export interface Deferred<T=any> {
resolve: (value: T | PromiseLike<T>) => void
reject: (reason?: any) => void
promise: Promise<T>
}

/** @internal */
export const createDeferred = <T=any>(noUncaught?: boolean): Deferred<T> => {
const dfd: any = {}
dfd.promise = new Promise((resolve, reject) => {
dfd.resolve = resolve
dfd.reject = reject
})
/* istanbul ignore next */
if (noUncaught === false) {
dfd.promise.catch(() => {})
}
return dfd
}
24 changes: 24 additions & 0 deletions __tests__/__utils__/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createHL7Date, Message } from '../../src'

export function _createAckMessage (type: string, message: Message): Message {
const ackMessage = new Message({
messageHeader: {
msh_9_1: 'ACK',
msh_9_2: message.get('MSH.9.2').toString(),
msh_10: `ACK${createHL7Date(new Date())}`,
msh_11_1: message.get('MSH.11.1').toString() as 'P' | 'D' | 'T'
}
})

ackMessage.set('MSH.3', message.get('MSH.5').toString())
ackMessage.set('MSH.4', message.get('MSH.6').toString())
ackMessage.set('MSH.5', message.get('MSH.3').toString())
ackMessage.set('MSH.6', message.get('MSH.4').toString())
ackMessage.set('MSH.12', message.get('MSH.12').toString())

const segment = ackMessage.addSegment('MSA')
segment.set('1', type)
segment.set('2', message.get('MSH.10').toString())

return ackMessage
}
1 change: 1 addition & 0 deletions __tests__/hl7.build.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { randomUUID } from 'crypto'
import fs from 'fs'
import path from 'path'
import { describe, expect, test, beforeEach, beforeAll } from 'vitest';
import { FileBatch, Batch, Message, createHL7Date, HL7Node, EmptyNode } from '../src'
import { HL7_2_1, HL7_2_7, HL7_2_2, HL7_2_3, HL7_2_3_1, HL7_2_4, HL7_2_5, HL7_2_5_1, HL7_2_6, HL7_2_7_1, HL7_2_8 } from '../src/hl7'
import {MSH_HEADER} from "./__data__/constants";
Expand Down
16 changes: 9 additions & 7 deletions __tests__/hl7.client.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test, beforeEach } from 'vitest';
import { Client } from '../src'

describe('node hl7 client', () => {
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('node hl7 client', () => {

test('properties exist', async () => {
const client = new Client({ host: 'hl7.server.local' })
expect(client).toHaveProperty('createOutbound')
expect(client).toHaveProperty('createConnection')
})

test('ensure getHost() is what we set in the host', async () => {
Expand All @@ -73,7 +74,7 @@ describe('node hl7 client', () => {
test('error - no port specified', async () => {
try {
// @ts-expect-error port is not specified
client.createOutbound()
client.createConnection()
} catch (err: any) {
expect(err.message).toBe('port is not defined.')
}
Expand All @@ -82,26 +83,27 @@ describe('node hl7 client', () => {
test('error - port not a number', async () => {
try {
// @ts-expect-error port is not specified as a number
client.createOutbound({ port: '12345' }, async () => {})
client.createConnection({ port: '12345' }, async () => {})
} catch (err: any) {
expect(err.message).toBe('port is not valid number.')
}
})

test('error - port less than 0', async () => {
try {
client.createOutbound({ port: -1 }, async () => {})
client.createConnection({ port: -1 }, async () => {})
} catch (err: any) {
expect(err.message).toBe('port must be a number (0, 65353).')
expect(err.message).toBe('port must be a number (1, 65353).')
}
})

test('error - port greater than 65353', async () => {
try {
client.createOutbound({ port: 65354 }, async () => {})
client.createConnection({ port: 65354 }, async () => {})
} catch (err: any) {
expect(err.message).toBe('port must be a number (0, 65353).')
expect(err.message).toBe('port must be a number (1, 65353).')
}
})

})
})
Loading

0 comments on commit 0bb8565

Please sign in to comment.