Skip to content

Commit

Permalink
feat(backend): Added new route for responding with Authz Documents. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mishraomp authored Jul 22, 2024
1 parent 6007c5c commit fc35e59
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 91 deletions.
209 changes: 123 additions & 86 deletions backend/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,118 +1,155 @@
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 { 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);
});
providers: [AppService, ObjectStoreService, AmsOracleConnectorService],
}).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
},
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);
],
}
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[] =[
const result: OmrrApplicationStatusResponse[] = [
{
"Authorization Number": 108485,
"Job Tracking Number": 386999,
"Job Type": "Authorization Amendment",
"Authorization Type": "Permit",
"Status": "In Review",
"Received Date": "2019-09-27"
'Authorization Number': 108485,
'Job Tracking Number': 386999,
'Job Type': 'Authorization Amendment',
'Authorization Type': 'Permit',
'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",
"Received Date": "2019-05-23"
'Authorization Number': 108531,
'Job Tracking Number': 384058,
'Job Type': 'Authorization Amendment',
'Authorization Type': 'Operational Certificate',
'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",
"Received Date": "2024-03-07"
'Authorization Number': 108536,
'Job Tracking Number': 433877,
'Job Type': 'Authorization Amendment',
'Authorization Type': 'Permit',
'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);
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)
})

})
})
5 changes: 5 additions & 0 deletions backend/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppService } from './app.service';
import { OmrrResponse } from './v1/types/omrr-response';
import { AmsOracleConnectorService } from './v1/ams-oracle-connector/ams.oracle.connector.service';
import { OmrrApplicationStatusResponse } from './v1/types/omrr-application-status'
import { OmrrAuthzDocsResponse } from './v1/types/omrr-authz-docs-response'

@Controller()
export class AppController {
Expand All @@ -23,4 +24,8 @@ export class AppController {
async getOmrrApplicationStatus(): Promise<OmrrApplicationStatusResponse[]> {
return this.amsOracleConnectorService.getLatestOmrrApplicationStatusFromCache();
}
@Get('/omrr/authorization-docs')
async getOmrrAuthorizationDocs(): Promise<OmrrAuthzDocsResponse[]> {
return this.amsOracleConnectorService.getLatestOmrrAuthzDocsFromCache();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ 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'

describe('AmsOracleConnectorService', () => {
let service: AmsOracleConnectorService;
let httpService: HttpService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
Expand All @@ -29,6 +30,7 @@ describe('AmsOracleConnectorService', () => {

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

});

afterEach(() => {
Expand All @@ -40,17 +42,19 @@ describe('AmsOracleConnectorService', () => {
});
describe('onModuleInit', () => {
it('should initialize AmsOracleConnectorService and call getOMRRDataFromAMS and getOMRRApplicationStatusFromAMS', async () => {
process.env.OMRR_AUTHZ_DOCS_FLAG = 'true';
const getOMRRDataFromAMS = jest
.spyOn(service, 'getOMRRDataFromAMS')
.mockResolvedValue(undefined);
const getOMRRApplicationStatusFromAMS = jest
.spyOn(service, 'getOMRRApplicationStatusFromAMS')
.mockResolvedValue(undefined);

const getAuthzDocsFromAMS = jest.spyOn(service, 'getOMRRAuthorizationDocumentsFromAMS').mockResolvedValue(undefined);
await service.onModuleInit();

expect(getOMRRDataFromAMS).toHaveBeenCalled();
expect(getOMRRApplicationStatusFromAMS).toHaveBeenCalled();
expect(getAuthzDocsFromAMS).toHaveBeenCalled();
});

it('should exit the process with code 128 if there is an error calling getOMRRDataFromAMS', async () => {
Expand Down Expand Up @@ -155,5 +159,54 @@ describe('AmsOracleConnectorService', () => {
});
});

describe('getOMRRAuthorizationDocumentsFromAMS', () => {
it('should get OMRR authorization documents from AMS', async () => {
const omrrAuthzDocs: OmrrAuthzDocsQueryResponse[] = [
{
'Authorization Number': 123,
DocumentObjectID: 124,
Description: 'desc',
Publiclyviewable: 'Y',
},
{
'Authorization Number': 123,
DocumentObjectID: 125,
Description: 'desc',
Publiclyviewable: 'Y',
},
]; // Mocked OMRR authorization documents
const response = {
status: 200,
data: omrrAuthzDocs,
};
jest.spyOn(httpService.axiosRef, 'post').mockResolvedValue(response);

const result = await service.getOMRRAuthorizationDocumentsFromAMS();

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

it('should throw error if status is not 200', async () => {
const response = {
status: 400,
data: undefined,
};
jest.spyOn(httpService.axiosRef, 'post').mockResolvedValue(response);
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');
jest.spyOn(httpService.axiosRef, 'post').mockRejectedValue(error);

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

});
Loading

0 comments on commit fc35e59

Please sign in to comment.