From 3dc0c1cae7e4b22288f4e8f6f6a53635f2a32a54 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 2 Nov 2018 19:12:16 +0100 Subject: [PATCH] add tests --- qenv.yml | 2 +- test/test.ts | 4 ++++ ts/logdna.logdnaaccount.ts | 45 +++++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/qenv.yml b/qenv.yml index e9f1679..cd68ff8 100644 --- a/qenv.yml +++ b/qenv.yml @@ -1,2 +1,2 @@ vars: - - LGDNA_APIKEY \ No newline at end of file + - LOGDNA_APIKEY \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 300bb9b..73b359b 100644 --- a/test/test.ts +++ b/test/test.ts @@ -27,4 +27,8 @@ tap.test('should create a standard log message', async () => { }); }); +tap.test('should send the message', async () => { + await testLogDnaAccount.sendLogDnaMessage(testLogMessage); +}) + tap.start(); diff --git a/ts/logdna.logdnaaccount.ts b/ts/logdna.logdnaaccount.ts index 38c3a88..0761c08 100644 --- a/ts/logdna.logdnaaccount.ts +++ b/ts/logdna.logdnaaccount.ts @@ -32,29 +32,38 @@ export class LogdnaAccount { public async sendLogDnaMessage(logdnaMessageArg: LogdnaMessage) { const lm = logdnaMessageArg; const euc = encodeURIComponent; - + // let construct the request uri - const requestUrlWithParams = `${this.baseUrl}?hostname=${euc( - lm.options.hostname - )}&mac=${euc(lm.options.mac)}&ip=1${euc(lm.options.ip)}&now=${Date.now()}`; - + const requestUrlWithParams = `${this.baseUrl}?hostname=${euc(lm.options.hostname)}&mac=${euc( + lm.options.mac + )}&ip=1${euc(lm.options.ip)}&now=${Date.now()}`; + + const requestBodyObject = { + lines: [ + { + line: lm.options.line, + app: lm.options.app, + level: lm.options.level, + env: lm.options.env, + meta: lm.options.meta, + tags: (() => { + return lm.options.tags.reduce((reduced, newItem) => { + return `${reduced},${newItem}`; + }); + })() + } + ] + }; + + console.log(requestBodyObject); + // lets post the message to logdna await plugins.smartrequest.postJson(requestUrlWithParams, { headers: { - 'Authorization': this.createBasicAuth(), - 'charset': 'UTF-8' + Authorization: this.createBasicAuth(), + charset: 'UTF-8' }, - requestBody: { - "lines": [ - { - "line": lm.options.line, - "app": lm.options.app, - "level": lm.options.level, - "env": lm.options.env, - "meta": lm.options.meta - } - ] - } + requestBody: requestBodyObject }); } }