From c5032a3d6e8b0bd1c532e2c8f90a2c070ebab57f Mon Sep 17 00:00:00 2001 From: Zaven Arra Date: Thu, 10 Mar 2022 16:38:30 -0800 Subject: [PATCH] fix: linting --- __tests__/seed-example.js | 93 ---------------------------- __tests__/seed-spec-example.spec.js | 94 ----------------------------- __tests__/serverTest-example.js | 20 ------ __tests__/supertest-example.spec.js | 36 ----------- database/etl/migrate.js | 14 ++--- server/app.js | 3 - 6 files changed, 7 insertions(+), 253 deletions(-) delete mode 100644 __tests__/seed-example.js delete mode 100644 __tests__/seed-spec-example.spec.js delete mode 100644 __tests__/serverTest-example.js delete mode 100644 __tests__/supertest-example.spec.js diff --git a/__tests__/seed-example.js b/__tests__/seed-example.js deleted file mode 100644 index cb2190a..0000000 --- a/__tests__/seed-example.js +++ /dev/null @@ -1,93 +0,0 @@ -/* - * seed data to DB for testing - */ -const uuid = require('uuid'); -const log = require('loglevel'); -const knex = require('knex')({ - client: 'pg', - // debug: true, - connection: require('../config/config').connectionString, -}); - -// Example of a database seed using knex -// This follows from the wallet microservice -// New mircroservices will need their own seed story - -const capture = { - id: 999999, -}; - -// const captureB = { -// id: 999998, -// }; - -const token = { - id: 9, - uuid: uuid.v4(), -}; - -const wallet = { - id: 12, - name: 'wallet', - password: 'test1234', - passwordHash: - '31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1', - salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde', - type: 'p', -}; - -// const storyOfThisSeed = ` -// a capture: #${capture.id} - -// a token: #${token.id} -// capture: #${capture.id} -// wallet: #${wallet.id} -// uuid: ${token.uuid} - -// wallet #${wallet.id} connected to capture #${capture.id}, get a token #${token.id} - -// Another capture: #${captureB.id} - -// `; -// console.debug( -// '--------------------------story of database ----------------------------------', -// storyOfThisSeed, -// '-----------------------------------------------------------------------------', -// ); - -async function seed() { - log.debug('seed api key'); - - // wallet - await knex('wallet').insert({ - id: wallet.id, - type: wallet.type, - name: wallet.name, - password: wallet.passwordHash, - salt: wallet.salt, - }); - - // token - log.log('seed token'); - await knex('token').insert({ - id: token.id, - capture_id: capture.id, - entity_id: wallet.id, - uuid: token.uuid, - }); - - // await knex('token').insert(tokenB); -} - -async function clear() { - log.debug('clear tables'); - await knex('token').del(); - await knex('wallet').del(); -} - -module.exports = { - seed, - clear, - wallet, - token, -}; diff --git a/__tests__/seed-spec-example.spec.js b/__tests__/seed-spec-example.spec.js deleted file mode 100644 index cad3260..0000000 --- a/__tests__/seed-spec-example.spec.js +++ /dev/null @@ -1,94 +0,0 @@ -/* - * seed data to DB for testing - */ -const uuid = require('uuid'); -const log = require('loglevel'); -const knex = require('knex')({ - client: 'pg', - // debug: true, - connection: require('../config/config').connectionString, -}); - -// Example of a database seed using knex -// This follows from the wallet microservice -// New mircroservices will need their own seed story - -const capture = { - id: 999999, -}; - -// const captureB = { -// id: 999998, -// }; - -const token = { - id: 9, - uuid: uuid.v4(), -}; - -const wallet = { - id: 12, - name: 'wallet', - password: 'test1234', - passwordHash: - '31dd4fe716e1a908f0e9612c1a0e92bfdd9f66e75ae12244b4ee8309d5b869d435182f5848b67177aa17a05f9306e23c10ba41675933e2cb20c66f1b009570c1', - salt: 'TnDe2LDPS7VaPD9GQWL3fhG4jk194nde', - type: 'p', -}; - -// const storyOfThisSeed = ` -// a capture: #${capture.id} - -// a token: #${token.id} -// capture: #${capture.id} -// wallet: #${wallet.id} -// uuid: ${token.uuid} - -// wallet #${wallet.id} connected to capture #${capture.id}, get a token #${token.id} - -// Another capture: #${captureB.id} - -// `; -// console.debug( -// '--------------------------story of database ----------------------------------', -// storyOfThisSeed, -// '-----------------------------------------------------------------------------', -// ); - -async function seed() { - log.debug('seed api key'); - - // wallet - await knex('wallet').insert({ - id: wallet.id, - type: wallet.type, - name: wallet.name, - password: wallet.passwordHash, - salt: wallet.salt, - }); - - // token - log.log('seed token'); - await knex('token').insert({ - id: token.id, - capture_id: capture.id, - entity_id: wallet.id, - uuid: token.uuid, - }); - - // await knex('token') - // .insert(tokenB); -} - -async function clear() { - log.debug('clear tables'); - await knex('token').del(); - await knex('wallet').del(); -} - -module.exports = { - seed, - clear, - wallet, - token, -}; diff --git a/__tests__/serverTest-example.js b/__tests__/serverTest-example.js deleted file mode 100644 index 5ee23cd..0000000 --- a/__tests__/serverTest-example.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * A test server for testing, seed some initial data into the DB - */ -require('dotenv').config(); -const log = require('loglevel'); - -const app = require('../server/app'); - -const port = process.env.NODE_PORT || 3006; -const seed = require('./seed-example'); -// set the log level -require('../server/setup'); - -app.listen(port, async () => { - log.info(`listening on port:${port}`); - log.info('Seed data'); - log.debug('debug log level!'); - await seed.clear(); - await seed.seed(); -}); diff --git a/__tests__/supertest-example.spec.js b/__tests__/supertest-example.spec.js deleted file mode 100644 index fe5cd57..0000000 --- a/__tests__/supertest-example.spec.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The integration test to test the whole microservice, with DB - */ -require('dotenv').config(); -const request = require('supertest'); -const { expect } = require('chai'); -const sinon = require('sinon'); -const seed = require('./seed-example'); -const server = require('../server/app'); - -describe('microservice integration tests', () => { - beforeEach(async () => { - // In case other sinon stub would affect me - sinon.restore(); - // before all, seed data to DB - await seed.clear(); - await seed.seed(); - - // do any other setup here - // including authorize to the service if required - }); - - afterEach((done) => { - // after finished all the test, clear data from DB - seed.clear().then(() => { - done(); - }); - }); - - describe('Does something', () => { - it(`Should do something and not fail`, async () => { - const res = await request(server).get(`/path`); - expect(res).to.have.property('statusCode', 200); - }); - }); -}); diff --git a/database/etl/migrate.js b/database/etl/migrate.js index 3fbf1c6..306e91a 100644 --- a/database/etl/migrate.js +++ b/database/etl/migrate.js @@ -1,13 +1,13 @@ require('dotenv').config({ path: `../../.env.${process.env.NODE_ENV}` }); -const generate_uuid_v4 = require("uuid").v4; +const log = require('loglevel'); const knex = require('../../server/database/knex'); async function migrate() { - thx = await knex.transaction(); + const thx = await knex.transaction(); const entities = await thx.table('entity').select('*') - let entityIdLookup = {} + const entityIdLookup = {} entities.forEach( (stakeholderRow) => { entityIdLookup[stakeholderRow.id] = stakeholderRow.stakeholder_uuid; }) @@ -16,19 +16,19 @@ async function migrate() { const exists = await thx.table('stakeholder.stakeholder').where('id', '=', stakeholderRow.stakeholder_uuid); if(exists.length > 0){ - console.log('stakeholder already exists') + log.warn('stakeholder already exists') return; } let type = 'Person'; - if(stakeholderRow.type == 'o' || stakeholderRow.type == 'O'){ + if(stakeholderRow.type === 'o' || stakeholderRow.type === 'O'){ type = 'Organization'; } const stakeholder = { id: stakeholderRow.stakeholder_uuid, - type: type, + type, org_name: stakeholderRow.org_name, first_name: stakeholderRow.first_name, last_name: stakeholderRow.last_name, @@ -51,7 +51,7 @@ async function migrate() { await thx.table('stakeholder.stakeholder_relation').insert(relation); })) })) - console.log('DONE'); + log.info('DONE'); thx.commit(); } diff --git a/server/app.js b/server/app.js index b44d57b..7d4cda6 100644 --- a/server/app.js +++ b/server/app.js @@ -1,9 +1,7 @@ const express = require('express'); -const Sentry = require('@sentry/node'); const cors = require('cors'); const log = require('loglevel'); const HttpError = require('./utils/HttpError'); -const { sentryDSN } = require('../config/config'); const { handlerWrapper, errorHandler } = require('./utils/utils'); const router = require('./routes'); @@ -14,7 +12,6 @@ if (process.env.NODE_ENV === 'development') { app.use(cors()); } -Sentry.init({ dsn: sentryDSN }); /* * Check request