Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
Bugs5382 committed Dec 22, 2023
1 parent ce7a79f commit 1f37c31
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions __tests__/hl7.end2end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,4 +622,90 @@ describe('node hl7 end to end - client', () => {

})

describe('...send file with two message, get proper ACK', () => {

let LISTEN_PORT: number

const hl7_string: string = "MSH|^~\\&|||||20081231||ADT^A01^ADT_A01|12345|D|2.7\rEVN||20081231\rMSH|^~\\&|||||20081231||ADT^A01^ADT_A01|12345|D|2.7\rEVN||20081231"

beforeAll(async () => {

fs.readdir("temp/", (err, files) => {
if (err) return;
for (const file of files) {
fs.unlink(path.join("temp/", file), (err) => {
if (err) throw err;
});
}
})

await sleep(2)

const message = new Message({text: hl7_string, date: "8"})
message.toFile('readFileTestMSH', true, 'temp/')

fs.access("temp/hl7.readFileTestMSH.20081231.hl7", fs.constants.F_OK, (err) => {
if (!err) {
// Do something
}
});

await (async () => {
try {
await fs.promises.access("temp/hl7.readFileTestMSH.20081231.hl7", fs.constants.F_OK);
// Do something
} catch (err) {
// Handle error
}
})();

})

beforeEach(async () => {
LISTEN_PORT = await portfinder.getPortPromise({
port: 3000,
stopPort: 65353
})

dfd = createDeferred<void>()

})

test('...no tls', async () => {

const server = new Server({bindAddress: '0.0.0.0'})
const IB_ADT = server.createInbound({port: LISTEN_PORT}, async (req, res) => {
const messageReq = req.getMessage()
expect(messageReq.get('MSH.12').toString()).toBe('2.7')
await res.sendResponse("AA")
})

// await expectEvent(IB_ADT, 'listen')

const client = new Client({host: '0.0.0.0'})
let count: number = 0
const OB_ADT = client.createOutbound({ port: LISTEN_PORT }, async (res) => {
const messageRes = res.getMessage()
expect(messageRes.get('MSA.1').toString()).toBe('AA')
count += 1
if (count == 2) {
dfd.resolve()
}
})

await expectEvent(OB_ADT, 'connect')

const fileBatch = await OB_ADT.readFile(`temp/hl7.readFileTestMSH.20081231.hl7`)

await OB_ADT.sendMessage(fileBatch)

await dfd.promise

await OB_ADT.close()
await IB_ADT.close()

})

})

})

0 comments on commit 1f37c31

Please sign in to comment.