Skip to content

Commit

Permalink
chore: code changes for docs query and red meat waste (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
mishraomp authored Nov 25, 2024
1 parent b8f1dc8 commit c34615a
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 236 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ test-report.xml
**/out
**/target

*.key
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.18.1-bullseye-slim AS build
FROM node:22-bullseye-slim AS build

# Install packages, build and keep only prod packages
WORKDIR /app
Expand All @@ -11,7 +11,7 @@ RUN npm run build

# Deploy container
# Distroless has node, but not npm
FROM gcr.io/distroless/nodejs20-debian11:nonroot
FROM gcr.io/distroless/nodejs22-debian12:nonroot
ENV NODE_ENV=production

# Copy over app
Expand Down
240 changes: 125 additions & 115 deletions backend/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
import { Test, TestingModule } from '@nestjs/testing'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { ObjectStoreService } from './v1/object-store/object.store.service'
import { AmsOracleConnectorService } from './v1/ams-oracle-connector/ams.oracle.connector.service'
import { HttpModule } from '@nestjs/axios'
import { OmrrResponse } from './v1/types/omrr-response'
import { OmrrApplicationStatusResponse } from './v1/types/omrr-application-status'
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ObjectStoreService } from './v1/object-store/object.store.service';
import { AmsOracleConnectorService } from './v1/ams-oracle-connector/ams.oracle.connector.service';
import { HttpModule } from '@nestjs/axios';
import { OmrrResponse } from './v1/types/omrr-response';
import { OmrrApplicationStatusResponse } from './v1/types/omrr-application-status';

