From: Justin Wind Date: Mon, 3 Jul 2023 18:02:03 +0000 (-0700) Subject: lint cleanup X-Git-Tag: v1.3.12^2~5 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=71587de3ea9839d14d9f7bffa6c1db19e52dd9b5;p=websub-hub lint cleanup --- diff --git a/test/src/common.js b/test/src/common.js index e46f96a..e205619 100644 --- a/test/src/common.js +++ b/test/src/common.js @@ -134,7 +134,7 @@ describe('Common', function () { it('covers default', function () { const result = common.attemptRetrySeconds(0); assert(result >= 60); - assert(result <= 60 * 1.618) + assert(result <= 60 * 1.618); }); }); // attemptRetrySeconds diff --git a/test/src/communication.js b/test/src/communication.js index 8be9241..3e09b3d 100644 --- a/test/src/communication.js +++ b/test/src/communication.js @@ -709,14 +709,14 @@ describe('Communication', function () { it('covers claim', async function () { communication.db.topicFetchClaimById.resolves({ changes: 1, - }) + }); await communication.topicFetchClaimAndProcessById(dbCtx, topicId, requestId); assert(communication.topicFetchProcess.called); }); it('covers no claim', async function () { communication.db.topicFetchClaimById.resolves({ changes: 0, - }) + }); await communication.topicFetchClaimAndProcessById(dbCtx, topicId, requestId); assert(!communication.topicFetchProcess.called); }); @@ -733,14 +733,14 @@ describe('Communication', function () { it('covers claim', async function () { communication.db.verificationClaimById.resolves({ changes: 1, - }) + }); await communication.verificationClaimAndProcessById(dbCtx, verificationId, requestId); assert(communication.verificationProcess.called); }); it('covers no claim', async function () { communication.db.verificationClaimById.resolves({ changes: 0, - }) + }); await communication.verificationClaimAndProcessById(dbCtx, verificationId, requestId); assert(!communication.verificationProcess.called); }); diff --git a/test/src/db/integration.js b/test/src/db/integration.js index bd28e92..84d1d26 100644 --- a/test/src/db/integration.js +++ b/test/src/db/integration.js @@ -285,7 +285,7 @@ describe('Database Integration', function () { const data = { ...testData.subscriptionUpsert, topicId, - } + }; await db.context(async (dbCtx) => { const result = await db.subscriptionUpsert(dbCtx, data); assert(result.lastInsertRowid); @@ -364,7 +364,7 @@ describe('Database Integration', function () { ...testData.subscriptionUpsert, secret: 'newSecret', topicId, - } + }; await db.context(async (dbCtx) => { const result = await db.subscriptionUpsert(dbCtx, data); assert(result.lastInsertRowid); @@ -416,7 +416,7 @@ describe('Database Integration', function () { }); step('delete expired subscriptions', async function() { await db.context(async (dbCtx) => { - await db.subscriptionDeleteExpired(dbCtx, topicId) + await db.subscriptionDeleteExpired(dbCtx, topicId); const subscription = await db.subscriptionGet(dbCtx, testData.subscriptionUpsert.callback, topicId); assert(!subscription); }); diff --git a/test/src/db/postgres-listener.js b/test/src/db/postgres-listener.js index ecd2fe2..eaa3a1c 100644 --- a/test/src/db/postgres-listener.js +++ b/test/src/db/postgres-listener.js @@ -2,7 +2,7 @@ 'use strict'; const assert = require('assert'); -const sinon = require('sinon'); +const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require const stubLogger = require('../../stub-logger'); const Listener = require('../../../src/db/postgres/listener'); diff --git a/test/src/db/postgres.js b/test/src/db/postgres.js index d6bf674..c762135 100644 --- a/test/src/db/postgres.js +++ b/test/src/db/postgres.js @@ -65,7 +65,7 @@ describe('DatabasePostgres', function () { httpRemoteAddr = '127.0.0.1'; httpFrom = 'user@example.com'; wanted = 5; -}); + }); afterEach(function () { sinon.restore(); }); @@ -631,7 +631,7 @@ describe('DatabasePostgres', function () { const expected = new Error(); sinon.stub(db.db, 'manyOrNone').throws(expected); try { - await db.subscriptionDeliveryClaim(dbCtx, wanted, claimTimeoutSeconds, claimant ); + await db.subscriptionDeliveryClaim(dbCtx, wanted, claimTimeoutSeconds, claimant); assert.fail(noExpectedException); } catch (e) { assert.deepStrictEqual(e, expected); @@ -650,7 +650,7 @@ describe('DatabasePostgres', function () { changes: 1, lastInsertRowid: 'c2e254c5-aa6e-4a8f-b1a1-e474b07392bb', duration: 11, - } + }; sinon.stub(db.db, 'result').resolves(dbResult); const result = await db.subscriptionDeliveryClaimById(dbCtx, subscriptionId, claimTimeoutSeconds, claimant); assert.deepStrictEqual(result, expected); @@ -1026,7 +1026,7 @@ describe('DatabasePostgres', function () { rowCount: 1, rows: [], duration: 10, - } + }; const expected = { changes: 1, lastInsertRowid: undefined, @@ -1048,7 +1048,7 @@ describe('DatabasePostgres', function () { rowCount: 1, rows: [], duration: 10, - } + }; const expected = { changes: 1, lastInsertRowid: undefined, @@ -1070,7 +1070,7 @@ describe('DatabasePostgres', function () { rowCount: 0, rows: [], duration: 10, - } + }; sinon.stub(db.db, 'one').resolves(dbOne); sinon.stub(db.db, 'result').onCall(0).resolves(dbResult0).onCall(1).resolves(dbResult1); try { @@ -1091,7 +1091,7 @@ describe('DatabasePostgres', function () { rowCount: 0, rows: [], duration: 10, - } + }; sinon.stub(db.db, 'one').resolves(dbOne); sinon.stub(db.db, 'result').onCall(0).resolves(dbResult0).onCall(1).resolves(dbResult1); try { @@ -1764,7 +1764,7 @@ describe('DatabasePostgres', function () { rowCount: 0, rows: [], duration: 10, - } + }; sinon.stub(db.db, 'result').resolves(dbResult); try { await db.verificationUpdate(dbCtx, verificationId, data); @@ -1790,7 +1790,7 @@ describe('DatabasePostgres', function () { rowCount: 1, rows: [], duration: 10, - } + }; sinon.stub(db.db, 'result').resolves(dbResult); await db.verificationValidated(dbCtx, verificationId); }); @@ -1799,7 +1799,7 @@ describe('DatabasePostgres', function () { rowCount: 0, rows: [], duration: 10, - } + }; sinon.stub(db.db, 'result').resolves(dbResult); try { await db.verificationValidated(dbCtx, verificationId); diff --git a/test/src/db/schema-version-helper.js b/test/src/db/schema-version-helper.js index b69735e..4a95202 100644 --- a/test/src/db/schema-version-helper.js +++ b/test/src/db/schema-version-helper.js @@ -121,6 +121,7 @@ describe('SchemaVersionHelper', function () { .onCall(i++).returns(notDir) // 'init.sql' .onCall(i++).returns(isDir).onCall(i++).returns(isMig) // '1.0.1' .onCall(i++).returns(isDir).onCall(i++).returns(isMig) // '1.0.0' + ; const result = svh.allSchemaVersions('path'); assert.deepStrictEqual(result, expected); }); @@ -137,7 +138,7 @@ describe('SchemaVersionHelper', function () { max: { major: 1, minor: 1, patch: 1 }, }; current = { major: 1, minor: 0, patch: 1 }; - }); + }); it('covers', function () { const expected = ['1.1.0', '1.1.1']; fs.readdirSync.returns(['1.1.2', 'file.txt', '1.1.0', '1.1.1', 'init.sql', '1.0.1', '1.0.0']); @@ -151,6 +152,7 @@ describe('SchemaVersionHelper', function () { .onCall(i++).returns(notDir) // 'init.sql' .onCall(i++).returns(isDir).onCall(i++).returns(isMig) // '1.0.1' .onCall(i++).returns(isDir).onCall(i++).returns(isMig) // '1.0.0' + ; const result = svh.unappliedSchemaVersions('path', current, supported); assert.deepStrictEqual(result, expected); }); diff --git a/test/src/db/sqlite.js b/test/src/db/sqlite.js index deb0ee2..e466930 100644 --- a/test/src/db/sqlite.js +++ b/test/src/db/sqlite.js @@ -237,7 +237,7 @@ describe('DatabaseSQLite', function () { contentFetchNextAttempt: now, contentUpdated: now, url: topic.url, - } + }; const result = DB._topicDataToNative(topic); assert.deepStrictEqual(result, expected); }); @@ -881,7 +881,7 @@ describe('DatabaseSQLite', function () { const dbResult1 = { changes: 1, lastInsertRowid: undefined, - } + }; const expected = { changes: 1, lastInsertRowid: undefined, @@ -901,7 +901,7 @@ describe('DatabaseSQLite', function () { const dbResult1 = { changes: 1, lastInsertRowid: undefined, - } + }; const expected = { changes: 1, lastInsertRowid: undefined, @@ -921,7 +921,7 @@ describe('DatabaseSQLite', function () { const dbResult1 = { changes: 0, lastInsertRowid: undefined, - } + }; sinon.stub(db.statement.topicAttempts, 'get').returns(dbGet); sinon.stub(db.statement.topicAttemptsIncrement, 'run').returns(dbResult0); sinon.stub(db.statement.topicContentFetchDone, 'run').returns(dbResult1); @@ -941,7 +941,7 @@ describe('DatabaseSQLite', function () { const dbResult1 = { changes: 0, lastInsertRowid: undefined, - } + }; sinon.stub(db.statement.topicAttempts, 'get').returns(dbGet); sinon.stub(db.statement.topicAttemptsIncrement, 'run').returns(dbResult0); sinon.stub(db.statement.topicContentFetchDone, 'run').returns(dbResult1); @@ -1534,7 +1534,7 @@ describe('DatabaseSQLite', function () { DB._verificationDataToEngine(data); assert.strictEqual(data.isPublisherValidated, 0); }); - }) // _verificationDataToEngine + }); // _verificationDataToEngine describe('verificationInsert', function () { let verification; @@ -1625,7 +1625,7 @@ describe('DatabaseSQLite', function () { const dbResult = { changes: 0, lastInsertRowid: undefined, - } + }; sinon.stub(db.statement.verificationUpdate, 'run').returns(dbResult); try { await db.verificationUpdate(dbCtx, verificationId, data); @@ -1650,7 +1650,7 @@ describe('DatabaseSQLite', function () { const dbResult = { changes: 1, lastInsertRowid: undefined, - } + }; sinon.stub(db.statement.verificationValidate, 'run').returns(dbResult); await db.verificationValidated(dbCtx, verificationId); }); @@ -1658,7 +1658,7 @@ describe('DatabaseSQLite', function () { const dbResult = { changes: 0, lastInsertRowid: undefined, - } + }; sinon.stub(db.statement.verificationValidate, 'run').returns(dbResult); try { await db.verificationValidated(dbCtx, verificationId); diff --git a/test/src/manager.js b/test/src/manager.js index 9d8c380..d3ddfb7 100644 --- a/test/src/manager.js +++ b/test/src/manager.js @@ -398,7 +398,7 @@ describe('Manager', function () { describe('_getRootData', function () { it('extracts expected values', function () { req.getHeader.returns('user@example.com'); - ctx = Object.assign({}, testData.validSubscribeCtx) + ctx = Object.assign({}, testData.validSubscribeCtx); const result = Manager._getRootData(req, ctx); assert.deepStrictEqual(result, testData.validRootData); }); @@ -791,7 +791,7 @@ describe('Manager', function () { assert(manager.db.topicFetchRequested.called); assert.strictEqual(res.statusCode, 202); assert(res.end.called); - assert(manager.communication.topicFetchClaimAndProcessById.called) + assert(manager.communication.topicFetchClaimAndProcessById.called); }); it('covers no immediate processing', async function() { manager.options.manager.processImmediately = false; @@ -803,7 +803,7 @@ describe('Manager', function () { assert(manager.db.topicFetchRequested.called); assert.strictEqual(res.statusCode, 202); assert(res.end.called); - assert(!manager.communication.topicFetchClaimAndProcessById.called) + assert(!manager.communication.topicFetchClaimAndProcessById.called); }); }); // _publishRequest diff --git a/test/src/service.js b/test/src/service.js index 2de3b52..576859f 100644 --- a/test/src/service.js +++ b/test/src/service.js @@ -21,6 +21,7 @@ describe('Service', function () { asyncLocalStorage = new AsyncLocalStorage(); options = new Config('test'); service = new Service(stubLogger, stubDb, options, asyncLocalStorage); + stubLogger._reset(); sinon.stub(service.manager); sinon.stub(service.sessionManager); sinon.stub(service.authenticator); @@ -49,7 +50,7 @@ describe('Service', function () { }); describe('preHandler', function () { - it('logs requestId', async () => { + it('logs requestId', async function () { sinon.stub(service.__proto__.__proto__, 'preHandler').resolves(); await service.asyncLocalStorage.run({}, async () => { await service.preHandler(req, res, ctx); @@ -57,6 +58,12 @@ describe('Service', function () { assert('requestId' in logObject); }); }); + it('covers weird async context failure', async function () { + sinon.stub(service.__proto__.__proto__, 'preHandler').resolves(); + sinon.stub(service.asyncLocalStorage, 'getStore').returns(); + await service.preHandler(req, res, ctx); + assert(service.logger.debug.called); + }); }); // preHandler describe('maybeIngestBody', function () { @@ -197,7 +204,7 @@ describe('Service', function () { await service.handlerGetAdminLogout(req, res, ctx); assert(service.sessionManager.getAdminLogout.called); }); -}); // handlerGetAdminLogout + }); // handlerGetAdminLogout describe('handlerGetAdminIA', function () { it('covers', async function () { diff --git a/test/src/template/badge-svg.js b/test/src/template/badge-svg.js index 1f4e026..8d7b66b 100644 --- a/test/src/template/badge-svg.js +++ b/test/src/template/badge-svg.js @@ -3,7 +3,6 @@ const assert = require('assert'); const template = require('../../../src/template/badge-svg'); -const Config = require('../../../config'); describe('Badge SVG Template', function () { let ctx, label, message, accessibleText;