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

Github Unit Tests #33

Merged
merged 7 commits into from
Nov 20, 2024
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
37 changes: 37 additions & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Unit Test

on:
pull_request:
types: [opened, edited, reopened, ready_for_review]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test:gh

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: JEST Tests # Name of the check run which will be created
path: reports/jest-*.xml # Path to test results
reporter: jest-junit # Format of test results
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# test reports
reports/
59 changes: 53 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:gh": "jest --ci --reporters=default --reporters=jest-junit",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand Down Expand Up @@ -55,6 +56,7 @@
"eslint-plugin-prettier": "^5.0.0",
"husky": "^9.1.6",
"jest": "^29.5.0",
"jest-junit": "^16.0.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
Expand Down Expand Up @@ -82,5 +84,14 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"jest-junit": {
"outputDirectory": "reports",
"outputName": "jest-junit.xml",
"ancestorSeparator": " › ",
"uniqueOutputName": "false",
"suiteNameTemplate": "{title}",
"classNameTemplate": "{title}",
"titleTemplate": "{title}"
}
}
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
Loading