describe('AppController', () => {
let appController: AppController
let amsConnectorService: AmsOracleConnectorService
let appController: AppController;
let amsConnectorService: AmsOracleConnectorService;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
imports: [HttpModule],
controllers: [AppController],
providers: [AppService, ObjectStoreService, AmsOracleConnectorService],
}).compile()
amsConnectorService = await app.resolve<AmsOracleConnectorService>(AmsOracleConnectorService)
appController = app.get<AppController>(AppController)
})
}).compile();
amsConnectorService = await app.resolve<AmsOracleConnectorService>(
AmsOracleConnectorService,
);
appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello Backend!"', () => {
expect(appController.getHello()).toBe('Hello Backend!')
})
})
expect(appController.getHello()).toBe('Hello Backend!');
});
});
describe('getAllOmrrRecords', () => {
it('should return an object', async () => {
//mock the AMSOracleConnectorService call
jest.spyOn(amsConnectorService, 'getLatestOmrrDataFromCache').mockImplementation(async () => {
const res: OmrrResponse = {
lastModified: new Date().toISOString(),
omrrData: [
{
'Manure': false,
'Untreated and Unprocessed Wood Residuals': false,
'Domestic Septic Tank Sludge': false,
'Operation Type': null,
'Latitude': 49.028961,
'Yard Waste': false,
'Fish Wastes': false,
'Whey': false,
'Animal Bedding': false,
'Biosolids': false,
'Hatchery Waste': false,
'Last Amendment Date': new Date(),
'Intended Dates of Land Application': null,
'Authorization Status': 'Inactive',
'Authorization Number': 11123,
'Waste Discharge Regulation': null,
'Milk Processing Waste': false,
'Material Land Applied': null,
'Poultry Carcasses': false,
'Authorization Type': 'Notification',
'Effective/Issue Date': new Date(),
'Longitude': -123.805217,
'Facility Location': 'LOT 10, OYSTER DISTRICT',
'Type of Compost Produced': null,
'Facility Design Capacity (t/y)': null,
'Brewery Waste/Wine Waste': false,
'Regulated Party': 'WYNDLOW WOOD WASTE REDUCTION INC.',
'Food Waste': false,
},

],
}
return res
})
const result = await appController.getAllOmrrRecords()
expect(result).toBeTruthy()
expect(result.omrrData).toHaveLength(1)

})


})
jest
.spyOn(amsConnectorService, 'getLatestOmrrDataFromCache')
.mockImplementation(async () => {
const res: OmrrResponse = {
lastModified: new Date().toISOString(),
omrrData: [
{
Manure: false,
'Untreated and Unprocessed Wood Residuals': false,
'Domestic Septic Tank Sludge': false,
'Operation Type': null,
Latitude: 49.028961,
'Yard Waste': false,
'Fish Wastes': false,
Whey: false,
'Animal Bedding': false,
Biosolids: false,
'Hatchery Waste': false,
'Last Amendment Date': new Date(),
'Intended Dates of Land Application': null,
'Authorization Status': 'Inactive',
'Authorization Number': 11123,
'Waste Discharge Regulation': null,
'Milk Processing Waste': false,
'Material Land Applied': null,
'Poultry Carcasses': false,
'Authorization Type': 'Notification',
'Effective/Issue Date': new Date(),
Longitude: -123.805217,
'Facility Location': 'LOT 10, OYSTER DISTRICT',
'Type of Compost Produced': null,
'Facility Design Capacity (t/y)': null,
'Brewery Waste/Wine Waste': false,
'Regulated Party': 'WYNDLOW WOOD WASTE REDUCTION INC.',
'Food Waste': false,
},
],
};
return res;
});
const result = await appController.getAllOmrrRecords();
expect(result).toBeTruthy();
expect(result.omrrData).toHaveLength(1);
});
});
describe('getOmrrApplicationStatus', () => {
it('should return an array', async () => {
const result: OmrrApplicationStatusResponse[] = [
Expand All @@ -84,72 +84,82 @@ describe('AppController', () => {
'Job Tracking Number': 386999,
'Job Type': 'Authorization Amendment',
'Authorization Type': 'Permit',
'Status': 'In Review',
Status: 'In Review',
'Received Date': '2019-09-27',
},
{
'Authorization Number': 108531,
'Job Tracking Number': 384058,
'Job Type': 'Authorization Amendment',
'Authorization Type': 'Operational Certificate',
'Status': 'In Review',
Status: 'In Review',
'Received Date': '2019-05-23',
},
{
'Authorization Number': 108536,
'Job Tracking Number': 433877,
'Job Type': 'Authorization Amendment',
'Authorization Type': 'Permit',
'Status': 'Pending Final Application',
Status: 'Pending Final Application',
'Received Date': '2024-03-07',
},

]
jest.spyOn(amsConnectorService, 'getLatestOmrrApplicationStatusFromCache').mockImplementation(async () => {
return result
})
const omrrApplicationStatus = await appController.getOmrrApplicationStatus()
expect(omrrApplicationStatus).toBeTruthy()
expect(omrrApplicationStatus).toHaveLength(3)

})

})
];
jest
.spyOn(amsConnectorService, 'getLatestOmrrApplicationStatusFromCache')
.mockImplementation(async () => {
return result;
});
const omrrApplicationStatus =
await appController.getOmrrApplicationStatus();
expect(omrrApplicationStatus).toBeTruthy();
expect(omrrApplicationStatus).toHaveLength(3);
});
});
describe('getOmrrAuthorizationDocuments', () => {
it('should return an object', async () => {
jest.spyOn(amsConnectorService, 'getLatestOmrrAuthzDocsFromCache').mockImplementation(async () => {
return [
{
'Authorization Number': 108485,
'doc_links': [{
'DocumentObjectID': 123,
'Description': 'desc',
'Publiclyviewable': 'Y',
}],

},
{
'Authorization Number': 108486,
'doc_links': [{
'DocumentObjectID': 124,
'Description': 'desc',
'Publiclyviewable': 'Y',
}],
},
{
'Authorization Number': 108487,
'doc_links': [{
'DocumentObjectID': 125,
'Description': 'desc',
'Publiclyviewable': 'Y',
}],
},
]
})
const omrrAuthorizationDocuments = await appController.getOmrrAuthorizationDocs()
expect(omrrAuthorizationDocuments).toBeTruthy()
expect(omrrAuthorizationDocuments).toHaveLength(3)
})

})
})
jest
.spyOn(amsConnectorService, 'getLatestOmrrAuthzDocsFromCache')
.mockImplementation(async () => {
return [
{
'Authorization Number': 108485,
doc_links: [
{
DocumentObjectID: 123,
Description: 'desc',
Publiclyviewable: 'Y',
Filename: 'file1.pdf',
},
],
},
{
'Authorization Number': 108486,
doc_links: [
{
DocumentObjectID: 124,
Description: 'desc',
Publiclyviewable: 'Y',
Filename: 'file2.pdf',
},
],
},
{
'Authorization Number': 108487,
doc_links: [
{
DocumentObjectID: 125,
Description: 'desc',
Publiclyviewable: 'Y',
Filename: 'file3.pdf',
},
],
},
];
});
const omrrAuthorizationDocuments =
await appController.getOmrrAuthorizationDocs();
expect(omrrAuthorizationDocuments).toBeTruthy();
expect(omrrAuthorizationDocuments).toHaveLength(3);
});
});
});
1 change: 1 addition & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const logger = new Logger('NestApplication');
bootstrap().then(async (app: NestExpressApplication) => {
await app.listen(3000);
logger.log(`Listening on ${await app.getUrl()}`);
logger.log(`Process start up took ${process.uptime()} seconds`);
}).catch(err => {
logger.error(err);
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { AmsOracleConnectorService } from './ams.oracle.connector.service';
import { HttpService } from '@nestjs/axios';
import { OmrrData } from '../types/omrr-data';
import { OmrrApplicationStatusResponse } from '../types/omrr-application-status';
import { OmrrAuthzDocsQueryResponse } from '../types/omrr-authz-docs-response'
import * as process from 'node:process'
import { OmrrAuthzDocsQueryResponse } from '../types/omrr-authz-docs-response';
import * as process from 'node:process';

describe('AmsOracleConnectorService', () => {
let service: AmsOracleConnectorService;
Expand All @@ -30,7 +30,6 @@ describe('AmsOracleConnectorService', () => {

service = module.get<AmsOracleConnectorService>(AmsOracleConnectorService);
httpService = module.get<HttpService>(HttpService);

});

afterEach(() => {
Expand All @@ -50,7 +49,9 @@ describe('AmsOracleConnectorService', () => {
const getOMRRApplicationStatusFromAMS = jest
.spyOn(service, 'getOMRRApplicationStatusFromAMS')
.mockResolvedValue(undefined);
const getAuthzDocsFromAMS = jest.spyOn(service, 'getOMRRAuthorizationDocumentsFromAMS').mockResolvedValue(undefined);
const getAuthzDocsFromAMS = jest
.spyOn(service, 'getOMRRAuthorizationDocumentsFromAMS')
.mockResolvedValue(undefined);
await service.onModuleInit();

expect(getOMRRDataFromAMS).toHaveBeenCalled();
Expand Down Expand Up @@ -168,12 +169,14 @@ describe('AmsOracleConnectorService', () => {
DocumentObjectID: 124,
Description: 'desc',
Publiclyviewable: 'Y',
Filename: 'file1.pdf',
},
{
'Authorization Number': 123,
DocumentObjectID: 125,
Description: 'desc',
Publiclyviewable: 'Y',
Filename: 'file2.pdf',
},
]; // Mocked OMRR authorization documents
const response = {
Expand All @@ -184,8 +187,8 @@ describe('AmsOracleConnectorService', () => {

const result = await service.getOMRRAuthorizationDocumentsFromAMS();

expect(result).toHaveLength(1)
expect(result[0].doc_links).toHaveLength(2)
expect(result).toHaveLength(1);
expect(result[0].doc_links).toHaveLength(2);
});

it('should throw error if status is not 200', async () => {
Expand All @@ -194,20 +197,23 @@ describe('AmsOracleConnectorService', () => {
data: undefined,
};
jest.spyOn(httpService.axiosRef, 'post').mockResolvedValue(response);
const error = new Error('Error Getting OMRR Authorization Documents from AMS');
const error = new Error(
'Error Getting OMRR Authorization Documents from AMS',
);
await expect(
service.getOMRRAuthorizationDocumentsFromAMS(),
).rejects.toThrow(error);
});

it('should throw an error if there is an error getting OMRR authorization documents from AMS', async () => {
const error = new Error('Error Getting OMRR Authorization Documents from AMS');
const error = new Error(
'Error Getting OMRR Authorization Documents from AMS',
);
jest.spyOn(httpService.axiosRef, 'post').mockRejectedValue(error);

await expect(
service.getOMRRAuthorizationDocumentsFromAMS(),
).rejects.toThrow(error);
});
});

});
Loading

0 comments on commit c34615a

Please sign in to comment.