Skip to content

Commit

Permalink
environment variable changes to get unit tests
Browse files Browse the repository at this point in the history
 running on gh
  • Loading branch information
hannah-macdonald1 committed Nov 20, 2024
1 parent 4df3734 commit 05be03e
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 46 deletions.
28 changes: 17 additions & 11 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,31 @@ export default () => ({
},
upstreamAuth: {
case: {
endpoint: process.env.CASE_ENDPOINT.trim().replace(/\s/g, '%20'),
endpoint: (process.env.CASE_ENDPOINT ?? ' ').trim().replace(/\s/g, '%20'),
workspace: 'int_lab',
idirField: 'Sales Rep',
},
incident: {
endpoint: process.env.INCIDENT_ENDPOINT.trim().replace(/\s/g, '%20'),
endpoint: (process.env.INCIDENT_ENDPOINT ?? ' ')
.trim()
.replace(/\s/g, '%20'),
workspace: 'int_lab',
idirField: 'Owned By',
},
sr: {
endpoint: process.env.SR_ENDPOINT.trim().replace(/\s/g, '%20'),
endpoint: (process.env.SR_ENDPOINT ?? ' ').trim().replace(/\s/g, '%20'),
workspace: 'int_lab',
idirField: 'Owner',
},
memo: {
endpoint: process.env.MEMO_ENDPOINT.trim().replace(/\s/g, '%20'),
endpoint: (process.env.MEMO_ENDPOINT ?? ' ').trim().replace(/\s/g, '%20'),
workspace: undefined,
},
},
oauth: {
accessTokenUrl: process.env.ACCESS_TOKEN_URL,
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
accessTokenUrl: process.env.ACCESS_TOKEN_URL ?? ' ',
clientId: process.env.CLIENT_ID ?? ' ',
clientSecret: process.env.CLIENT_SECRET ?? ' ',
},
workspaces: {
supportNetwork: undefined,
Expand All @@ -40,10 +42,14 @@ export default () => ({
attachments: undefined,
},
skipAuthGuard: process.env.SKIP_AUTH_GUARD === 'true',
endpointUrls: {
baseUrl: process.env.UPSTREAM_BASE_URL ?? ' ',
supportNetwork: process.env.SUPPORT_NETWORK_ENDPOINT ?? ' ',
inPersonVisits: process.env.IN_PERSON_VISITS_ENDPOINT ?? ' ',
postInPersonVisits: process.env.IN_PERSON_VISITS_POST_ENDPOINT ?? ' ',
attachments: process.env.ATTACHMENTS_ENDPOINT ?? ' ',
},
buildInfo: {
buildNumber:
process.env.VPI_APP_LABEL === undefined
? 'localBuild'
: process.env.VPI_APP_LABEL,
buildNumber: process.env.VPI_APP_LABEL ?? 'localBuild',
},
});
3 changes: 2 additions & 1 deletion src/controllers/cases/cases.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
idirUsernameHeaderField,
startRowNumParamName,
} from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('CasesController', () => {
let controller: CasesController;
Expand All @@ -44,7 +45,7 @@ describe('CasesController', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
CasesService,
AuthService,
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/cases/cases.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../../entities/attachments.entity';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('CasesService', () => {
let service: CasesService;
Expand All @@ -42,7 +43,7 @@ describe('CasesService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule, ConfigModule.forRoot()],
imports: [HttpModule, ConfigModule.forRoot({ load: [configuration] })],
providers: [
CasesService,
SupportNetworkService,
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/incidents/incidents.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '../../entities/attachments.entity';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('IncidentsController', () => {
let controller: IncidentsController;
Expand All @@ -34,7 +35,7 @@ describe('IncidentsController', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
IncidentsService,
SupportNetworkService,
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/incidents/incidents.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '../../entities/attachments.entity';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('IncidentsService', () => {
let service: IncidentsService;
Expand All @@ -35,7 +36,7 @@ describe('IncidentsService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule, ConfigModule.forRoot()],
imports: [HttpModule, ConfigModule.forRoot({ load: [configuration] })],
providers: [
IncidentsService,
SupportNetworkService,
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/memos/memos.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '../../entities/attachments.entity';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('MemosController', () => {
let controller: MemosController;
Expand All @@ -28,7 +29,7 @@ describe('MemosController', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
MemosService,
AttachmentsService,
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/memos/memos.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { IdPathParams } from '../../dto/id-path-params.dto';
import { FilterQueryParams } from '../../dto/filter-query-params.dto';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
MemosService,
AttachmentsService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { AuthService } from '../../common/guards/auth/auth.service';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('ServiceRequestsController', () => {
let controller: ServiceRequestsController;
Expand All @@ -34,7 +35,7 @@ describe('ServiceRequestsController', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
ServiceRequestsService,
AuthService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
} from '../../entities/attachments.entity';
import { getMockRes } from '@jest-mock/express';
import { startRowNumParamName } from '../../common/constants/upstream-constants';
import configuration from '../../configuration/configuration';

describe('ServiceRequestsService', () => {
let service: ServiceRequestsService;
Expand All @@ -35,7 +36,7 @@ describe('ServiceRequestsService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [HttpModule, ConfigModule.forRoot()],
imports: [HttpModule, ConfigModule.forRoot({ load: [configuration] })],
providers: [
ServiceRequestsService,
SupportNetworkService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
startRowNumParamName,
} from '../../common/constants/upstream-constants';
import { RecordCountNeededEnum } from '../../common/constants/enumerations';
import configuration from '../../configuration/configuration';

describe('RequestPreparerService', () => {
let service: RequestPreparerService;
Expand All @@ -38,7 +39,7 @@ describe('RequestPreparerService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
RequestPreparerService,
UtilitiesService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
InternalAxiosRequestConfig,
RawAxiosRequestHeaders,
} from 'axios';
import configuration from '../../configuration/configuration';

describe('TokenRefresherService', () => {
let service: TokenRefresherService;
Expand All @@ -19,7 +20,7 @@ describe('TokenRefresherService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
TokenRefresherService,
{ provide: HttpService, useValue: { get: jest.fn(), post: jest.fn() } },
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/attachments/attachments.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
NestedAttachmentsEntity,
} from '../../entities/attachments.entity';
import { getMockRes } from '@jest-mock/express';
import configuration from '../../configuration/configuration';

describe('AttachmentsService', () => {
let service: AttachmentsService;
Expand All @@ -26,7 +27,7 @@ describe('AttachmentsService', () => {

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
AttachmentsService,
UtilitiesService,
Expand Down
8 changes: 2 additions & 6 deletions src/helpers/attachments/attachments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { FilterQueryParams } from '../../dto/filter-query-params.dto';
import { ConfigService } from '@nestjs/config';
import { RequestPreparerService } from '../../external-api/request-preparer/request-preparer.service';
import { NestedAttachmentsEntity } from '../../entities/attachments.entity';
import {
baseUrlEnvVarName,
attachmentsEndpointEnvVarName,
} from '../../common/constants/upstream-constants';
import { idName } from '../../common/constants/parameter-constants';
import { Response } from 'express';

Expand All @@ -22,8 +18,8 @@ export class AttachmentsService {
private readonly requestPreparerService: RequestPreparerService,
) {
this.url = (
this.configService.get<string>(baseUrlEnvVarName) +
this.configService.get<string>(attachmentsEndpointEnvVarName)
this.configService.get<string>('endpointUrls.baseUrl') +
this.configService.get<string>('endpointUrls.attachments')
).replace(/\s/g, '%20');
this.workspace = this.configService.get('workspaces.attachments');
this.sinceFieldName = this.configService.get('sinceFieldName.attachments');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '../../common/constants/parameter-constants';
import { PostInPersonVisitDtoUpstream } from '../../dto/post-in-person-visit.dto';
import { getMockRes } from '@jest-mock/express';
import configuration from '../../configuration/configuration';

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

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
InPersonVisitsService,
UtilitiesService,
Expand Down
13 changes: 4 additions & 9 deletions src/helpers/in-person-visits/in-person-visits.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { FilterQueryParams } from '../../dto/filter-query-params.dto';
import { ConfigService } from '@nestjs/config';
import { RequestPreparerService } from '../../external-api/request-preparer/request-preparer.service';
import { NestedInPersonVisitsEntity } from '../../entities/in-person-visits.entity';
import {
baseUrlEnvVarName,
inPersonVisitsEndpointEnvVarName,
postInPersonVisitsEndpointEnvVarName,
} from '../../common/constants/upstream-constants';
import {
CONTENT_TYPE,
idName,
Expand All @@ -31,12 +26,12 @@ export class InPersonVisitsService {
private readonly requestPreparerService: RequestPreparerService,
) {
this.url = (
this.configService.get<string>(baseUrlEnvVarName) +
this.configService.get<string>(inPersonVisitsEndpointEnvVarName)
this.configService.get<string>('endpointUrls.baseUrl') +
this.configService.get<string>('endpointUrls.inPersonVisits')
).replace(/\s/g, '%20');
this.postUrl = (
this.configService.get<string>(baseUrlEnvVarName) +
this.configService.get<string>(postInPersonVisitsEndpointEnvVarName)
this.configService.get<string>('endpointUrls.baseUrl') +
this.configService.get<string>('endpointUrls.postInPersonVisits')
).replace(/\s/g, '%20');
this.workspace = this.configService.get('workspaces.inPersonVisits');
this.postWorkspace = this.configService.get(
Expand Down
9 changes: 7 additions & 2 deletions src/helpers/support-network/support-network.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ import {
sinceParamName,
} from '../../common/constants/parameter-constants';
import { getMockRes } from '@jest-mock/express';
import { log } from 'console';
import configuration from '../../configuration/configuration';

describe('SupportNetworkService', () => {
let service: SupportNetworkService;
let requestPreparerService: RequestPreparerService;
let configService: ConfigService;
const { res, mockClear } = getMockRes();

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ConfigModule.forRoot()],
imports: [ConfigModule.forRoot({ load: [configuration] })],
providers: [
SupportNetworkService,
UtilitiesService,
Expand All @@ -50,10 +53,12 @@ describe('SupportNetworkService', () => {
requestPreparerService = module.get<RequestPreparerService>(
RequestPreparerService,
);
configService = module.get<ConfigService>(ConfigService);
mockClear();
});

it('should be defined', () => {
it('should be defined a', () => {
log(configService.get<string>('endpointUrls.baseUrl'));
expect(service).toBeDefined();
});

Expand Down
9 changes: 3 additions & 6 deletions src/helpers/support-network/support-network.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import { NestedSupportNetworkEntity } from '../../entities/support-network.entit
import { IdPathParams } from '../../dto/id-path-params.dto';
import { FilterQueryParams } from '../../dto/filter-query-params.dto';
import { RequestPreparerService } from '../../external-api/request-preparer/request-preparer.service';
import {
baseUrlEnvVarName,
supportNetworkEndpointEnvVarName,
} from '../../common/constants/upstream-constants';
import { idName } from '../../common/constants/parameter-constants';
import { Response } from 'express';

Expand All @@ -24,9 +20,10 @@ export class SupportNetworkService {
private readonly configService: ConfigService,
private readonly requestPreparerService: RequestPreparerService,
) {
// console.log(this.configService.get<string>('endpointUrls.baseUrl'));
this.url = (
this.configService.get<string>(baseUrlEnvVarName) +
this.configService.get<string>(supportNetworkEndpointEnvVarName)
this.configService.get<string>('endpointUrls.baseUrl') +
this.configService.get<string>('endpointUrls.supportNetwork')
).replace(/\s/g, '%20');
this.workspace = this.configService.get('workspaces.supportNetwork');
this.sinceFieldName = this.configService.get(
Expand Down

0 comments on commit 05be03e

Please sign in to comment.