more linting

This commit is contained in:
Chris Troutner
2021-07-30 10:20:19 -07:00
parent 60a2c49863
commit 2e3187f3eb
2 changed files with 59 additions and 59 deletions
+18 -18
View File
@@ -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
+41 -41
View File
@@ -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)
})
})
})