Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move db-export services to data folder #299

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions app/controllers/data/data.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

const Boom = require('@hapi/boom')

const DbExportService = require('../../services/db-export/db-export.service.js')
const ExportService = require('../../services/data/export/export.service.js')
const SeedService = require('../../services/data/seed/seed.service.js')
const TearDownService = require('../../services/data/tear-down/tear-down.service.js')

/**
* Triggers export of all relevant tables to CSV and then uploads them to S3
*
* > Has to be called something other than 'export' because export is a reserved word
*/
async function dbExport (_request, h) {
DbExportService.go()
async function exportDb (_request, h) {
ExportService.go()

return h.response().code(204)
}
Expand All @@ -41,7 +43,7 @@ async function tearDown (_request, h) {
}

module.exports = {
dbExport,
exportDb,
seed,
tearDown
}
4 changes: 2 additions & 2 deletions app/routes/data.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const DataController = require('../controllers/data/data.controller.js')
const routes = [
{
method: 'GET',
path: '/data/db-export',
handler: DataController.dbExport,
path: '/data/export',
handler: DataController.exportDb,
options: {
description: 'Used to export the database and upload the file to our AWS S3 bucket',
app: { excludeFromProd: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module DbExportService
*/

const SchemaExportService = require('../db-export/schema-export.service.js')
const SchemaExportService = require('./schema-export.service.js')

/**
* Calls SchemaExportService giving it a schemaName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module FetchTableNamesService
*/

const { db } = require('../../../db/db.js')
const { db } = require('../../../../db/db.js')

/**
* Retrieves the table names for a specific schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module FetchTableService
*/

const { db } = require('../../../db/db.js')
const { db } = require('../../../../db/db.js')

/**
* Retrieves headers, rows and the table name from the table in the db, and returns them as an object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const fsPromises = require('fs').promises
const path = require('path')
const { PutObjectCommand, S3Client } = require('@aws-sdk/client-s3')

const S3Config = require('../../../config/s3.config.js')
const S3Config = require('../../../../config/s3.config.js')

/**
* Sends a file to our AWS S3 Bucket using the filePath that it receives
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/data/data.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const DbExportService = require('../../../app/services/db-export/db-export.service')
const ExportService = require('../../../app/services/data/export/export.service')
const SeedService = require('../../../app/services/data/seed/seed.service.js')
const TearDownService = require('../../../app/services/data/tear-down/tear-down.service.js')

Expand All @@ -35,15 +35,15 @@ describe('Data controller', () => {
Sinon.restore()
})

describe('GET /data/db-export', () => {
describe('GET /data/export', () => {
const options = {
method: 'GET',
url: '/data/db-export'
url: '/data/export'
}

describe('when the request succeeds', () => {
beforeEach(async () => {
Sinon.stub(DbExportService, 'go').resolves()
Sinon.stub(ExportService, 'go').resolves()
})

it('displays the correct message', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { expect } = Code
const tar = require('tar')

// Thing under test
const CompressSchemaFolderService = require('../../../app/services/db-export/compress-schema-folder.service.js')
const CompressSchemaFolderService = require('../../../../app/services/data/export/compress-schema-folder.service.js')

describe('Compress schema folder service', () => {
let tarCreateStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { describe, it } = exports.lab = Lab.script()
const { expect } = Code

// Thing under test
const ConvertToCSVService = require('../../../app/services/db-export/convert-to-csv.service.js')
const ConvertToCSVService = require('../../../../app/services/data/export/convert-to-csv.service.js')

/**
* billingChargeCategoriesTable has all data types we are testing for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const path = require('path')
const mockFs = require('mock-fs')

// Thing under test
const DeleteFilesService = require('../../../app/services/db-export/delete-files.service.js')
const DeleteFilesService = require('../../../../app/services/data/export/delete-files.service.js')

describe('Delete Files service', () => {
let filenameWithPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('fs')
const path = require('path')

// Thing under test
const ExportDataFilesService = require('../../../app/services/db-export/export-data-files.service.js')
const ExportDataFilesService = require('../../../../app/services/data/export/export-data-files.service.js')

const csvHeader = [
'"billingChargeCategoryId"',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const ConvertToCSVService = require('../../../app/services/db-export/convert-to-csv.service.js')
const ExportDataFilesService = require('../../../app/services/db-export/export-data-files.service.js')
const FetchTableService = require('../../../app/services/db-export/fetch-table.service.js')
const ConvertToCSVService = require('../../../../app/services/data/export/convert-to-csv.service.js')
const ExportDataFilesService = require('../../../../app/services/data/export/export-data-files.service.js')
const FetchTableService = require('../../../../app/services/data/export/fetch-table.service.js')

// Thing under test
const ExportTableService = require('../../../app/services/db-export/export-table.service.js')
const ExportTableService = require('../../../../app/services/data/export/export-table.service.js')

describe('Table Export service', () => {
let convertToCSVServiceStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const SchemaExportService = require('../../../app/services/db-export/schema-export.service.js')
const SchemaExportService = require('../../../../app/services/data/export/schema-export.service.js')

// Thing under test
const DbExportService = require('../../../app/services/db-export/db-export.service.js')
const ExportService = require('../../../../app/services/data/export/export.service.js')

describe('Db Export Service', () => {
describe('Export Service', () => {
let SchemaExportServiceStub
let notifierStub

Expand All @@ -32,7 +32,7 @@ describe('Db Export Service', () => {
it('calls the SchemaExportService with the different schema names', async () => {
const schemaNames = ['water', 'returns', 'crm', 'crm_v2', 'idm', 'permit']

await DbExportService.go()
await ExportService.go()

const allArgs = SchemaExportServiceStub.getCalls().flatMap((call) => {
return call.args
Expand All @@ -42,7 +42,7 @@ describe('Db Export Service', () => {
})

it('logs the time taken to export the db', async () => {
await DbExportService.go()
await ExportService.go()

const args = notifierStub.omg.firstCall.args

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { describe, it } = exports.lab = Lab.script()
const { expect } = Code

// Thing under test
const FetchTableNamesService = require('../../../app/services/db-export/fetch-table-names.service')
const FetchTableNamesService = require('../../../../app/services/data/export/fetch-table-names.service')

describe('Fetch table names', () => {
describe('when given a schema name', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const BillingChargeCategoryHelper = require('../../support/helpers/water/billing-charge-category.helper.js')
const DatabaseHelper = require('../../support/helpers/database.helper.js')
const BillingChargeCategoryHelper = require('../../../support/helpers/water/billing-charge-category.helper.js')
const DatabaseHelper = require('../../../support/helpers/database.helper.js')

// Thing under test
const FetchTableService = require('../../../app/services/db-export/fetch-table.service.js')
const FetchTableService = require('../../../../app/services/data/export/fetch-table.service.js')

const billingChargeCategoriesColumnInfo = [
'billingChargeCategoryId',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const CompressSchemaFolderService = require('../../../app/services/db-export/compress-schema-folder.service.js')
const DeleteFilesService = require('../../../app/services/db-export/delete-files.service.js')
const ExportTableService = require('../../../app/services/db-export/export-table.service.js')
const FetchTableNamesService = require('../../../app/services/db-export/fetch-table-names.service.js')
const SendToS3BucketService = require('../../../app/services/db-export/send-to-s3-bucket.service.js')
const CompressSchemaFolderService = require('../../../../app/services/data/export/compress-schema-folder.service.js')
const DeleteFilesService = require('../../../../app/services/data/export/delete-files.service.js')
const ExportTableService = require('../../../../app/services/data/export/export-table.service.js')
const FetchTableNamesService = require('../../../../app/services/data/export/fetch-table-names.service.js')
const SendToS3BucketService = require('../../../../app/services/data/export/send-to-s3-bucket.service.js')

// Thing under test
const SchemaExportService = require('../../../app/services/db-export/schema-export.service.js')
const SchemaExportService = require('../../../../app/services/data/export/schema-export.service.js')

describe('Schema export service', () => {
let FetchTableNamesServiceStub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { expect } = Code
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3')

// Thing under test
const SendToS3BucketService = require('../../../app/services/db-export/send-to-s3-bucket.service.js')
const SendToS3BucketService = require('../../../../app/services/data/export/send-to-s3-bucket.service.js')

describe('Send to S3 bucket service', () => {
let s3Stub
Expand Down