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 jobs to an explicit /jobs endpoint #607

Merged
merged 8 commits into from
Dec 19, 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
18 changes: 0 additions & 18 deletions app/controllers/charge-elements.controller.js

This file was deleted.

13 changes: 0 additions & 13 deletions app/controllers/data.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@
* @module DataController
*/

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 exportDb (_request, h) {
ExportService.go()

return h.response().code(204)
}

async function seed (_request, h) {
await SeedService.go()

Expand All @@ -33,7 +21,6 @@ async function tearDown (_request, h) {
}

module.exports = {
exportDb,
seed,
tearDown
}
31 changes: 31 additions & 0 deletions app/controllers/jobs.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

/**
* Controller for /jobs endpoints
* @module JobsController
*/

const ExportService = require('../services/jobs/export/export.service.js')
const ProcessTimeLimitedLicencesService = require('../services/jobs/time-limited/process-time-limited-licences.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 exportDb (_request, h) {
ExportService.go()

return h.response().code(204)
}

async function timeLimited (_request, h) {
ProcessTimeLimitedLicencesService.go()

return h.response().code(204)
}

module.exports = {
exportDb,
timeLimited
}
4 changes: 2 additions & 2 deletions app/plugins/router.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const BillLicences = require('../routes/bill-licences.routes.js')
const BillRoutes = require('../routes/bills.routes.js')
const BillRunRoutes = require('../routes/bill-runs.routes.js')
const BillingAccountRoutes = require('../routes/billing-accounts.routes.js')
const ChargeElements = require('../routes/charge-elements.routes.js')
const CheckRoutes = require('../routes/check.routes.js')
const DataRoutes = require('../routes/data.routes.js')
const FilterRoutesService = require('../services/plugins/filter-routes.service.js')
const HealthRoutes = require('../routes/health.routes.js')
const JobRoutes = require('../routes/jobs.routes.js')
const LicenceRoutes = require('../routes/licence.routes.js')
const RootRoutes = require('../routes/root.routes.js')

Expand All @@ -34,8 +34,8 @@ const routes = [
...BillRoutes,
...BillRunRoutes,
...BillingAccountRoutes,
...ChargeElements,
...LicenceRoutes,
...JobRoutes,
...CheckRoutes,
...DataRoutes
]
Expand Down
20 changes: 0 additions & 20 deletions app/routes/charge-elements.routes.js

This file was deleted.

13 changes: 0 additions & 13 deletions app/routes/data.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,6 @@
const DataController = require('../controllers/data.controller.js')

const routes = [
{
method: 'GET',
path: '/data/export',
handler: DataController.exportDb,
options: {
app: {
excludeFromProd: true,
plainOutput: true
},
auth: false,
description: 'Used to export the database and upload the file to our AWS S3 bucket'
}
},
{
method: 'POST',
path: '/data/seed',
Expand Down
32 changes: 32 additions & 0 deletions app/routes/jobs.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

const JobsController = require('../controllers/jobs.controller.js')

const routes = [
{
method: 'GET',
path: '/jobs/export',
handler: JobsController.exportDb,
options: {
app: {
plainOutput: true
},
auth: false,
description: 'Used to export the database and upload the file to our AWS S3 bucket'
}
},
{
method: 'POST',
path: '/jobs/time-limited',
handler: JobsController.timeLimited,
options: {
app: {
plainOutput: true
},
auth: false,
description: 'Puts a licence into workflow when a charge element has a `timeLimitedEndDate` which is < 50 days away'
}
}
]

module.exports = routes
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @module FetchTimeLimitedLicencesService
*/

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

/**
* Fetch licences that have a related `purpose` that is due to expire in less than 50 days
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

const FetchTimeLimitedLicencesService = require('./fetch-time-limited-licences.service.js')
const { timestampForPostgres } = require('../../lib/general.lib.js')
const Workflow = require('../../models/workflow.model.js')
const { timestampForPostgres } = require('../../../lib/general.lib.js')
const Workflow = require('../../../models/workflow.model.js')

/**
* Puts SROC licences into workflow that have a related `purpose` that is due to expire in less than 50 days
Expand Down
20 changes: 0 additions & 20 deletions test/controllers/data.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const ExportService = require('../../app/services/data/export/export.service.js')
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,25 +34,6 @@ describe('Data controller', () => {
Sinon.restore()
})

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

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

it('displays the correct message', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(204)
})
})
})

describe('POST /data/seed', () => {
const options = {
method: 'POST',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const ProcessTimeLimitedLicencesService = require('../../app/services/charge-elements/process-time-limited-licences.service.js')
const ExportService = require('../../app/services/jobs/export/export.service.js')
const ProcessTimeLimitedLicencesService = require('../../app/services/jobs/time-limited/process-time-limited-licences.service.js')

// For running our service
const { init } = require('../../app/server.js')

describe('Charge Elements controller', () => {
describe('Jobs controller', () => {
let server

beforeEach(async () => {
Expand All @@ -33,10 +34,29 @@ describe('Charge Elements controller', () => {
Sinon.restore()
})

describe('POST /charge-elements/time-limited', () => {
describe('GET /jobs/export', () => {
const options = {
method: 'GET',
url: '/jobs/export'
}

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

it('displays the correct message', async () => {
const response = await server.inject(options)

expect(response.statusCode).to.equal(204)
})
})
})

describe('POST /jobs/time-limited', () => {
const options = {
method: 'POST',
url: '/charge-elements/time-limited'
url: '/jobs/time-limited'
}

describe('when the request succeeds', () => {
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/data/export/compress-schema-folder.service.js')
const CompressSchemaFolderService = require('../../../../app/services/jobs/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/data/export/convert-to-csv.service.js')
const ConvertToCSVService = require('../../../../app/services/jobs/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 @@ -14,7 +14,7 @@ const path = require('path')
const mockFs = require('mock-fs')

// Thing under test
const DeleteFilesService = require('../../../../app/services/data/export/delete-files.service.js')
const DeleteFilesService = require('../../../../app/services/jobs/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 @@ -9,11 +9,11 @@ const { describe, it, beforeEach, afterEach } = exports.lab = Lab.script()
const { expect } = Code

// Things we need to stub
const FetchTableService = require('../../../../app/services/data/export/fetch-table.service.js')
const WriteTableToFileService = require('../../../../app/services/data/export/write-table-to-file.service.js')
const FetchTableService = require('../../../../app/services/jobs/export/fetch-table.service.js')
const WriteTableToFileService = require('../../../../app/services/jobs/export/write-table-to-file.service.js')

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

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

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

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

describe('Export Service', () => {
let SchemaExportServiceStub
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/data/export/fetch-table-names.service')
const FetchTableNamesService = require('../../../../app/services/jobs/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 @@ -12,7 +12,7 @@ const ChargeCategoryHelper = require('../../../support/helpers/charge-category.h
const DatabaseHelper = require('../../../support/helpers/database.helper.js')

// Thing under test
const FetchTableService = require('../../../../app/services/data/export/fetch-table.service.js')
const FetchTableService = require('../../../../app/services/jobs/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/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')
const CompressSchemaFolderService = require('../../../../app/services/jobs/export/compress-schema-folder.service.js')
const DeleteFilesService = require('../../../../app/services/jobs/export/delete-files.service.js')
const ExportTableService = require('../../../../app/services/jobs/export/export-table.service.js')
const FetchTableNamesService = require('../../../../app/services/jobs/export/fetch-table-names.service.js')
const SendToS3BucketService = require('../../../../app/services/jobs/export/send-to-s3-bucket.service.js')

// Thing under test
const SchemaExportService = require('../../../../app/services/data/export/schema-export.service.js')
const SchemaExportService = require('../../../../app/services/jobs/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/data/export/send-to-s3-bucket.service.js')
const SendToS3BucketService = require('../../../../app/services/jobs/export/send-to-s3-bucket.service.js')

describe('Send to S3 bucket service', () => {
let s3Stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const fs = require('fs')
const path = require('path')

// Thing under test
const WriteTableToFileService = require('../../../../app/services/data/export/write-table-to-file.service.js')
const WriteTableToFileService = require('../../../../app/services/jobs/export/write-table-to-file.service.js')

const tableName = 'billing_charge_categories'
const schemaName = 'water'
Expand Down
Loading
Loading