From 2e3187f3eb92707a0d838167f23c03e4eadbe3dc Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Fri, 30 Jul 2021 10:20:19 -0700 Subject: [PATCH] more linting --- src/adapters/webhook.js | 36 +++++----- test/unit/adapters/webhook.adapter.unit.js | 82 +++++++++++----------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/adapters/webhook.js b/src/adapters/webhook.js index 0620e5b..ee223cc 100644 --- a/src/adapters/webhook.js +++ b/src/adapters/webhook.js @@ -2,40 +2,40 @@ The (Clean Architecture) Adapter for manageing a webhook connection to P2WDB. */ -const config = require("../../config"); -const axios = require("axios"); +const config = require('../../config') +const axios = require('axios') -let _this; +let _this class WebHook { - constructor() { - _this = this; - _this.config = config; - _this.axios = axios; + constructor () { + _this = this + _this.config = config + _this.axios = axios } // REST petition to create a webhook in p2wdb-service - async createWebHook(url) { + async createWebHook (url) { try { - if (!url || typeof url !== "string") { - throw new Error("url must be a string"); + if (!url || typeof url !== 'string') { + throw new Error('url must be a string') } - const endpoint = _this.config.webhookService; + const endpoint = _this.config.webhookService const obj = { - appId: "torlist", + appId: 'torlist', url - }; + } - const result = await axios.post(endpoint, obj); + const result = await axios.post(endpoint, obj) - return result.data; + return result.data } catch (err) { - console.log("Error in adapters/webhook/createWebHook()"); - throw err; + console.log('Error in adapters/webhook/createWebHook()') + throw err } } } -module.exports = WebHook; +module.exports = WebHook diff --git a/test/unit/adapters/webhook.adapter.unit.js b/test/unit/adapters/webhook.adapter.unit.js index 138086c..2a570da 100644 --- a/test/unit/adapters/webhook.adapter.unit.js +++ b/test/unit/adapters/webhook.adapter.unit.js @@ -2,67 +2,67 @@ Unit tests for the webhook adapter. */ -const assert = require("chai").assert; -const sinon = require("sinon"); +const assert = require('chai').assert +const sinon = require('sinon') // Set the environment variable to signal this is a test. -process.env.SVC_ENV = "test"; +process.env.SVC_ENV = 'test' -const WebHook = require("../../../src/adapters/webhook"); +const WebHook = require('../../../src/adapters/webhook') -describe("#Webhook-Adapter", () => { - let uut; - let sandbox; +describe('#Webhook-Adapter', () => { + let uut + let sandbox beforeEach(async () => { - uut = new WebHook(); - sandbox = sinon.createSandbox(); - }); + uut = new WebHook() + sandbox = sinon.createSandbox() + }) - afterEach(() => sandbox.restore()); + afterEach(() => sandbox.restore()) - describe("#createWebHook", () => { - it("should throw error if input is not provided", async () => { + describe('#createWebHook', () => { + it('should throw error if input is not provided', async () => { try { - await uut.createWebHook(); - assert.fail("unexpected code path"); + await uut.createWebHook() + assert.fail('unexpected code path') } catch (err) { - assert.include(err.message, "url must be a string"); + assert.include(err.message, 'url must be a string') } - }); + }) - it("should throw error if input is not string", async () => { + it('should throw error if input is not string', async () => { try { - await uut.createWebHook(1); - assert.fail("unexpected code path"); + await uut.createWebHook(1) + assert.fail('unexpected code path') } catch (err) { - assert.include(err.message, "url must be a string"); + assert.include(err.message, 'url must be a string') } - }); + }) - it("should handle error", async () => { + it('should handle error', async () => { try { - sandbox.stub(uut.axios, "post").throws(new Error("test error")); - await uut.createWebHook("https://test.com/my-webhook"); - assert.fail("unexpected code path"); + sandbox.stub(uut.axios, 'post').throws(new Error('test error')) + await uut.createWebHook('https://test.com/my-webhook') + assert.fail('unexpected code path') } catch (err) { - assert.include(err.message, "test error"); + assert.include(err.message, 'test error') } - }); + }) - it("should return response", async () => { + it('should return response', async () => { sandbox - .stub(uut.axios, "post") - .resolves({ data: { success: true, id: "61018c8c9a71973a596cdccb" } }); + .stub(uut.axios, 'post') + .resolves({ data: { success: true, id: '61018c8c9a71973a596cdccb' } }) - const url = "https://test.com/my-webhook"; - const result = await uut.createWebHook(url); + const url = 'https://test.com/my-webhook' + const result = await uut.createWebHook(url) - assert.isObject(result); - assert.property(result, "success"); - assert.property(result, "id"); - assert.isBoolean(result.success); - assert.isString(result.id); - }); - }); -}); + assert.isObject(result) + assert.property(result, 'success') + assert.property(result, 'id') + assert.isBoolean(result.success) + assert.isString(result.id) + }) + }) +})