From ffd5993cbaf848220d954b48f96d628b5fc6a6f7 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:02:36 +0800 Subject: [PATCH 1/8] chore: inline model tests --- .../admin_verification.server.model.spec.ts | 5 +-- .../__tests__}/agency.server.model.spec.ts | 2 +- .../encrypt-submission.server.model.spec.ts | 40 +++++++++---------- .../__tests__}/form.server.model.spec.ts | 2 +- .../form_feedback.server.model.spec.ts | 2 +- .../__tests__}/form_fields.schema.spec.ts | 2 +- ...form_statistics_total.server.model.spec.ts | 2 +- .../__tests__}/login.server.model.spec.ts | 2 +- .../submission.server.model.spec.ts | 3 +- .../__tests__}/user.server.model.spec.ts | 2 +- 10 files changed, 30 insertions(+), 32 deletions(-) rename {tests/unit/backend/models => src/app/models/__tests__}/admin_verification.server.model.spec.ts (98%) rename {tests/unit/backend/models => src/app/models/__tests__}/agency.server.model.spec.ts (94%) rename {tests/unit/backend/models => src/app/models/__tests__}/encrypt-submission.server.model.spec.ts (94%) rename {tests/unit/backend/models => src/app/models/__tests__}/form.server.model.spec.ts (99%) rename {tests/unit/backend/models => src/app/models/__tests__}/form_feedback.server.model.spec.ts (98%) rename {tests/unit/backend/models => src/app/models/__tests__}/form_fields.schema.spec.ts (98%) rename {tests/unit/backend/models => src/app/models/__tests__}/form_statistics_total.server.model.spec.ts (97%) rename {tests/unit/backend/models => src/app/models/__tests__}/login.server.model.spec.ts (99%) rename {tests/unit/backend/models => src/app/models/__tests__}/submission.server.model.spec.ts (99%) rename {tests/unit/backend/models => src/app/models/__tests__}/user.server.model.spec.ts (99%) diff --git a/tests/unit/backend/models/admin_verification.server.model.spec.ts b/src/app/models/__tests__/admin_verification.server.model.spec.ts similarity index 98% rename from tests/unit/backend/models/admin_verification.server.model.spec.ts rename to src/app/models/__tests__/admin_verification.server.model.spec.ts index 5476933b23..250cc50e50 100644 --- a/tests/unit/backend/models/admin_verification.server.model.spec.ts +++ b/src/app/models/__tests__/admin_verification.server.model.spec.ts @@ -7,7 +7,7 @@ import { UpsertOtpParams, } from 'src/types/admin_verification' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const AdminVerification = getAdminVerificationModel(mongoose) @@ -87,7 +87,6 @@ describe('AdminVerification Model', () => { } // Act - // @ts-ignore const actualPromise = AdminVerification.create(missingContactParams) // Assert @@ -104,7 +103,6 @@ describe('AdminVerification Model', () => { } // Act - // @ts-ignore const actualPromise = AdminVerification.create(missingOtpParams) // Assert @@ -121,7 +119,6 @@ describe('AdminVerification Model', () => { } // Act - // @ts-ignore const actualPromise = AdminVerification.create(missingExpireParams) // Assert diff --git a/tests/unit/backend/models/agency.server.model.spec.ts b/src/app/models/__tests__/agency.server.model.spec.ts similarity index 94% rename from tests/unit/backend/models/agency.server.model.spec.ts rename to src/app/models/__tests__/agency.server.model.spec.ts index 65b73f73b8..40a7a2bf1d 100644 --- a/tests/unit/backend/models/agency.server.model.spec.ts +++ b/src/app/models/__tests__/agency.server.model.spec.ts @@ -5,7 +5,7 @@ import getAgencyModel, { AGENCY_PUBLIC_FIELDS, } from 'src/app/models/agency.server.model' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const Agency = getAgencyModel(mongoose) diff --git a/tests/unit/backend/models/encrypt-submission.server.model.spec.ts b/src/app/models/__tests__/encrypt-submission.server.model.spec.ts similarity index 94% rename from tests/unit/backend/models/encrypt-submission.server.model.spec.ts rename to src/app/models/__tests__/encrypt-submission.server.model.spec.ts index fb28541361..e182bcfe1b 100644 --- a/tests/unit/backend/models/encrypt-submission.server.model.spec.ts +++ b/src/app/models/__tests__/encrypt-submission.server.model.spec.ts @@ -14,7 +14,7 @@ import { SubmissionType, } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const Submission = getSubmissionModel(mongoose) const EncryptSubmission = getEncryptSubmissionModel(mongoose) @@ -33,16 +33,16 @@ describe('Encrypt Submission Model', () => { const validFormId = new ObjectId().toHexString() const createdDate = new Date() // Add valid encrypt submission. - const validSubmission = await Submission.create< - IEncryptedSubmissionSchema - >({ - form: validFormId, - myInfoFields: [], - submissionType: SubmissionType.Encrypt, - encryptedContent: MOCK_ENCRYPTED_CONTENT, - version: 1, - created: createdDate, - }) + const validSubmission = await Submission.create( + { + form: validFormId, + myInfoFields: [], + submissionType: SubmissionType.Encrypt, + encryptedContent: MOCK_ENCRYPTED_CONTENT, + version: 1, + created: createdDate, + }, + ) // Act const result = await EncryptSubmission.findSingleMetadata( @@ -391,15 +391,15 @@ describe('Encrypt Submission Model', () => { it('should return null when type of submission with given id is not SubmissionType.Encrypt', async () => { // Arrange const validFormId = new ObjectId().toHexString() - const validEmailSubmission = await Submission.create< - IEmailSubmissionSchema - >({ - submissionType: SubmissionType.Email, - form: validFormId, - recipientEmails: ['any@example.com'], - responseHash: 'any hash', - responseSalt: 'any salt', - }) + const validEmailSubmission = await Submission.create( + { + submissionType: SubmissionType.Email, + form: validFormId, + recipientEmails: ['any@example.com'], + responseHash: 'any hash', + responseSalt: 'any salt', + }, + ) // Act const actual = await EncryptSubmission.findEncryptedSubmissionById( diff --git a/tests/unit/backend/models/form.server.model.spec.ts b/src/app/models/__tests__/form.server.model.spec.ts similarity index 99% rename from tests/unit/backend/models/form.server.model.spec.ts rename to src/app/models/__tests__/form.server.model.spec.ts index fada279002..bd303f59af 100644 --- a/tests/unit/backend/models/form.server.model.spec.ts +++ b/src/app/models/__tests__/form.server.model.spec.ts @@ -16,7 +16,7 @@ import { Status, } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const Form = getFormModel(mongoose) const EncryptedForm = getEncryptedFormModel(mongoose) diff --git a/tests/unit/backend/models/form_feedback.server.model.spec.ts b/src/app/models/__tests__/form_feedback.server.model.spec.ts similarity index 98% rename from tests/unit/backend/models/form_feedback.server.model.spec.ts rename to src/app/models/__tests__/form_feedback.server.model.spec.ts index b794c0e2a7..444a73dfc3 100644 --- a/tests/unit/backend/models/form_feedback.server.model.spec.ts +++ b/src/app/models/__tests__/form_feedback.server.model.spec.ts @@ -5,7 +5,7 @@ import mongoose from 'mongoose' import getFormFeedbackModel from 'src/app/models/form_feedback.server.model' import { IFormFeedback } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const FeedbackModel = getFormFeedbackModel(mongoose) diff --git a/tests/unit/backend/models/form_fields.schema.spec.ts b/src/app/models/__tests__/form_fields.schema.spec.ts similarity index 98% rename from tests/unit/backend/models/form_fields.schema.spec.ts rename to src/app/models/__tests__/form_fields.schema.spec.ts index 04f96228b2..1cc017bd58 100644 --- a/tests/unit/backend/models/form_fields.schema.spec.ts +++ b/src/app/models/__tests__/form_fields.schema.spec.ts @@ -4,7 +4,7 @@ import mongoose from 'mongoose' import getFormModel from 'src/app/models/form.server.model' import { BasicField, IFieldSchema, ResponseMode } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const Form = getFormModel(mongoose) diff --git a/tests/unit/backend/models/form_statistics_total.server.model.spec.ts b/src/app/models/__tests__/form_statistics_total.server.model.spec.ts similarity index 97% rename from tests/unit/backend/models/form_statistics_total.server.model.spec.ts rename to src/app/models/__tests__/form_statistics_total.server.model.spec.ts index 5cb9b8d46b..7163dacca7 100644 --- a/tests/unit/backend/models/form_statistics_total.server.model.spec.ts +++ b/src/app/models/__tests__/form_statistics_total.server.model.spec.ts @@ -4,7 +4,7 @@ import mongoose from 'mongoose' import getFormStatisticsTotalModel from 'src/app/models/form_statistics_total.server.model' import { AggregateFormCountResult, IFormStatisticsTotalSchema } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const FormStatsModel = getFormStatisticsTotalModel(mongoose) diff --git a/tests/unit/backend/models/login.server.model.spec.ts b/src/app/models/__tests__/login.server.model.spec.ts similarity index 99% rename from tests/unit/backend/models/login.server.model.spec.ts rename to src/app/models/__tests__/login.server.model.spec.ts index c7020fdb9c..64ce5e53cd 100644 --- a/tests/unit/backend/models/login.server.model.spec.ts +++ b/src/app/models/__tests__/login.server.model.spec.ts @@ -13,7 +13,7 @@ import { IUserSchema, } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const LoginModel = getLoginModel(mongoose) diff --git a/tests/unit/backend/models/submission.server.model.spec.ts b/src/app/models/__tests__/submission.server.model.spec.ts similarity index 99% rename from tests/unit/backend/models/submission.server.model.spec.ts rename to src/app/models/__tests__/submission.server.model.spec.ts index 666fa26042..766a4cb86b 100644 --- a/tests/unit/backend/models/submission.server.model.spec.ts +++ b/src/app/models/__tests__/submission.server.model.spec.ts @@ -6,13 +6,14 @@ import getSubmissionModel, { getEncryptSubmissionModel, } from 'src/app/models/submission.server.model' +import dbHandler from 'tests/unit/backend/helpers/jest-db' + import { AuthType, ISubmissionSchema, IWebhookResponse, SubmissionType, } from '../../../../src/types' -import dbHandler from '../helpers/jest-db' const Submission = getSubmissionModel(mongoose) const EncryptedSubmission = getEncryptSubmissionModel(mongoose) diff --git a/tests/unit/backend/models/user.server.model.spec.ts b/src/app/models/__tests__/user.server.model.spec.ts similarity index 99% rename from tests/unit/backend/models/user.server.model.spec.ts rename to src/app/models/__tests__/user.server.model.spec.ts index 96a7b28e12..ea4c3cf7b0 100644 --- a/tests/unit/backend/models/user.server.model.spec.ts +++ b/src/app/models/__tests__/user.server.model.spec.ts @@ -4,7 +4,7 @@ import mongoose from 'mongoose' import getUserModel from 'src/app/models/user.server.model' import { IAgencySchema, IUser, IUserSchema } from 'src/types' -import dbHandler from '../helpers/jest-db' +import dbHandler from 'tests/unit/backend/helpers/jest-db' const User = getUserModel(mongoose) From ffec63489259c12463ad6612675df8f9ad1635a7 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:04:15 +0800 Subject: [PATCH 2/8] chore: rename frontend.server.* to frontend.* --- ...nd.server.controller.spec.ts => frontend.controller.spec.ts} | 2 +- .../{frontend.server.controller.ts => frontend.controller.ts} | 0 .../frontend/{frontend.server.routes.ts => frontend.routes.ts} | 2 +- src/app/modules/frontend/google-analytics.factory.ts | 2 +- src/loaders/express/index.ts | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/app/modules/frontend/__tests__/{frontend.server.controller.spec.ts => frontend.controller.spec.ts} (97%) rename src/app/modules/frontend/{frontend.server.controller.ts => frontend.controller.ts} (100%) rename src/app/modules/frontend/{frontend.server.routes.ts => frontend.routes.ts} (95%) diff --git a/src/app/modules/frontend/__tests__/frontend.server.controller.spec.ts b/src/app/modules/frontend/__tests__/frontend.controller.spec.ts similarity index 97% rename from src/app/modules/frontend/__tests__/frontend.server.controller.spec.ts rename to src/app/modules/frontend/__tests__/frontend.controller.spec.ts index 05ce6016a2..3b853c0d23 100644 --- a/src/app/modules/frontend/__tests__/frontend.server.controller.spec.ts +++ b/src/app/modules/frontend/__tests__/frontend.controller.spec.ts @@ -2,7 +2,7 @@ import { StatusCodes } from 'http-status-codes' import expressHandler from 'tests/unit/backend/helpers/jest-express' -import * as FrontendServerController from '../frontend.server.controller' +import * as FrontendServerController from '../frontend.controller' describe('frontend.server.controller', () => { afterEach(() => jest.clearAllMocks()) diff --git a/src/app/modules/frontend/frontend.server.controller.ts b/src/app/modules/frontend/frontend.controller.ts similarity index 100% rename from src/app/modules/frontend/frontend.server.controller.ts rename to src/app/modules/frontend/frontend.controller.ts diff --git a/src/app/modules/frontend/frontend.server.routes.ts b/src/app/modules/frontend/frontend.routes.ts similarity index 95% rename from src/app/modules/frontend/frontend.server.routes.ts rename to src/app/modules/frontend/frontend.routes.ts index 0038ce44d0..4e823f2967 100644 --- a/src/app/modules/frontend/frontend.server.routes.ts +++ b/src/app/modules/frontend/frontend.routes.ts @@ -1,7 +1,7 @@ import { celebrate, Joi, Segments } from 'celebrate' import { Router } from 'express' -import * as FrontendServerController from './frontend.server.controller' +import * as FrontendServerController from './frontend.controller' import { GoogleAnalyticsFactory } from './google-analytics.factory' export const FrontendRouter = Router() diff --git a/src/app/modules/frontend/google-analytics.factory.ts b/src/app/modules/frontend/google-analytics.factory.ts index 1273dec4e6..4f9eaa55d8 100644 --- a/src/app/modules/frontend/google-analytics.factory.ts +++ b/src/app/modules/frontend/google-analytics.factory.ts @@ -7,7 +7,7 @@ import FeatureManager, { RegisteredFeature, } from '../../../config/feature-manager' -import * as FrontendServerController from './frontend.server.controller' +import * as FrontendServerController from './frontend.controller' interface IGoogleAnalyticsFactory { addGoogleAnalyticsData: RequestHandler< diff --git a/src/loaders/express/index.ts b/src/loaders/express/index.ts index 1acdd06314..21ebc3553a 100644 --- a/src/loaders/express/index.ts +++ b/src/loaders/express/index.ts @@ -15,7 +15,7 @@ import { BounceRouter } from '../../app/modules/bounce/bounce.routes' import { ExamplesRouter } from '../../app/modules/examples/examples.routes' import { AdminFormsRouter } from '../../app/modules/form/admin-form/admin-form.routes' import { PublicFormRouter } from '../../app/modules/form/public-form/public-form.routes' -import { FrontendRouter } from '../../app/modules/frontend/frontend.server.routes' +import { FrontendRouter } from '../../app/modules/frontend/frontend.routes' import { HomeRouter } from '../../app/modules/home/home.routes' import { MYINFO_ROUTER_PREFIX } from '../../app/modules/myinfo/myinfo.constants' import { MyInfoRouter } from '../../app/modules/myinfo/myinfo.routes' From 3355ae707f216a95afa42e75fb3334ba754bf000 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:07:31 +0800 Subject: [PATCH 3/8] chore: inline field validator tests --- .../validators/__tests__}/attachment-validation.spec.ts | 2 +- .../validators/__tests__}/checkbox-validation.spec.ts | 2 +- .../validators/__tests__}/date-validation.spec.ts | 2 +- .../validators/__tests__}/decimal-validation.spec.ts | 2 +- .../validators/__tests__}/dropdown-validation.spec.ts | 2 +- .../validators/__tests__}/email-validation.spec.ts | 0 .../validators/__tests__}/home-num-validation.spec.ts | 2 +- .../validators/__tests__}/mobile-num-validation.spec.ts | 2 +- .../validators/__tests__}/nric-validation.spec.ts | 2 +- .../validators/__tests__}/number-validation.spec.ts | 2 +- .../validators/__tests__}/radio-button-validation.spec.ts | 2 +- .../validators/__tests__}/rating-validation.spec.ts | 2 +- .../validators/__tests__}/table-validation.spec.ts | 2 +- .../validators/__tests__}/text-validator.spec.ts | 2 +- .../validators/__tests__}/yesno-validation.spec.ts | 2 +- 15 files changed, 14 insertions(+), 14 deletions(-) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/attachment-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/checkbox-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/date-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/decimal-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/dropdown-validation.spec.ts (98%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/email-validation.spec.ts (100%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/home-num-validation.spec.ts (98%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/mobile-num-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/nric-validation.spec.ts (98%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/number-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/radio-button-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/rating-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/table-validation.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/text-validator.spec.ts (99%) rename {tests/unit/backend/utils/field-validation => src/app/utils/field-validation/validators/__tests__}/yesno-validation.spec.ts (98%) diff --git a/tests/unit/backend/utils/field-validation/attachment-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/attachment-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/attachment-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/attachment-validation.spec.ts index 70b75d0d43..554632f230 100644 --- a/tests/unit/backend/utils/field-validation/attachment-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/attachment-validation.spec.ts @@ -7,7 +7,7 @@ import { AttachmentSize, BasicField } from 'src/types' import { generateDefaultField, generateNewAttachmentResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Attachment validation', () => { const formId = new ObjectId().toHexString() diff --git a/tests/unit/backend/utils/field-validation/checkbox-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/checkbox-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/checkbox-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/checkbox-validation.spec.ts index d053427703..2977a26414 100644 --- a/tests/unit/backend/utils/field-validation/checkbox-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/checkbox-validation.spec.ts @@ -7,7 +7,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewCheckboxResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Checkbox validation', () => { const formId = new ObjectId().toHexString() diff --git a/tests/unit/backend/utils/field-validation/date-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/date-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/date-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/date-validation.spec.ts index 55384322ed..8368f2cc89 100644 --- a/tests/unit/backend/utils/field-validation/date-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/date-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Date field validation', () => { beforeAll(() => { diff --git a/tests/unit/backend/utils/field-validation/decimal-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/decimal-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/decimal-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/decimal-validation.spec.ts index cf5359fc84..543e706c03 100644 --- a/tests/unit/backend/utils/field-validation/decimal-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/decimal-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Decimal Validation', () => { it('should allow decimal with valid maximum', () => { diff --git a/tests/unit/backend/utils/field-validation/dropdown-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/dropdown-validation.spec.ts similarity index 98% rename from tests/unit/backend/utils/field-validation/dropdown-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/dropdown-validation.spec.ts index 09b2191235..5c0ff431f1 100644 --- a/tests/unit/backend/utils/field-validation/dropdown-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/dropdown-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Dropdown validation', () => { it('should allow valid option', () => { diff --git a/tests/unit/backend/utils/field-validation/email-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/email-validation.spec.ts similarity index 100% rename from tests/unit/backend/utils/field-validation/email-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/email-validation.spec.ts diff --git a/tests/unit/backend/utils/field-validation/home-num-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/home-num-validation.spec.ts similarity index 98% rename from tests/unit/backend/utils/field-validation/home-num-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/home-num-validation.spec.ts index 5ba51d60e4..853b6ece21 100644 --- a/tests/unit/backend/utils/field-validation/home-num-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/home-num-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Home phone number validation tests', () => { it('should allow empty answer for required logic field that is not visible', () => { diff --git a/tests/unit/backend/utils/field-validation/mobile-num-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/mobile-num-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts index e9d727ec74..0f6449cc1c 100644 --- a/tests/unit/backend/utils/field-validation/mobile-num-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts @@ -7,7 +7,7 @@ import { BasicField } from 'src/types/field/fieldTypes' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' type VerificationMock = { authenticate: () => boolean diff --git a/tests/unit/backend/utils/field-validation/nric-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/nric-validation.spec.ts similarity index 98% rename from tests/unit/backend/utils/field-validation/nric-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/nric-validation.spec.ts index c762c12002..1a0de0c34c 100644 --- a/tests/unit/backend/utils/field-validation/nric-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/nric-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('NRIC field validation', () => { it('should allow valid NRIC with S prefix', () => { diff --git a/tests/unit/backend/utils/field-validation/number-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/number-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/number-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/number-validation.spec.ts index 50a0a12a87..5df3bd3bec 100644 --- a/tests/unit/backend/utils/field-validation/number-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/number-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField, NumberSelectedValidation } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Number field validation', () => { it('should allow number with valid maximum', () => { diff --git a/tests/unit/backend/utils/field-validation/radio-button-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/radio-button-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/radio-button-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/radio-button-validation.spec.ts index 96ee953ad7..4dab0be12c 100644 --- a/tests/unit/backend/utils/field-validation/radio-button-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/radio-button-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Radio button validation', () => { it('should allow valid option', () => { diff --git a/tests/unit/backend/utils/field-validation/rating-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/rating-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/rating-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/rating-validation.spec.ts index eee084e01c..53fee4103a 100644 --- a/tests/unit/backend/utils/field-validation/rating-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/rating-validation.spec.ts @@ -6,7 +6,7 @@ import { RatingShape } from 'src/types/field/ratingField' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Rating field validation', () => { it('should allow answer within range', () => { diff --git a/tests/unit/backend/utils/field-validation/table-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/table-validation.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/table-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/table-validation.spec.ts index 2ee0ca27ad..576a20600b 100644 --- a/tests/unit/backend/utils/field-validation/table-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/table-validation.spec.ts @@ -9,7 +9,7 @@ import { generateNewTableResponse, generateTableDropdownColumn, generateTableShortTextColumn, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Table validation', () => { const formId = new ObjectId().toHexString() diff --git a/tests/unit/backend/utils/field-validation/text-validator.spec.ts b/src/app/utils/field-validation/validators/__tests__/text-validator.spec.ts similarity index 99% rename from tests/unit/backend/utils/field-validation/text-validator.spec.ts rename to src/app/utils/field-validation/validators/__tests__/text-validator.spec.ts index 4690e27ec2..ab60ce4a27 100644 --- a/tests/unit/backend/utils/field-validation/text-validator.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/text-validator.spec.ts @@ -5,7 +5,7 @@ import { BasicField, TextSelectedValidation } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Text validation', () => { describe('Short text', () => { diff --git a/tests/unit/backend/utils/field-validation/yesno-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/yesno-validation.spec.ts similarity index 98% rename from tests/unit/backend/utils/field-validation/yesno-validation.spec.ts rename to src/app/utils/field-validation/validators/__tests__/yesno-validation.spec.ts index 5fec5bbf59..358dbfd4de 100644 --- a/tests/unit/backend/utils/field-validation/yesno-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/yesno-validation.spec.ts @@ -5,7 +5,7 @@ import { BasicField } from 'src/types' import { generateDefaultField, generateNewSingleAnswerResponse, -} from '../../helpers/generate-form-data' +} from 'tests/unit/backend/helpers/generate-form-data' describe('Yes/No field validation', () => { it('should allow yes', () => { From ad6bebfeda2d7a7783fa69db3ea4d855e5825eb7 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:09:05 +0800 Subject: [PATCH 4/8] chore: inline app/utils tests --- .../unit/backend/utils => src/app/utils/__tests__}/date.spec.ts | 0 .../utils => src/app/utils/__tests__}/file-validation.spec.ts | 0 .../utils => src/app/utils/__tests__}/handle-mongo-error.spec.ts | 0 .../unit/backend/utils => src/app/utils/__tests__}/logic.spec.ts | 0 .../utils => src/app/utils/__tests__}/stringify-safe.spec.ts | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {tests/unit/backend/utils => src/app/utils/__tests__}/date.spec.ts (100%) rename {tests/unit/backend/utils => src/app/utils/__tests__}/file-validation.spec.ts (100%) rename {tests/unit/backend/utils => src/app/utils/__tests__}/handle-mongo-error.spec.ts (100%) rename {tests/unit/backend/utils => src/app/utils/__tests__}/logic.spec.ts (100%) rename {tests/unit/backend/utils => src/app/utils/__tests__}/stringify-safe.spec.ts (100%) diff --git a/tests/unit/backend/utils/date.spec.ts b/src/app/utils/__tests__/date.spec.ts similarity index 100% rename from tests/unit/backend/utils/date.spec.ts rename to src/app/utils/__tests__/date.spec.ts diff --git a/tests/unit/backend/utils/file-validation.spec.ts b/src/app/utils/__tests__/file-validation.spec.ts similarity index 100% rename from tests/unit/backend/utils/file-validation.spec.ts rename to src/app/utils/__tests__/file-validation.spec.ts diff --git a/tests/unit/backend/utils/handle-mongo-error.spec.ts b/src/app/utils/__tests__/handle-mongo-error.spec.ts similarity index 100% rename from tests/unit/backend/utils/handle-mongo-error.spec.ts rename to src/app/utils/__tests__/handle-mongo-error.spec.ts diff --git a/tests/unit/backend/utils/logic.spec.ts b/src/app/utils/__tests__/logic.spec.ts similarity index 100% rename from tests/unit/backend/utils/logic.spec.ts rename to src/app/utils/__tests__/logic.spec.ts diff --git a/tests/unit/backend/utils/stringify-safe.spec.ts b/src/app/utils/__tests__/stringify-safe.spec.ts similarity index 100% rename from tests/unit/backend/utils/stringify-safe.spec.ts rename to src/app/utils/__tests__/stringify-safe.spec.ts From b6df6c002b077d20a90eb8b96887eaebf31dead4 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:21:51 +0800 Subject: [PATCH 5/8] chore: move loaders and config into src/app --- src/{ => app}/config/config.ts | 8 ++++- .../feature-manager/aggregate-stats.config.ts | 0 .../config/feature-manager/captcha.config.ts | 0 .../google-analytics.config.ts | 0 src/{ => app}/config/feature-manager/index.ts | 0 .../config/feature-manager/intranet.config.ts | 0 .../config/feature-manager/sentry.config.ts | 0 .../config/feature-manager/sms.config.ts | 0 .../feature-manager/spcp-myinfo.config.ts | 0 src/{ => app}/config/feature-manager/types.ts | 0 .../util/FeatureManager.class.ts | 0 .../feature-manager/verified-fields.config.ts | 0 .../webhook-verified-content.config.ts | 0 src/{ => app}/config/formsg-sdk.ts | 2 +- src/{ => app}/config/logger.ts | 2 +- src/{ => app}/config/ndi-config.ts | 0 src/{ => app}/config/schema.ts | 2 +- .../loaders/express/__tests__/helmet.spec.ts | 4 +-- .../loaders/express/error-handler.ts | 0 src/{ => app}/loaders/express/helmet.ts | 0 src/{ => app}/loaders/express/index.ts | 36 +++++++++---------- src/{ => app}/loaders/express/locals.ts | 0 src/{ => app}/loaders/express/logging.ts | 2 +- src/{ => app}/loaders/express/parser.ts | 0 src/{ => app}/loaders/express/sentry.ts | 0 src/{ => app}/loaders/express/session.ts | 0 src/{ => app}/loaders/index.ts | 0 src/{ => app}/loaders/mongoose.ts | 0 src/app/models/field/imageField.ts | 2 +- .../modules/analytics/analytics.controller.ts | 2 +- .../modules/analytics/analytics.service.ts | 4 +-- src/app/modules/auth/auth.controller.ts | 2 +- src/app/modules/auth/auth.routes.ts | 2 +- src/app/modules/auth/auth.service.ts | 4 +-- src/app/modules/auth/auth.utils.ts | 2 +- .../billing/__tests__/billing.factory.spec.ts | 2 +- src/app/modules/billing/billing.controller.ts | 2 +- src/app/modules/billing/billing.factory.ts | 4 +-- src/app/modules/billing/billing.service.ts | 2 +- .../bounce/__tests__/bounce.service.spec.ts | 2 +- src/app/modules/bounce/bounce.controller.ts | 2 +- src/app/modules/bounce/bounce.model.ts | 2 +- src/app/modules/bounce/bounce.service.ts | 8 ++--- src/app/modules/core/core.errors.ts | 2 +- .../__tests__/examples.factory.spec.ts | 2 +- .../modules/examples/examples.controller.ts | 2 +- src/app/modules/examples/examples.factory.ts | 2 +- src/app/modules/examples/examples.service.ts | 2 +- src/app/modules/examples/examples.utils.ts | 2 +- src/app/modules/feedback/feedback.service.ts | 2 +- .../__tests__/admin-form.routes.spec.ts | 2 +- .../__tests__/admin-form.service.spec.ts | 2 +- .../form/admin-form/admin-form.controller.ts | 2 +- .../form/admin-form/admin-form.service.ts | 4 +-- .../form/admin-form/admin-form.utils.ts | 2 +- src/app/modules/form/form.service.ts | 2 +- .../__tests__/public-form.controller.spec.ts | 2 +- .../public-form/public-form.controller.ts | 2 +- .../form/public-form/public-form.service.ts | 2 +- .../form/public-form/public-form.utils.ts | 2 +- .../google-analytics.factory.spec.ts | 2 +- .../modules/frontend/frontend.controller.ts | 4 +-- .../frontend/google-analytics.factory.ts | 2 +- .../myinfo/__tests__/myinfo.factory.spec.ts | 4 +-- .../myinfo/__tests__/myinfo.test.constants.ts | 2 +- .../__tests__/myinfo_hash.model.spec.ts | 2 +- src/app/modules/myinfo/myinfo.constants.ts | 2 +- src/app/modules/myinfo/myinfo.controller.ts | 2 +- src/app/modules/myinfo/myinfo.factory.ts | 10 +++--- src/app/modules/myinfo/myinfo.format.ts | 2 +- src/app/modules/myinfo/myinfo.service.ts | 2 +- src/app/modules/myinfo/myinfo.types.ts | 2 +- src/app/modules/myinfo/myinfo.util.ts | 2 +- src/app/modules/myinfo/myinfo_hash.model.ts | 2 +- .../spcp/__tests__/spcp.controller.spec.ts | 2 +- .../spcp/__tests__/spcp.factory.spec.ts | 2 +- .../spcp/__tests__/spcp.service.spec.ts | 2 +- .../spcp/__tests__/spcp.test.constants.ts | 2 +- src/app/modules/spcp/spcp.controller.ts | 4 +-- src/app/modules/spcp/spcp.factory.ts | 2 +- src/app/modules/spcp/spcp.service.ts | 4 +-- src/app/modules/spcp/spcp.util.ts | 2 +- .../email-submission.controller.ts | 2 +- .../email-submission.middleware.ts | 2 +- .../email-submission.receiver.ts | 2 +- .../email-submission.routes.ts | 2 +- .../email-submission.service.ts | 2 +- .../email-submission/email-submission.util.ts | 2 +- .../encrypt-submission.service.spec.ts | 2 +- .../encrypt-submission.controller.ts | 2 +- .../encrypt-submission.routes.ts | 2 +- .../encrypt-submission.service.ts | 4 +-- .../encrypt-submission.utils.ts | 2 +- .../modules/submission/submission.service.ts | 2 +- src/app/modules/user/user.controller.ts | 2 +- src/app/modules/user/user.service.ts | 4 +-- src/app/modules/user/user.utils.ts | 2 +- .../__tests__/verification.factory.spec.ts | 2 +- .../__tests__/verification.service.spec.ts | 2 +- .../verification/verification.controller.ts | 2 +- .../verification/verification.factory.ts | 2 +- .../verification/verification.service.ts | 4 +-- .../modules/verification/verification.util.ts | 2 +- .../verified-content.factory.spec.ts | 2 +- .../verified-content.service.spec.ts | 2 +- .../verified-content.factory.ts | 2 +- .../verified-content.service.ts | 4 +-- .../webhook/__tests__/webhook.service.spec.ts | 2 +- .../__tests__/webhook.validation.spec.ts | 2 +- src/app/modules/webhook/webhook.factory.ts | 2 +- src/app/modules/webhook/webhook.service.ts | 4 +-- src/app/modules/webhook/webhook.validation.ts | 2 +- src/app/routes/api/v3/auth/auth.routes.ts | 2 +- src/app/services/captcha/captcha.factory.ts | 2 +- src/app/services/captcha/captcha.service.ts | 2 +- src/app/services/captcha/captcha.util.ts | 2 +- .../__tests__/intranet.factory.spec.ts | 2 +- src/app/services/intranet/intranet.factory.ts | 2 +- .../services/intranet/intranet.middleware.ts | 2 +- src/app/services/intranet/intranet.service.ts | 4 +-- src/app/services/mail/mail.service.ts | 4 +-- src/app/services/mail/mail.utils.ts | 4 +-- .../sms/__tests__/sms.factory.spec.ts | 4 +-- src/app/services/sms/sms.factory.ts | 2 +- src/app/services/sms/sms.service.ts | 4 +-- src/app/utils/field-validation/index.ts | 2 +- .../__tests__/email-validation.spec.ts | 2 +- .../__tests__/mobile-num-validation.spec.ts | 2 +- .../field-validation/validators/common.ts | 2 +- src/app/utils/hash.ts | 2 +- src/app/utils/limit-rate.ts | 2 +- src/server.ts | 6 ++-- tests/integration/helpers/express-setup.ts | 8 ++--- 133 files changed, 166 insertions(+), 160 deletions(-) rename src/{ => app}/config/config.ts (98%) rename src/{ => app}/config/feature-manager/aggregate-stats.config.ts (100%) rename src/{ => app}/config/feature-manager/captcha.config.ts (100%) rename src/{ => app}/config/feature-manager/google-analytics.config.ts (100%) rename src/{ => app}/config/feature-manager/index.ts (100%) rename src/{ => app}/config/feature-manager/intranet.config.ts (100%) rename src/{ => app}/config/feature-manager/sentry.config.ts (100%) rename src/{ => app}/config/feature-manager/sms.config.ts (100%) rename src/{ => app}/config/feature-manager/spcp-myinfo.config.ts (100%) rename src/{ => app}/config/feature-manager/types.ts (100%) rename src/{ => app}/config/feature-manager/util/FeatureManager.class.ts (100%) rename src/{ => app}/config/feature-manager/verified-fields.config.ts (100%) rename src/{ => app}/config/feature-manager/webhook-verified-content.config.ts (100%) rename src/{ => app}/config/formsg-sdk.ts (91%) rename src/{ => app}/config/logger.ts (99%) rename src/{ => app}/config/ndi-config.ts (100%) rename src/{ => app}/config/schema.ts (99%) rename src/{ => app}/loaders/express/__tests__/helmet.spec.ts (98%) rename src/{ => app}/loaders/express/error-handler.ts (100%) rename src/{ => app}/loaders/express/helmet.ts (100%) rename src/{ => app}/loaders/express/index.ts (79%) rename src/{ => app}/loaders/express/locals.ts (100%) rename src/{ => app}/loaders/express/logging.ts (97%) rename src/{ => app}/loaders/express/parser.ts (100%) rename src/{ => app}/loaders/express/sentry.ts (100%) rename src/{ => app}/loaders/express/session.ts (100%) rename src/{ => app}/loaders/index.ts (100%) rename src/{ => app}/loaders/mongoose.ts (100%) diff --git a/src/config/config.ts b/src/app/config/config.ts similarity index 98% rename from src/config/config.ts rename to src/app/config/config.ts index 79f63c4581..9834219462 100644 --- a/src/config/config.ts +++ b/src/app/config/config.ts @@ -6,7 +6,13 @@ import nodemailer from 'nodemailer' import Mail from 'nodemailer/lib/mailer' import SMTPPool from 'nodemailer/lib/smtp-pool' -import { AwsConfig, Config, DbConfig, Environment, MailConfig } from '../types' +import { + AwsConfig, + Config, + DbConfig, + Environment, + MailConfig, +} from '../../types' import { compulsoryVarsSchema, diff --git a/src/config/feature-manager/aggregate-stats.config.ts b/src/app/config/feature-manager/aggregate-stats.config.ts similarity index 100% rename from src/config/feature-manager/aggregate-stats.config.ts rename to src/app/config/feature-manager/aggregate-stats.config.ts diff --git a/src/config/feature-manager/captcha.config.ts b/src/app/config/feature-manager/captcha.config.ts similarity index 100% rename from src/config/feature-manager/captcha.config.ts rename to src/app/config/feature-manager/captcha.config.ts diff --git a/src/config/feature-manager/google-analytics.config.ts b/src/app/config/feature-manager/google-analytics.config.ts similarity index 100% rename from src/config/feature-manager/google-analytics.config.ts rename to src/app/config/feature-manager/google-analytics.config.ts diff --git a/src/config/feature-manager/index.ts b/src/app/config/feature-manager/index.ts similarity index 100% rename from src/config/feature-manager/index.ts rename to src/app/config/feature-manager/index.ts diff --git a/src/config/feature-manager/intranet.config.ts b/src/app/config/feature-manager/intranet.config.ts similarity index 100% rename from src/config/feature-manager/intranet.config.ts rename to src/app/config/feature-manager/intranet.config.ts diff --git a/src/config/feature-manager/sentry.config.ts b/src/app/config/feature-manager/sentry.config.ts similarity index 100% rename from src/config/feature-manager/sentry.config.ts rename to src/app/config/feature-manager/sentry.config.ts diff --git a/src/config/feature-manager/sms.config.ts b/src/app/config/feature-manager/sms.config.ts similarity index 100% rename from src/config/feature-manager/sms.config.ts rename to src/app/config/feature-manager/sms.config.ts diff --git a/src/config/feature-manager/spcp-myinfo.config.ts b/src/app/config/feature-manager/spcp-myinfo.config.ts similarity index 100% rename from src/config/feature-manager/spcp-myinfo.config.ts rename to src/app/config/feature-manager/spcp-myinfo.config.ts diff --git a/src/config/feature-manager/types.ts b/src/app/config/feature-manager/types.ts similarity index 100% rename from src/config/feature-manager/types.ts rename to src/app/config/feature-manager/types.ts diff --git a/src/config/feature-manager/util/FeatureManager.class.ts b/src/app/config/feature-manager/util/FeatureManager.class.ts similarity index 100% rename from src/config/feature-manager/util/FeatureManager.class.ts rename to src/app/config/feature-manager/util/FeatureManager.class.ts diff --git a/src/config/feature-manager/verified-fields.config.ts b/src/app/config/feature-manager/verified-fields.config.ts similarity index 100% rename from src/config/feature-manager/verified-fields.config.ts rename to src/app/config/feature-manager/verified-fields.config.ts diff --git a/src/config/feature-manager/webhook-verified-content.config.ts b/src/app/config/feature-manager/webhook-verified-content.config.ts similarity index 100% rename from src/config/feature-manager/webhook-verified-content.config.ts rename to src/app/config/feature-manager/webhook-verified-content.config.ts diff --git a/src/config/formsg-sdk.ts b/src/app/config/formsg-sdk.ts similarity index 91% rename from src/config/formsg-sdk.ts rename to src/app/config/formsg-sdk.ts index 5dda108394..180ef78761 100644 --- a/src/config/formsg-sdk.ts +++ b/src/app/config/formsg-sdk.ts @@ -1,7 +1,7 @@ import formsgSdkPackage from '@opengovsg/formsg-sdk' import { get } from 'lodash' -import * as vfnConstants from '../shared/util/verification' +import * as vfnConstants from '../../shared/util/verification' import { formsgSdkMode } from './config' import featureManager, { FeatureNames } from './feature-manager' diff --git a/src/config/logger.ts b/src/app/config/logger.ts similarity index 99% rename from src/config/logger.ts rename to src/app/config/logger.ts index 91fa4c319b..fe7455aa66 100644 --- a/src/config/logger.ts +++ b/src/app/config/logger.ts @@ -8,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid' import { format, Logger, LoggerOptions, loggers, transports } from 'winston' import WinstonCloudWatch from 'winston-cloudwatch' -import { Environment } from '../types' +import { Environment } from '../../types' import { aws, customCloudWatchGroup, isDev, nodeEnv } from './config' diff --git a/src/config/ndi-config.ts b/src/app/config/ndi-config.ts similarity index 100% rename from src/config/ndi-config.ts rename to src/app/config/ndi-config.ts diff --git a/src/config/schema.ts b/src/app/config/schema.ts similarity index 99% rename from src/config/schema.ts rename to src/app/config/schema.ts index 34308b7dc8..68a57683f6 100644 --- a/src/config/schema.ts +++ b/src/app/config/schema.ts @@ -12,7 +12,7 @@ import { ICompulsoryVarsSchema, IOptionalVarsSchema, IProdOnlyVarsSchema, -} from '../types' +} from '../../types' convict.addFormat(url) convict.addFormat(email) diff --git a/src/loaders/express/__tests__/helmet.spec.ts b/src/app/loaders/express/__tests__/helmet.spec.ts similarity index 98% rename from src/loaders/express/__tests__/helmet.spec.ts rename to src/app/loaders/express/__tests__/helmet.spec.ts index fc9a57a612..bfb3fb4528 100644 --- a/src/loaders/express/__tests__/helmet.spec.ts +++ b/src/app/loaders/express/__tests__/helmet.spec.ts @@ -1,8 +1,8 @@ import helmet from 'helmet' import { mocked } from 'ts-jest/utils' -import config from 'src/config/config' -import featureManager from 'src/config/feature-manager' +import config from 'src/app/config/config' +import featureManager from 'src/app/config/feature-manager' import expressHandler from 'tests/unit/backend/helpers/jest-express' diff --git a/src/loaders/express/error-handler.ts b/src/app/loaders/express/error-handler.ts similarity index 100% rename from src/loaders/express/error-handler.ts rename to src/app/loaders/express/error-handler.ts diff --git a/src/loaders/express/helmet.ts b/src/app/loaders/express/helmet.ts similarity index 100% rename from src/loaders/express/helmet.ts rename to src/app/loaders/express/helmet.ts diff --git a/src/loaders/express/index.ts b/src/app/loaders/express/index.ts similarity index 79% rename from src/loaders/express/index.ts rename to src/app/loaders/express/index.ts index 21ebc3553a..fe2b264ee1 100644 --- a/src/loaders/express/index.ts +++ b/src/app/loaders/express/index.ts @@ -8,28 +8,28 @@ import nocache from 'nocache' import path from 'path' import url from 'url' -import { AnalyticsRouter } from '../../app/modules/analytics/analytics.routes' -import { AuthRouter } from '../../app/modules/auth/auth.routes' -import { BillingRouter } from '../../app/modules/billing/billing.routes' -import { BounceRouter } from '../../app/modules/bounce/bounce.routes' -import { ExamplesRouter } from '../../app/modules/examples/examples.routes' -import { AdminFormsRouter } from '../../app/modules/form/admin-form/admin-form.routes' -import { PublicFormRouter } from '../../app/modules/form/public-form/public-form.routes' -import { FrontendRouter } from '../../app/modules/frontend/frontend.routes' -import { HomeRouter } from '../../app/modules/home/home.routes' -import { MYINFO_ROUTER_PREFIX } from '../../app/modules/myinfo/myinfo.constants' -import { MyInfoRouter } from '../../app/modules/myinfo/myinfo.routes' +import config from '../../config/config' +import { AnalyticsRouter } from '../../modules/analytics/analytics.routes' +import { AuthRouter } from '../../modules/auth/auth.routes' +import { BillingRouter } from '../../modules/billing/billing.routes' +import { BounceRouter } from '../../modules/bounce/bounce.routes' +import { ExamplesRouter } from '../../modules/examples/examples.routes' +import { AdminFormsRouter } from '../../modules/form/admin-form/admin-form.routes' +import { PublicFormRouter } from '../../modules/form/public-form/public-form.routes' +import { FrontendRouter } from '../../modules/frontend/frontend.routes' +import { HomeRouter } from '../../modules/home/home.routes' +import { MYINFO_ROUTER_PREFIX } from '../../modules/myinfo/myinfo.constants' +import { MyInfoRouter } from '../../modules/myinfo/myinfo.routes' import { CorppassLoginRouter, SingpassLoginRouter, SpcpRouter, -} from '../../app/modules/spcp/spcp.routes' -import { SubmissionRouter } from '../../app/modules/submission/submission.routes' -import UserRouter from '../../app/modules/user/user.routes' -import { VfnRouter } from '../../app/modules/verification/verification.routes' -import { ApiRouter } from '../../app/routes/api' -import * as IntranetMiddleware from '../../app/services/intranet/intranet.middleware' -import config from '../../config/config' +} from '../../modules/spcp/spcp.routes' +import { SubmissionRouter } from '../../modules/submission/submission.routes' +import UserRouter from '../../modules/user/user.routes' +import { VfnRouter } from '../../modules/verification/verification.routes' +import { ApiRouter } from '../../routes/api' +import * as IntranetMiddleware from '../../services/intranet/intranet.middleware' import errorHandlerMiddlewares from './error-handler' import helmetMiddlewares from './helmet' diff --git a/src/loaders/express/locals.ts b/src/app/loaders/express/locals.ts similarity index 100% rename from src/loaders/express/locals.ts rename to src/app/loaders/express/locals.ts diff --git a/src/loaders/express/logging.ts b/src/app/loaders/express/logging.ts similarity index 97% rename from src/loaders/express/logging.ts rename to src/app/loaders/express/logging.ts index 1c3461be9c..fcfaee6440 100644 --- a/src/loaders/express/logging.ts +++ b/src/app/loaders/express/logging.ts @@ -2,9 +2,9 @@ import expressWinston from 'express-winston' import get from 'lodash/get' import winston from 'winston' -import { getRequestIp, getTrace } from '../../app/utils/request' import config from '../../config/config' import { customFormat } from '../../config/logger' +import { getRequestIp, getTrace } from '../../utils/request' const LOGGER_LABEL = 'network' diff --git a/src/loaders/express/parser.ts b/src/app/loaders/express/parser.ts similarity index 100% rename from src/loaders/express/parser.ts rename to src/app/loaders/express/parser.ts diff --git a/src/loaders/express/sentry.ts b/src/app/loaders/express/sentry.ts similarity index 100% rename from src/loaders/express/sentry.ts rename to src/app/loaders/express/sentry.ts diff --git a/src/loaders/express/session.ts b/src/app/loaders/express/session.ts similarity index 100% rename from src/loaders/express/session.ts rename to src/app/loaders/express/session.ts diff --git a/src/loaders/index.ts b/src/app/loaders/index.ts similarity index 100% rename from src/loaders/index.ts rename to src/app/loaders/index.ts diff --git a/src/loaders/mongoose.ts b/src/app/loaders/mongoose.ts similarity index 100% rename from src/loaders/mongoose.ts rename to src/app/loaders/mongoose.ts diff --git a/src/app/models/field/imageField.ts b/src/app/models/field/imageField.ts index f03a6fab3b..c2084fb7a5 100644 --- a/src/app/models/field/imageField.ts +++ b/src/app/models/field/imageField.ts @@ -1,8 +1,8 @@ import { Schema } from 'mongoose' import validator from 'validator' -import { isDev } from '../../../config/config' import { IImageFieldSchema } from '../../../types' +import { isDev } from '../../config/config' const createImageFieldSchema = () => { return new Schema({ diff --git a/src/app/modules/analytics/analytics.controller.ts b/src/app/modules/analytics/analytics.controller.ts index f42aaf21da..3609266d51 100644 --- a/src/app/modules/analytics/analytics.controller.ts +++ b/src/app/modules/analytics/analytics.controller.ts @@ -6,7 +6,7 @@ import { StatusCodes } from 'http-status-codes' import { AnalyticStatsDto } from 'src/types/analytics' -import { createLoggerWithLabel } from '../../../config/logger' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' import { diff --git a/src/app/modules/analytics/analytics.service.ts b/src/app/modules/analytics/analytics.service.ts index a36b35037b..9fa29d75a0 100644 --- a/src/app/modules/analytics/analytics.service.ts +++ b/src/app/modules/analytics/analytics.service.ts @@ -2,8 +2,8 @@ import * as TE from 'fp-ts/TaskEither' import mongoose from 'mongoose' import { getMongoErrorMessage } from '../../../app/utils/handle-mongo-error' -import { submissionsTopUp } from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' +import { submissionsTopUp } from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import getFormModel from '../../models/form.server.model' import getSubmissionModel from '../../models/submission.server.model' import getUserModel from '../../models/user.server.model' diff --git a/src/app/modules/auth/auth.controller.ts b/src/app/modules/auth/auth.controller.ts index 99839c600b..8eae149063 100644 --- a/src/app/modules/auth/auth.controller.ts +++ b/src/app/modules/auth/auth.controller.ts @@ -3,8 +3,8 @@ import { ParamsDictionary } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' import { isEmpty } from 'lodash' -import { createLoggerWithLabel } from '../../../config/logger' import { LINKS } from '../../../shared/constants' +import { createLoggerWithLabel } from '../../config/logger' import MailService from '../../services/mail/mail.service' import { createReqMeta, getRequestIp } from '../../utils/request' import * as UserService from '../user/user.service' diff --git a/src/app/modules/auth/auth.routes.ts b/src/app/modules/auth/auth.routes.ts index 3ef281e026..bd1d343669 100644 --- a/src/app/modules/auth/auth.routes.ts +++ b/src/app/modules/auth/auth.routes.ts @@ -1,7 +1,7 @@ import { celebrate, Joi, Segments } from 'celebrate' import { Router } from 'express' -import { rateLimitConfig } from '../../../config/config' +import { rateLimitConfig } from '../../config/config' import { limitRate } from '../../utils/limit-rate' import * as AuthController from './auth.controller' diff --git a/src/app/modules/auth/auth.service.ts b/src/app/modules/auth/auth.service.ts index c1d4946cd3..9bda20eb17 100644 --- a/src/app/modules/auth/auth.service.ts +++ b/src/app/modules/auth/auth.service.ts @@ -2,8 +2,6 @@ import mongoose from 'mongoose' import { errAsync, okAsync, ResultAsync } from 'neverthrow' import validator from 'validator' -import config from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' import { LINKS } from '../../../shared/constants' import { IAgencySchema, @@ -11,6 +9,8 @@ import { ITokenSchema, IUserSchema, } from '../../../types' +import config from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import getAgencyModel from '../../models/agency.server.model' import getTokenModel from '../../models/token.server.model' import { compareHash, HashingError } from '../../utils/hash' diff --git a/src/app/modules/auth/auth.utils.ts b/src/app/modules/auth/auth.utils.ts index 9985679382..b6de7e1d51 100644 --- a/src/app/modules/auth/auth.utils.ts +++ b/src/app/modules/auth/auth.utils.ts @@ -1,7 +1,7 @@ import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { MapRouteError } from '../../../types/routing' +import { createLoggerWithLabel } from '../../config/logger' import * as MailErrors from '../../services/mail/mail.errors' import { HashingError } from '../../utils/hash' import * as CoreErrors from '../core/core.errors' diff --git a/src/app/modules/billing/__tests__/billing.factory.spec.ts b/src/app/modules/billing/__tests__/billing.factory.spec.ts index e9ad83aebf..247ace448c 100644 --- a/src/app/modules/billing/__tests__/billing.factory.spec.ts +++ b/src/app/modules/billing/__tests__/billing.factory.spec.ts @@ -5,7 +5,7 @@ import { FeatureNames, ISpcpMyInfo, RegisteredFeature, -} from 'src/config/feature-manager' +} from 'src/app/config/feature-manager' import { AuthType, ILoginSchema, diff --git a/src/app/modules/billing/billing.controller.ts b/src/app/modules/billing/billing.controller.ts index 77d9e6fb3b..2d2886501c 100644 --- a/src/app/modules/billing/billing.controller.ts +++ b/src/app/modules/billing/billing.controller.ts @@ -3,8 +3,8 @@ import { ParamsDictionary } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' import moment from 'moment-timezone' -import { createLoggerWithLabel } from '../../../config/logger' import { BillingInfoDto, BillingQueryDto, ErrorDto } from '../../../types/api' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' import { BillingFactory } from './billing.factory' diff --git a/src/app/modules/billing/billing.factory.ts b/src/app/modules/billing/billing.factory.ts index dd5b0cdd14..9414cf225e 100644 --- a/src/app/modules/billing/billing.factory.ts +++ b/src/app/modules/billing/billing.factory.ts @@ -1,10 +1,10 @@ import { errAsync, okAsync, ResultAsync } from 'neverthrow' +import { ILoginSchema, IPopulatedForm } from '../../../types' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' -import { ILoginSchema, IPopulatedForm } from '../../../types' +} from '../../config/feature-manager' import { DatabaseError, MissingFeatureError } from '../core/core.errors' import { FormHasNoAuthError } from './billing.errors' diff --git a/src/app/modules/billing/billing.service.ts b/src/app/modules/billing/billing.service.ts index 2d50279c7e..6045e9b3c6 100644 --- a/src/app/modules/billing/billing.service.ts +++ b/src/app/modules/billing/billing.service.ts @@ -7,13 +7,13 @@ import mongoose from 'mongoose' import { errAsync, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../config/logger' import { AuthType, ILoginSchema, IPopulatedForm, LoginStatistic, } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import getLoginModel from '../../models/login.server.model' import { getMongoErrorMessage } from '../../utils/handle-mongo-error' import { DatabaseError } from '../core/core.errors' diff --git a/src/app/modules/bounce/__tests__/bounce.service.spec.ts b/src/app/modules/bounce/__tests__/bounce.service.spec.ts index 8e5e773660..47724c6959 100644 --- a/src/app/modules/bounce/__tests__/bounce.service.spec.ts +++ b/src/app/modules/bounce/__tests__/bounce.service.spec.ts @@ -8,12 +8,12 @@ import mongoose from 'mongoose' import { errAsync, okAsync } from 'neverthrow' import { mocked } from 'ts-jest/utils' +import * as LoggerModule from 'src/app/config/logger' import getFormModel from 'src/app/models/form.server.model' import * as UserService from 'src/app/modules/user/user.service' import { EMAIL_HEADERS, EmailType } from 'src/app/services/mail/mail.constants' import MailService from 'src/app/services/mail/mail.service' import { SmsFactory } from 'src/app/services/sms/sms.factory' -import * as LoggerModule from 'src/config/logger' import { BounceType, IPopulatedForm, diff --git a/src/app/modules/bounce/bounce.controller.ts b/src/app/modules/bounce/bounce.controller.ts index 074be5ff54..5bffc1b6de 100644 --- a/src/app/modules/bounce/bounce.controller.ts +++ b/src/app/modules/bounce/bounce.controller.ts @@ -1,8 +1,8 @@ import { RequestHandler } from 'express' import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { ISnsNotification } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { EmailType } from '../../services/mail/mail.constants' import { DatabaseConflictError } from '../core/core.errors' import * as FormService from '../form/form.service' diff --git a/src/app/modules/bounce/bounce.model.ts b/src/app/modules/bounce/bounce.model.ts index de7d7f4d47..da20085f46 100644 --- a/src/app/modules/bounce/bounce.model.ts +++ b/src/app/modules/bounce/bounce.model.ts @@ -2,7 +2,6 @@ import { keyBy } from 'lodash' import { Model, Mongoose, Schema } from 'mongoose' import validator from 'validator' -import { bounceLifeSpan } from '../../../config/config' import { BounceType, IBounceSchema, @@ -10,6 +9,7 @@ import { ISingleBounce, UserContactView, } from '../../../types' +import { bounceLifeSpan } from '../../config/config' import { FORM_SCHEMA_ID } from '../../models/form.server.model' import { hasEmailBeenDelivered, hasEmailBounced } from './bounce.util' diff --git a/src/app/modules/bounce/bounce.service.ts b/src/app/modules/bounce/bounce.service.ts index 78d9173bb6..fa31c17aba 100644 --- a/src/app/modules/bounce/bounce.service.ts +++ b/src/app/modules/bounce/bounce.service.ts @@ -10,10 +10,6 @@ import { ResultAsync, } from 'neverthrow' -import { - createCloudWatchLogger, - createLoggerWithLabel, -} from '../../../config/logger' import { BounceType, IBounceSchema, @@ -21,6 +17,10 @@ import { IPopulatedForm, ISnsNotification, } from '../../../types' +import { + createCloudWatchLogger, + createLoggerWithLabel, +} from '../../config/logger' import { EMAIL_HEADERS, EmailType } from '../../services/mail/mail.constants' import MailService from '../../services/mail/mail.service' import { SmsFactory } from '../../services/sms/sms.factory' diff --git a/src/app/modules/core/core.errors.ts b/src/app/modules/core/core.errors.ts index 95282fd36e..9bf9e2ae45 100644 --- a/src/app/modules/core/core.errors.ts +++ b/src/app/modules/core/core.errors.ts @@ -1,4 +1,4 @@ -import { FeatureNames } from 'src/config/feature-manager' +import { FeatureNames } from '../../config/feature-manager' /** * A custom base error class that encapsulates the name, message, status code, diff --git a/src/app/modules/examples/__tests__/examples.factory.spec.ts b/src/app/modules/examples/__tests__/examples.factory.spec.ts index f2e5c8d083..21089076a3 100644 --- a/src/app/modules/examples/__tests__/examples.factory.spec.ts +++ b/src/app/modules/examples/__tests__/examples.factory.spec.ts @@ -4,7 +4,7 @@ import { FeatureNames, IAggregateStats, RegisteredFeature, -} from 'src/config/feature-manager' +} from 'src/app/config/feature-manager' import { createExamplesFactory } from '../examples.factory' import * as ExamplesService from '../examples.service' diff --git a/src/app/modules/examples/examples.controller.ts b/src/app/modules/examples/examples.controller.ts index df080efa23..b1586aa833 100644 --- a/src/app/modules/examples/examples.controller.ts +++ b/src/app/modules/examples/examples.controller.ts @@ -2,13 +2,13 @@ import { RequestHandler } from 'express' import { ParamsDictionary, Query } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { ErrorDto, ExampleFormsQueryDto, ExampleFormsResult, ExampleSingleFormResult, } from '../../../types/api' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' import { ExamplesFactory } from './examples.factory' diff --git a/src/app/modules/examples/examples.factory.ts b/src/app/modules/examples/examples.factory.ts index 34677052ba..44ea0cfa3b 100644 --- a/src/app/modules/examples/examples.factory.ts +++ b/src/app/modules/examples/examples.factory.ts @@ -1,7 +1,7 @@ import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import * as ExamplesService from './examples.service' import { RetrievalType } from './examples.types' diff --git a/src/app/modules/examples/examples.service.ts b/src/app/modules/examples/examples.service.ts index 3ca8f7ba31..52fbc4c3a0 100644 --- a/src/app/modules/examples/examples.service.ts +++ b/src/app/modules/examples/examples.service.ts @@ -3,7 +3,7 @@ import mongoose from 'mongoose' import { errAsync, okAsync, ResultAsync } from 'neverthrow' import { Except, Merge } from 'type-fest' -import { createLoggerWithLabel } from '../../../config/logger' +import { createLoggerWithLabel } from '../../config/logger' import getFormModel from '../../models/form.server.model' import getFormStatisticsTotalModel from '../../models/form_statistics_total.server.model' import getSubmissionModel from '../../models/submission.server.model' diff --git a/src/app/modules/examples/examples.utils.ts b/src/app/modules/examples/examples.utils.ts index d6d02ee753..5024e043fb 100644 --- a/src/app/modules/examples/examples.utils.ts +++ b/src/app/modules/examples/examples.utils.ts @@ -1,8 +1,8 @@ import { StatusCodes } from 'http-status-codes' import moment from 'moment-timezone' -import { createLoggerWithLabel } from '../../../config/logger' import { MapRouteError } from '../../../types/routing' +import { createLoggerWithLabel } from '../../config/logger' import { DatabaseError } from '../core/core.errors' import { ResultsNotFoundError } from './examples.errors' diff --git a/src/app/modules/feedback/feedback.service.ts b/src/app/modules/feedback/feedback.service.ts index 8156a8624d..919dde1860 100644 --- a/src/app/modules/feedback/feedback.service.ts +++ b/src/app/modules/feedback/feedback.service.ts @@ -3,8 +3,8 @@ import moment from 'moment-timezone' import mongoose from 'mongoose' import { ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../config/logger' import { IFormFeedbackSchema } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import getFormFeedbackModel from '../../models/form_feedback.server.model' import { getMongoErrorMessage } from '../../utils/handle-mongo-error' import { DatabaseError } from '../core/core.errors' diff --git a/src/app/modules/form/admin-form/__tests__/admin-form.routes.spec.ts b/src/app/modules/form/admin-form/__tests__/admin-form.routes.spec.ts index 47bbf64f93..837c9eeeec 100644 --- a/src/app/modules/form/admin-form/__tests__/admin-form.routes.spec.ts +++ b/src/app/modules/form/admin-form/__tests__/admin-form.routes.spec.ts @@ -7,6 +7,7 @@ import { errAsync, okAsync } from 'neverthrow' import SparkMD5 from 'spark-md5' import supertest, { Session } from 'supertest-session' +import { aws } from 'src/app/config/config' import getFormModel, { getEmailFormModel, getEncryptedFormModel, @@ -35,7 +36,6 @@ import { } from 'src/app/modules/submission/email-submission/__tests__/email-submission.test.constants' import { saveSubmissionMetadata } from 'src/app/modules/submission/email-submission/email-submission.service' import { SubmissionHash } from 'src/app/modules/submission/email-submission/email-submission.types' -import { aws } from 'src/config/config' import { EditFieldActions, VALID_UPLOAD_FILE_TYPES } from 'src/shared/constants' import { BasicField, diff --git a/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts b/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts index f24f930260..db632f7da3 100644 --- a/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts +++ b/src/app/modules/form/admin-form/__tests__/admin-form.service.spec.ts @@ -5,6 +5,7 @@ import mongoose from 'mongoose' import { err, errAsync, ok, okAsync } from 'neverthrow' import { mocked } from 'ts-jest/utils' +import { aws } from 'src/app/config/config' import getFormModel, { getEmailFormModel, getEncryptedFormModel, @@ -18,7 +19,6 @@ import { import { MissingUserError } from 'src/app/modules/user/user.errors' import * as UserService from 'src/app/modules/user/user.service' import { formatErrorRecoveryMessage } from 'src/app/utils/handle-mongo-error' -import { aws } from 'src/config/config' import { EditFieldActions, VALID_UPLOAD_FILE_TYPES } from 'src/shared/constants' import { AuthType, diff --git a/src/app/modules/form/admin-form/admin-form.controller.ts b/src/app/modules/form/admin-form/admin-form.controller.ts index 95516eb76b..5f1e409225 100644 --- a/src/app/modules/form/admin-form/admin-form.controller.ts +++ b/src/app/modules/form/admin-form/admin-form.controller.ts @@ -4,7 +4,6 @@ import { StatusCodes } from 'http-status-codes' import JSONStream from 'JSONStream' import { ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../../config/logger' import { AuthType, FieldResponse, @@ -17,6 +16,7 @@ import { ErrorDto, SettingsUpdateDto, } from '../../../../types/api' +import { createLoggerWithLabel } from '../../../config/logger' import MailService from '../../../services/mail/mail.service' import { checkIsEncryptedEncoding } from '../../../utils/encryption' import { createReqMeta } from '../../../utils/request' diff --git a/src/app/modules/form/admin-form/admin-form.service.ts b/src/app/modules/form/admin-form/admin-form.service.ts index cac0f76728..461bc64906 100644 --- a/src/app/modules/form/admin-form/admin-form.service.ts +++ b/src/app/modules/form/admin-form/admin-form.service.ts @@ -4,8 +4,6 @@ import mongoose from 'mongoose' import { errAsync, okAsync, ResultAsync } from 'neverthrow' import { Except, Merge } from 'type-fest' -import { aws as AwsConfig } from '../../../../config/config' -import { createLoggerWithLabel } from '../../../../config/logger' import { MAX_UPLOAD_FILE_SIZE, VALID_UPLOAD_FILE_TYPES, @@ -22,6 +20,8 @@ import { IUserSchema, } from '../../../../types' import { SettingsUpdateDto } from '../../../../types/api' +import { aws as AwsConfig } from '../../../config/config' +import { createLoggerWithLabel } from '../../../config/logger' import getFormModel from '../../../models/form.server.model' import { dotifyObject } from '../../../utils/dotify-object' import { diff --git a/src/app/modules/form/admin-form/admin-form.utils.ts b/src/app/modules/form/admin-form/admin-form.utils.ts index 957ccfd7f7..6f6009a3b4 100644 --- a/src/app/modules/form/admin-form/admin-form.utils.ts +++ b/src/app/modules/form/admin-form/admin-form.utils.ts @@ -1,7 +1,6 @@ import { StatusCodes } from 'http-status-codes' import { err, ok, Result } from 'neverthrow' -import { createLoggerWithLabel } from '../../../../config/logger' import { EditFieldActions } from '../../../../shared/constants' import { IFieldSchema, @@ -9,6 +8,7 @@ import { ResponseMode, Status, } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import { reorder, replaceAt } from '../../../utils/immutable-array-fns' import { ApplicationError, diff --git a/src/app/modules/form/form.service.ts b/src/app/modules/form/form.service.ts index 5ff5e62333..dd668230a7 100644 --- a/src/app/modules/form/form.service.ts +++ b/src/app/modules/form/form.service.ts @@ -1,7 +1,6 @@ import mongoose from 'mongoose' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../config/logger' import { AuthType, IEmailFormModel, @@ -11,6 +10,7 @@ import { ResponseMode, Status, } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import getFormModel, { getEmailFormModel, getEncryptedFormModel, diff --git a/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts b/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts index e18cce6cdd..2d592f65e1 100644 --- a/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts +++ b/src/app/modules/form/public-form/__tests__/public-form.controller.spec.ts @@ -6,6 +6,7 @@ import { err, errAsync, ok, okAsync } from 'neverthrow' import querystring from 'querystring' import { mocked } from 'ts-jest/utils' +import { FeatureNames } from 'src/app/config/feature-manager/types' import getFormFeedbackModel from 'src/app/models/form_feedback.server.model' import { DatabaseError, @@ -20,7 +21,6 @@ import { } from 'src/app/modules/myinfo/myinfo.errors' import { MyInfoCookieState } from 'src/app/modules/myinfo/myinfo.types' import { JwtPayload } from 'src/app/modules/spcp/spcp.types' -import { FeatureNames } from 'src/config/feature-manager/types' import { AuthType, IPopulatedForm, diff --git a/src/app/modules/form/public-form/public-form.controller.ts b/src/app/modules/form/public-form/public-form.controller.ts index 90034261da..52d0fab2f0 100644 --- a/src/app/modules/form/public-form/public-form.controller.ts +++ b/src/app/modules/form/public-form/public-form.controller.ts @@ -3,9 +3,9 @@ import { StatusCodes } from 'http-status-codes' import querystring from 'querystring' import { UnreachableCaseError } from 'ts-essentials' -import { createLoggerWithLabel } from '../../../../config/logger' import { AuthType } from '../../../../types' import { ErrorDto } from '../../../../types/api' +import { createLoggerWithLabel } from '../../../config/logger' import { isMongoError } from '../../../utils/handle-mongo-error' import { createReqMeta, getRequestIp } from '../../../utils/request' import { getFormIfPublic } from '../../auth/auth.service' diff --git a/src/app/modules/form/public-form/public-form.service.ts b/src/app/modules/form/public-form/public-form.service.ts index 6d924cea1d..4548f2146a 100644 --- a/src/app/modules/form/public-form/public-form.service.ts +++ b/src/app/modules/form/public-form/public-form.service.ts @@ -1,8 +1,8 @@ import mongoose from 'mongoose' import { errAsync, okAsync, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../../config/logger' import { IFormFeedbackSchema } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import getFormModel from '../../../models/form.server.model' import getFormFeedbackModel from '../../../models/form_feedback.server.model' import { DatabaseError } from '../../core/core.errors' diff --git a/src/app/modules/form/public-form/public-form.utils.ts b/src/app/modules/form/public-form/public-form.utils.ts index f1d6326b9b..bf7b73f574 100644 --- a/src/app/modules/form/public-form/public-form.utils.ts +++ b/src/app/modules/form/public-form/public-form.utils.ts @@ -1,6 +1,6 @@ import { getReasonPhrase, StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../../config/logger' +import { createLoggerWithLabel } from '../../../config/logger' import { ApplicationError, DatabaseError } from '../../core/core.errors' import { ErrorResponseData } from '../../core/core.types' import * as FormErrors from '../form.errors' diff --git a/src/app/modules/frontend/__tests__/google-analytics.factory.spec.ts b/src/app/modules/frontend/__tests__/google-analytics.factory.spec.ts index a868f00c09..a25e3d1ec1 100644 --- a/src/app/modules/frontend/__tests__/google-analytics.factory.spec.ts +++ b/src/app/modules/frontend/__tests__/google-analytics.factory.spec.ts @@ -1,6 +1,6 @@ import { StatusCodes } from 'http-status-codes' -import { FeatureNames, RegisteredFeature } from 'src/config/feature-manager' +import { FeatureNames, RegisteredFeature } from 'src/app/config/feature-manager' import expressHandler from 'tests/unit/backend/helpers/jest-express' diff --git a/src/app/modules/frontend/frontend.controller.ts b/src/app/modules/frontend/frontend.controller.ts index 32f54e6a02..0f5351210e 100644 --- a/src/app/modules/frontend/frontend.controller.ts +++ b/src/app/modules/frontend/frontend.controller.ts @@ -3,8 +3,8 @@ import { RequestHandler } from 'express' import { ParamsDictionary } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' -import featureManager from '../../../config/feature-manager' -import { createLoggerWithLabel } from '../../../config/logger' +import featureManager from '../../config/feature-manager' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' const logger = createLoggerWithLabel(module) diff --git a/src/app/modules/frontend/google-analytics.factory.ts b/src/app/modules/frontend/google-analytics.factory.ts index 4f9eaa55d8..9132d32f92 100644 --- a/src/app/modules/frontend/google-analytics.factory.ts +++ b/src/app/modules/frontend/google-analytics.factory.ts @@ -5,7 +5,7 @@ import { StatusCodes } from 'http-status-codes' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import * as FrontendServerController from './frontend.controller' diff --git a/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts b/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts index 932d5200ca..e59ef14b21 100644 --- a/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts +++ b/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts @@ -1,7 +1,7 @@ import { mocked } from 'ts-jest/utils' -import config from 'src/config/config' -import { ISpcpMyInfo } from 'src/config/feature-manager' +import config from 'src/app/config/config' +import { ISpcpMyInfo } from 'src/app/config/feature-manager' import { Environment, IPopulatedForm } from 'src/types' import { MyInfoData } from '../myinfo.adapter' diff --git a/src/app/modules/myinfo/__tests__/myinfo.test.constants.ts b/src/app/modules/myinfo/__tests__/myinfo.test.constants.ts index 033b77af50..2056029180 100644 --- a/src/app/modules/myinfo/__tests__/myinfo.test.constants.ts +++ b/src/app/modules/myinfo/__tests__/myinfo.test.constants.ts @@ -7,7 +7,7 @@ import { import { ObjectId } from 'bson' import { merge, omit, zipWith } from 'lodash' -import { ISpcpMyInfo } from 'src/config/feature-manager' +import { ISpcpMyInfo } from 'src/app/config/feature-manager' import { AuthType, Environment, IFormSchema, MyInfoAttribute } from 'src/types' import { diff --git a/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts b/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts index da1d754444..99c3673d46 100644 --- a/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts +++ b/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts @@ -4,7 +4,7 @@ import { omit, pick } from 'lodash' import mongoose from 'mongoose' import { mocked } from 'ts-jest/utils' -import config from 'src/config/config' +import config from 'src/app/config/config' import dbHandler from '../../../../../tests/unit/backend/helpers/jest-db' diff --git a/src/app/modules/myinfo/myinfo.constants.ts b/src/app/modules/myinfo/myinfo.constants.ts index 389062ef15..5b8b61e206 100644 --- a/src/app/modules/myinfo/myinfo.constants.ts +++ b/src/app/modules/myinfo/myinfo.constants.ts @@ -1,4 +1,4 @@ -import config from '../../../config/config' +import config from '../../config/config' /** * Top-level router prefix to be used for MyInfo routes. diff --git a/src/app/modules/myinfo/myinfo.controller.ts b/src/app/modules/myinfo/myinfo.controller.ts index f19fd923a6..84ab16abfe 100644 --- a/src/app/modules/myinfo/myinfo.controller.ts +++ b/src/app/modules/myinfo/myinfo.controller.ts @@ -3,8 +3,8 @@ import { Request } from 'express' import { Query, RequestHandler } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { AuthType } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' import { BillingFactory } from '../billing/billing.factory' import * as FormService from '../form/form.service' diff --git a/src/app/modules/myinfo/myinfo.factory.ts b/src/app/modules/myinfo/myinfo.factory.ts index d7f51b04b6..479e4113e9 100644 --- a/src/app/modules/myinfo/myinfo.factory.ts +++ b/src/app/modules/myinfo/myinfo.factory.ts @@ -1,17 +1,17 @@ import { LeanDocument } from 'mongoose' import { err, errAsync, Result, ResultAsync } from 'neverthrow' -import config from '../../../config/config' -import FeatureManager, { - FeatureNames, - RegisteredFeature, -} from '../../../config/feature-manager' import { IFieldSchema, IHashes, IMyInfoHashSchema, IPopulatedForm, } from '../../../types' +import config from '../../config/config' +import FeatureManager, { + FeatureNames, + RegisteredFeature, +} from '../../config/feature-manager' import { DatabaseError, MissingFeatureError } from '../core/core.errors' import { ProcessedFieldResponse } from '../submission/submission.types' diff --git a/src/app/modules/myinfo/myinfo.format.ts b/src/app/modules/myinfo/myinfo.format.ts index 126522ed47..899c5281a1 100644 --- a/src/app/modules/myinfo/myinfo.format.ts +++ b/src/app/modules/myinfo/myinfo.format.ts @@ -10,7 +10,7 @@ import { MyInfoVehicle, } from '@opengovsg/myinfo-gov-client' -import { createLoggerWithLabel } from '../../../config/logger' +import { createLoggerWithLabel } from '../../config/logger' const logger = createLoggerWithLabel(module) diff --git a/src/app/modules/myinfo/myinfo.service.ts b/src/app/modules/myinfo/myinfo.service.ts index 99e5062269..020aeb4543 100644 --- a/src/app/modules/myinfo/myinfo.service.ts +++ b/src/app/modules/myinfo/myinfo.service.ts @@ -10,7 +10,6 @@ import mongoose, { LeanDocument } from 'mongoose' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' import CircuitBreaker from 'opossum' -import { createLoggerWithLabel } from '../../../config/logger' import { Environment, IFieldSchema, @@ -19,6 +18,7 @@ import { IPopulatedForm, MyInfoAttribute, } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { DatabaseError, MissingFeatureError } from '../core/core.errors' import { ProcessedFieldResponse } from '../submission/submission.types' diff --git a/src/app/modules/myinfo/myinfo.types.ts b/src/app/modules/myinfo/myinfo.types.ts index 2be487cad8..d472230e07 100644 --- a/src/app/modules/myinfo/myinfo.types.ts +++ b/src/app/modules/myinfo/myinfo.types.ts @@ -1,6 +1,5 @@ import { LeanDocument } from 'mongoose' -import { ISpcpMyInfo } from '../../../config/feature-manager' import { AuthType, Environment, @@ -9,6 +8,7 @@ import { IMyInfo, MyInfoAttribute, } from '../../../types' +import { ISpcpMyInfo } from '../../config/feature-manager' import { ProcessedFieldResponse } from '../submission/submission.types' export interface IMyInfoServiceConfig { diff --git a/src/app/modules/myinfo/myinfo.util.ts b/src/app/modules/myinfo/myinfo.util.ts index 4f5ef51a33..87629fa864 100644 --- a/src/app/modules/myinfo/myinfo.util.ts +++ b/src/app/modules/myinfo/myinfo.util.ts @@ -5,7 +5,6 @@ import mongoose from 'mongoose' import { err, ok, Result } from 'neverthrow' import { v4 as uuidv4, validate as validateUUID } from 'uuid' -import { createLoggerWithLabel } from '../../../config/logger' import { types as myInfoTypes } from '../../../shared/resources/myinfo' import { AuthType, @@ -16,6 +15,7 @@ import { IPopulatedForm, MapRouteError, } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { hasProp } from '../../utils/has-prop' import { DatabaseError, MissingFeatureError } from '../core/core.errors' import { FormNotFoundError } from '../form/form.errors' diff --git a/src/app/modules/myinfo/myinfo_hash.model.ts b/src/app/modules/myinfo/myinfo_hash.model.ts index 03f95905f9..bf4c168a8c 100644 --- a/src/app/modules/myinfo/myinfo_hash.model.ts +++ b/src/app/modules/myinfo/myinfo_hash.model.ts @@ -1,8 +1,8 @@ import crypto from 'crypto' import { Mongoose, Schema } from 'mongoose' -import { sessionSecret } from '../../../config/config' import { IHashes, IMyInfoHashModel, IMyInfoHashSchema } from '../../../types' +import { sessionSecret } from '../../config/config' import { FORM_SCHEMA_ID } from '../../models/form.server.model' export const MYINFO_HASH_SCHEMA_ID = 'MyInfoHash' diff --git a/src/app/modules/spcp/__tests__/spcp.controller.spec.ts b/src/app/modules/spcp/__tests__/spcp.controller.spec.ts index aed79f1e3f..31fba20d34 100644 --- a/src/app/modules/spcp/__tests__/spcp.controller.spec.ts +++ b/src/app/modules/spcp/__tests__/spcp.controller.spec.ts @@ -1,9 +1,9 @@ import { err, errAsync, ok, okAsync } from 'neverthrow' import { mocked } from 'ts-jest/utils' +import config from 'src/app/config/config' import * as FormService from 'src/app/modules/form/form.service' import { MOCK_COOKIE_AGE } from 'src/app/modules/myinfo/__tests__/myinfo.test.constants' -import config from 'src/config/config' import { AuthType } from 'src/types' import expressHandler from 'tests/unit/backend/helpers/jest-express' diff --git a/src/app/modules/spcp/__tests__/spcp.factory.spec.ts b/src/app/modules/spcp/__tests__/spcp.factory.spec.ts index 7d8903e1dc..b7fb6db682 100644 --- a/src/app/modules/spcp/__tests__/spcp.factory.spec.ts +++ b/src/app/modules/spcp/__tests__/spcp.factory.spec.ts @@ -1,6 +1,6 @@ import { mocked } from 'ts-jest/utils' -import { FeatureNames, ISpcpMyInfo } from 'src/config/feature-manager' +import { FeatureNames, ISpcpMyInfo } from 'src/app/config/feature-manager' import { AuthType } from 'src/types' import { MissingFeatureError } from '../../core/core.errors' diff --git a/src/app/modules/spcp/__tests__/spcp.service.spec.ts b/src/app/modules/spcp/__tests__/spcp.service.spec.ts index dc20f58a5f..2d72705590 100644 --- a/src/app/modules/spcp/__tests__/spcp.service.spec.ts +++ b/src/app/modules/spcp/__tests__/spcp.service.spec.ts @@ -4,8 +4,8 @@ import fs from 'fs' import { omit } from 'lodash' import { mocked } from 'ts-jest/utils' +import { ISpcpMyInfo } from 'src/app/config/feature-manager' import { MOCK_COOKIE_AGE } from 'src/app/modules/myinfo/__tests__/myinfo.test.constants' -import { ISpcpMyInfo } from 'src/config/feature-manager' import { AuthType } from 'src/types' import dbHandler from 'tests/unit/backend/helpers/jest-db' diff --git a/src/app/modules/spcp/__tests__/spcp.test.constants.ts b/src/app/modules/spcp/__tests__/spcp.test.constants.ts index 2a036f4a12..10dbe981c8 100644 --- a/src/app/modules/spcp/__tests__/spcp.test.constants.ts +++ b/src/app/modules/spcp/__tests__/spcp.test.constants.ts @@ -3,7 +3,7 @@ import { ObjectId } from 'bson' import crypto from 'crypto' import _ from 'lodash' -import { ISpcpMyInfo } from 'src/config/feature-manager' +import { ISpcpMyInfo } from 'src/app/config/feature-manager' import { ILoginSchema, IPopulatedForm } from 'src/types' import { JwtName } from '../spcp.types' diff --git a/src/app/modules/spcp/spcp.controller.ts b/src/app/modules/spcp/spcp.controller.ts index 77f7c6c082..4e747b9f98 100644 --- a/src/app/modules/spcp/spcp.controller.ts +++ b/src/app/modules/spcp/spcp.controller.ts @@ -2,9 +2,9 @@ import { RequestHandler } from 'express' import { ParamsDictionary } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' -import config from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' import { AuthType } from '../../../types' +import config from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta } from '../../utils/request' import { BillingFactory } from '../billing/billing.factory' import * as FormService from '../form/form.service' diff --git a/src/app/modules/spcp/spcp.factory.ts b/src/app/modules/spcp/spcp.factory.ts index 5df9aaf191..0b5efb3437 100644 --- a/src/app/modules/spcp/spcp.factory.ts +++ b/src/app/modules/spcp/spcp.factory.ts @@ -3,7 +3,7 @@ import { err, errAsync } from 'neverthrow' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../core/core.errors' import { SpcpService } from './spcp.service' diff --git a/src/app/modules/spcp/spcp.service.ts b/src/app/modules/spcp/spcp.service.ts index 81e353c2a0..468b544aac 100644 --- a/src/app/modules/spcp/spcp.service.ts +++ b/src/app/modules/spcp/spcp.service.ts @@ -4,9 +4,9 @@ import fs from 'fs' import { StatusCodes } from 'http-status-codes' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' -import { ISpcpMyInfo } from '../../../config/feature-manager' -import { createLoggerWithLabel } from '../../../config/logger' import { AuthType } from '../../../types' +import { ISpcpMyInfo } from '../../config/feature-manager' +import { createLoggerWithLabel } from '../../config/logger' import { ApplicationError } from '../core/core.errors' import { diff --git a/src/app/modules/spcp/spcp.util.ts b/src/app/modules/spcp/spcp.util.ts index 9c12577194..c802aded61 100644 --- a/src/app/modules/spcp/spcp.util.ts +++ b/src/app/modules/spcp/spcp.util.ts @@ -2,8 +2,8 @@ import SPCPAuthClient from '@opengovsg/spcp-auth-client' import crypto from 'crypto' import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { BasicField, MapRouteError, SPCPFieldTitle } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { hasProp } from '../../utils/has-prop' import { MissingFeatureError } from '../core/core.errors' import { ProcessedSingleAnswerResponse } from '../submission/submission.types' diff --git a/src/app/modules/submission/email-submission/email-submission.controller.ts b/src/app/modules/submission/email-submission/email-submission.controller.ts index bc751f0c92..87af5cbe68 100644 --- a/src/app/modules/submission/email-submission/email-submission.controller.ts +++ b/src/app/modules/submission/email-submission/email-submission.controller.ts @@ -1,7 +1,7 @@ import { Request, RequestHandler } from 'express' -import { createLoggerWithLabel } from '../../../../config/logger' import { AuthType, FieldResponse } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import { CaptchaFactory } from '../../../services/captcha/captcha.factory' import MailService from '../../../services/mail/mail.service' import { createReqMeta, getRequestIp } from '../../../utils/request' diff --git a/src/app/modules/submission/email-submission/email-submission.middleware.ts b/src/app/modules/submission/email-submission/email-submission.middleware.ts index 8c85e8acd6..89d5ec2acb 100644 --- a/src/app/modules/submission/email-submission/email-submission.middleware.ts +++ b/src/app/modules/submission/email-submission/email-submission.middleware.ts @@ -2,8 +2,8 @@ import { celebrate, Joi } from 'celebrate' import { RequestHandler } from 'express' import { ParamsDictionary } from 'express-serve-static-core' -import { createLoggerWithLabel } from '../../../../config/logger' import { BasicField, FieldResponse } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import { createReqMeta } from '../../../utils/request' import * as EmailSubmissionReceiver from './email-submission.receiver' diff --git a/src/app/modules/submission/email-submission/email-submission.receiver.ts b/src/app/modules/submission/email-submission/email-submission.receiver.ts index bc741651b3..47d2c2c7a7 100644 --- a/src/app/modules/submission/email-submission/email-submission.receiver.ts +++ b/src/app/modules/submission/email-submission/email-submission.receiver.ts @@ -2,8 +2,8 @@ import Busboy from 'busboy' import { IncomingHttpHeaders } from 'http' import { err, ok, Result, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../../config/logger' import { IAttachmentInfo } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import { MB } from '../../../constants/filesize' import { diff --git a/src/app/modules/submission/email-submission/email-submission.routes.ts b/src/app/modules/submission/email-submission/email-submission.routes.ts index 8827e849a9..c3c833b77e 100644 --- a/src/app/modules/submission/email-submission/email-submission.routes.ts +++ b/src/app/modules/submission/email-submission/email-submission.routes.ts @@ -1,6 +1,6 @@ import { Router } from 'express' -import { rateLimitConfig } from '../../../../config/config' +import { rateLimitConfig } from '../../../config/config' import { CaptchaFactory } from '../../../services/captcha/captcha.factory' import { limitRate } from '../../../utils/limit-rate' diff --git a/src/app/modules/submission/email-submission/email-submission.service.ts b/src/app/modules/submission/email-submission/email-submission.service.ts index 90c3d30408..3cce3c4b53 100644 --- a/src/app/modules/submission/email-submission/email-submission.service.ts +++ b/src/app/modules/submission/email-submission/email-submission.service.ts @@ -2,7 +2,6 @@ import crypto from 'crypto' import mongoose from 'mongoose' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../../config/logger' import { BasicField, EmailAdminDataField, @@ -14,6 +13,7 @@ import { ResponseMode, SubmissionType, } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import { getEmailSubmissionModel } from '../../../models/submission.server.model' import { DatabaseError } from '../../core/core.errors' import { isEmailModeForm, transformEmails } from '../../form/form.utils' diff --git a/src/app/modules/submission/email-submission/email-submission.util.ts b/src/app/modules/submission/email-submission/email-submission.util.ts index c327a93fa6..710d183df4 100644 --- a/src/app/modules/submission/email-submission/email-submission.util.ts +++ b/src/app/modules/submission/email-submission/email-submission.util.ts @@ -1,7 +1,6 @@ import { StatusCodes } from 'http-status-codes' import { compact, flattenDeep, sumBy } from 'lodash' -import { createLoggerWithLabel } from '../../../../config/logger' import { FilePlatforms } from '../../../../shared/constants' import * as FileValidation from '../../../../shared/util/file-validation' import { @@ -18,6 +17,7 @@ import { MapRouteError, SPCPFieldTitle, } from '../../../../types' +import { createLoggerWithLabel } from '../../../config/logger' import { CaptchaConnectionError, MissingCaptchaError, diff --git a/src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.service.spec.ts b/src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.service.spec.ts index 65fb082ccf..e993724b43 100644 --- a/src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.service.spec.ts +++ b/src/app/modules/submission/encrypt-submission/__tests__/encrypt-submission.service.spec.ts @@ -4,6 +4,7 @@ import { clone } from 'lodash' import mongoose from 'mongoose' import { PassThrough, Transform } from 'stream' +import { aws } from 'src/app/config/config' import { getEncryptSubmissionModel } from 'src/app/models/submission.server.model' import { DatabaseError, @@ -11,7 +12,6 @@ import { } from 'src/app/modules/core/core.errors' import { CreatePresignedUrlError } from 'src/app/modules/form/admin-form/admin-form.errors' import { formatErrorRecoveryMessage } from 'src/app/utils/handle-mongo-error' -import { aws } from 'src/config/config' import { IPopulatedEncryptedForm, SubmissionCursorData, diff --git a/src/app/modules/submission/encrypt-submission/encrypt-submission.controller.ts b/src/app/modules/submission/encrypt-submission/encrypt-submission.controller.ts index 75fe9dc5e1..63d178911e 100644 --- a/src/app/modules/submission/encrypt-submission/encrypt-submission.controller.ts +++ b/src/app/modules/submission/encrypt-submission/encrypt-submission.controller.ts @@ -5,13 +5,13 @@ import JSONStream from 'JSONStream' import mongoose from 'mongoose' import { SetOptional } from 'type-fest' -import { createLoggerWithLabel } from '../../../../config/logger' import { AuthType, EncryptedSubmissionDto, SubmissionMetadataList, } from '../../../../types' import { EncryptSubmissionDto, ErrorDto } from '../../../../types/api' +import { createLoggerWithLabel } from '../../../config/logger' import { getEncryptSubmissionModel } from '../../../models/submission.server.model' import { CaptchaFactory } from '../../../services/captcha/captcha.factory' import { checkIsEncryptedEncoding } from '../../../utils/encryption' diff --git a/src/app/modules/submission/encrypt-submission/encrypt-submission.routes.ts b/src/app/modules/submission/encrypt-submission/encrypt-submission.routes.ts index f9a6a80fbe..2d70d01df6 100644 --- a/src/app/modules/submission/encrypt-submission/encrypt-submission.routes.ts +++ b/src/app/modules/submission/encrypt-submission/encrypt-submission.routes.ts @@ -1,6 +1,6 @@ import { Router } from 'express' -import { rateLimitConfig } from '../../../../config/config' +import { rateLimitConfig } from '../../../config/config' import { CaptchaFactory } from '../../../services/captcha/captcha.factory' import { limitRate } from '../../../utils/limit-rate' diff --git a/src/app/modules/submission/encrypt-submission/encrypt-submission.service.ts b/src/app/modules/submission/encrypt-submission/encrypt-submission.service.ts index 1784312fa9..2ef8cc81f6 100644 --- a/src/app/modules/submission/encrypt-submission/encrypt-submission.service.ts +++ b/src/app/modules/submission/encrypt-submission/encrypt-submission.service.ts @@ -5,8 +5,6 @@ import mongoose from 'mongoose' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' import { Transform } from 'stream' -import { aws as AwsConfig } from '../../../../config/config' -import { createLoggerWithLabel } from '../../../../config/logger' import { IEncryptedSubmissionSchema, IPopulatedEncryptedForm, @@ -17,6 +15,8 @@ import { SubmissionMetadata, SubmissionMetadataList, } from '../../../../types' +import { aws as AwsConfig } from '../../../config/config' +import { createLoggerWithLabel } from '../../../config/logger' import { getEncryptSubmissionModel } from '../../../models/submission.server.model' import { isMalformedDate } from '../../../utils/date' import { getMongoErrorMessage } from '../../../utils/handle-mongo-error' diff --git a/src/app/modules/submission/encrypt-submission/encrypt-submission.utils.ts b/src/app/modules/submission/encrypt-submission/encrypt-submission.utils.ts index 4117ae9edd..c1f99b8203 100644 --- a/src/app/modules/submission/encrypt-submission/encrypt-submission.utils.ts +++ b/src/app/modules/submission/encrypt-submission/encrypt-submission.utils.ts @@ -1,9 +1,9 @@ import { StatusCodes } from 'http-status-codes' import moment from 'moment-timezone' -import { createLoggerWithLabel } from '../../../../config/logger' import { EncryptedSubmissionDto, SubmissionData } from '../../../../types' import { MapRouteError } from '../../../../types/routing' +import { createLoggerWithLabel } from '../../../config/logger' import { MalformedVerifiedContentError } from '../../../modules/verified-content/verified-content.errors' import { CaptchaConnectionError, diff --git a/src/app/modules/submission/submission.service.ts b/src/app/modules/submission/submission.service.ts index 50619491c7..ac4447eb25 100644 --- a/src/app/modules/submission/submission.service.ts +++ b/src/app/modules/submission/submission.service.ts @@ -2,7 +2,6 @@ import _ from 'lodash' import mongoose from 'mongoose' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../config/logger' import { getLogicUnitPreventingSubmit, getVisibleFieldIds, @@ -17,6 +16,7 @@ import { ISubmissionSchema, ResponseMode, } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import getSubmissionModel from '../../models/submission.server.model' import MailService from '../../services/mail/mail.service' import { createQueryWithDateParam, isMalformedDate } from '../../utils/date' diff --git a/src/app/modules/user/user.controller.ts b/src/app/modules/user/user.controller.ts index 2e32d23057..6789c5c390 100644 --- a/src/app/modules/user/user.controller.ts +++ b/src/app/modules/user/user.controller.ts @@ -2,8 +2,8 @@ import { RequestHandler } from 'express' import { ParamsDictionary } from 'express-serve-static-core' import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { IPopulatedUser } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { SmsFactory } from '../../services/sms/sms.factory' import { getRequestIp } from '../../utils/request' import { getUserIdFromSession } from '../auth/auth.utils' diff --git a/src/app/modules/user/user.service.ts b/src/app/modules/user/user.service.ts index a65e1c80ee..1d4d6e0aa7 100644 --- a/src/app/modules/user/user.service.ts +++ b/src/app/modules/user/user.service.ts @@ -2,8 +2,6 @@ import mongoose from 'mongoose' import { errAsync, okAsync, ResultAsync } from 'neverthrow' import validator from 'validator' -import config from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' import { IAdminVerificationDoc, IAgencySchema, @@ -12,6 +10,8 @@ import { UpsertOtpParams, UserContactView, } from '../../../types' +import config from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import getAdminVerificationModel from '../../models/admin_verification.server.model' import { AGENCY_SCHEMA_ID } from '../../models/agency.server.model' import getUserModel from '../../models/user.server.model' diff --git a/src/app/modules/user/user.utils.ts b/src/app/modules/user/user.utils.ts index d9026359e6..75f7d92c28 100644 --- a/src/app/modules/user/user.utils.ts +++ b/src/app/modules/user/user.utils.ts @@ -1,7 +1,7 @@ import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { UserContactView } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import * as SmsErrors from '../../services/sms/sms.errors' import { HashingError } from '../../utils/hash' import * as CoreErrors from '../core/core.errors' diff --git a/src/app/modules/verification/__tests__/verification.factory.spec.ts b/src/app/modules/verification/__tests__/verification.factory.spec.ts index 0065a23922..40b39c6fb6 100644 --- a/src/app/modules/verification/__tests__/verification.factory.spec.ts +++ b/src/app/modules/verification/__tests__/verification.factory.spec.ts @@ -1,7 +1,7 @@ import { mocked } from 'ts-jest/utils' +import { FeatureNames } from 'src/app/config/feature-manager' import { MissingFeatureError } from 'src/app/modules/core/core.errors' -import { FeatureNames } from 'src/config/feature-manager' import { createVerificationFactory } from '../verification.factory' import * as VerificationService from '../verification.service' diff --git a/src/app/modules/verification/__tests__/verification.service.spec.ts b/src/app/modules/verification/__tests__/verification.service.spec.ts index 5a7b7f1d28..93cf7f5d24 100644 --- a/src/app/modules/verification/__tests__/verification.service.spec.ts +++ b/src/app/modules/verification/__tests__/verification.service.spec.ts @@ -4,13 +4,13 @@ import mongoose from 'mongoose' import { errAsync, okAsync } from 'neverthrow' import { mocked } from 'ts-jest/utils' +import formsgSdk from 'src/app/config/formsg-sdk' import * as FormService from 'src/app/modules/form/form.service' import { MailSendError } from 'src/app/services/mail/mail.errors' import MailService from 'src/app/services/mail/mail.service' import { SmsSendError } from 'src/app/services/sms/sms.errors' import { SmsFactory } from 'src/app/services/sms/sms.factory' import * as HashUtils from 'src/app/utils/hash' -import formsgSdk from 'src/config/formsg-sdk' import { BasicField, IFormSchema, diff --git a/src/app/modules/verification/verification.controller.ts b/src/app/modules/verification/verification.controller.ts index a829d760b7..b60b7abf6b 100644 --- a/src/app/modules/verification/verification.controller.ts +++ b/src/app/modules/verification/verification.controller.ts @@ -1,10 +1,10 @@ import { RequestHandler } from 'express' import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { SALT_ROUNDS } from '../../../shared/util/verification' import { PublicTransaction } from '../../../types' import { ErrorDto } from '../../../types/api' +import { createLoggerWithLabel } from '../../config/logger' import { generateOtpWithHash } from '../../utils/otp' import { createReqMeta } from '../../utils/request' diff --git a/src/app/modules/verification/verification.factory.ts b/src/app/modules/verification/verification.factory.ts index 65c9047827..f1cfa91e33 100644 --- a/src/app/modules/verification/verification.factory.ts +++ b/src/app/modules/verification/verification.factory.ts @@ -3,7 +3,7 @@ import { errAsync } from 'neverthrow' import featureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../core/core.errors' import * as VerificationService from './verification.service' diff --git a/src/app/modules/verification/verification.service.ts b/src/app/modules/verification/verification.service.ts index f128c7804b..d1f48041d8 100644 --- a/src/app/modules/verification/verification.service.ts +++ b/src/app/modules/verification/verification.service.ts @@ -1,8 +1,6 @@ import mongoose from 'mongoose' import { err, errAsync, ok, okAsync, Result, ResultAsync } from 'neverthrow' -import formsgSdk from '../../../config/formsg-sdk' -import { createLoggerWithLabel } from '../../../config/logger' import { NUM_OTP_RETRIES } from '../../../shared/util/verification' import { BasicField, @@ -10,6 +8,8 @@ import { IVerificationSchema, PublicTransaction, } from '../../../types' +import formsgSdk from '../../config/formsg-sdk' +import { createLoggerWithLabel } from '../../config/logger' import { MailSendError } from '../../services/mail/mail.errors' import MailService from '../../services/mail/mail.service' import { InvalidNumberError, SmsSendError } from '../../services/sms/sms.errors' diff --git a/src/app/modules/verification/verification.util.ts b/src/app/modules/verification/verification.util.ts index 43167dea9d..eac730fa75 100644 --- a/src/app/modules/verification/verification.util.ts +++ b/src/app/modules/verification/verification.util.ts @@ -1,6 +1,5 @@ import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { HASH_EXPIRE_AFTER_SECONDS, VERIFIED_FIELDTYPES, @@ -11,6 +10,7 @@ import { IVerificationSchema, MapRouteError, } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { MailSendError } from '../../services/mail/mail.errors' import { InvalidNumberError, SmsSendError } from '../../services/sms/sms.errors' import { HashingError } from '../../utils/hash' diff --git a/src/app/modules/verified-content/__tests__/verified-content.factory.spec.ts b/src/app/modules/verified-content/__tests__/verified-content.factory.spec.ts index 26c983afb2..188bd48b2a 100644 --- a/src/app/modules/verified-content/__tests__/verified-content.factory.spec.ts +++ b/src/app/modules/verified-content/__tests__/verified-content.factory.spec.ts @@ -1,7 +1,7 @@ import { ok } from 'neverthrow' import { mocked } from 'ts-jest/utils' -import { FeatureNames, RegisteredFeature } from 'src/config/feature-manager' +import { FeatureNames, RegisteredFeature } from 'src/app/config/feature-manager' import { MissingFeatureError } from '../../core/core.errors' import { createVerifiedContentFactory } from '../verified-content.factory' diff --git a/src/app/modules/verified-content/__tests__/verified-content.service.spec.ts b/src/app/modules/verified-content/__tests__/verified-content.service.spec.ts index 390ccf6bda..0ee60d6895 100644 --- a/src/app/modules/verified-content/__tests__/verified-content.service.spec.ts +++ b/src/app/modules/verified-content/__tests__/verified-content.service.spec.ts @@ -1,4 +1,4 @@ -import formsgSdk from 'src/config/formsg-sdk' +import formsgSdk from 'src/app/config/formsg-sdk' import { AuthType } from 'src/types' import { diff --git a/src/app/modules/verified-content/verified-content.factory.ts b/src/app/modules/verified-content/verified-content.factory.ts index 63344ff3aa..cfc4efe651 100644 --- a/src/app/modules/verified-content/verified-content.factory.ts +++ b/src/app/modules/verified-content/verified-content.factory.ts @@ -3,7 +3,7 @@ import { err } from 'neverthrow' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../core/core.errors' import { diff --git a/src/app/modules/verified-content/verified-content.service.ts b/src/app/modules/verified-content/verified-content.service.ts index a137423133..e3afd21627 100644 --- a/src/app/modules/verified-content/verified-content.service.ts +++ b/src/app/modules/verified-content/verified-content.service.ts @@ -1,8 +1,8 @@ import { err, ok, Result } from 'neverthrow' -import formsgSdk from '../../../config/formsg-sdk' -import { createLoggerWithLabel } from '../../../config/logger' import { AuthType } from '../../../types' +import formsgSdk from '../../config/formsg-sdk' +import { createLoggerWithLabel } from '../../config/logger' import { EncryptVerifiedContentError } from './verified-content.errors' import { diff --git a/src/app/modules/webhook/__tests__/webhook.service.spec.ts b/src/app/modules/webhook/__tests__/webhook.service.spec.ts index a1b74c5952..03be2ea88d 100644 --- a/src/app/modules/webhook/__tests__/webhook.service.spec.ts +++ b/src/app/modules/webhook/__tests__/webhook.service.spec.ts @@ -3,13 +3,13 @@ import { ObjectID } from 'bson' import mongoose from 'mongoose' import { mocked } from 'ts-jest/utils' +import formsgSdk from 'src/app/config/formsg-sdk' import getFormModel from 'src/app/models/form.server.model' import { getEncryptSubmissionModel } from 'src/app/models/submission.server.model' import { WebhookValidationError } from 'src/app/modules/webhook/webhook.errors' import * as WebhookValidationModule from 'src/app/modules/webhook/webhook.validation' import { transformMongoError } from 'src/app/utils/handle-mongo-error' import * as HasPropModule from 'src/app/utils/has-prop' -import formsgSdk from 'src/config/formsg-sdk' import { IEncryptedSubmissionSchema, IWebhookResponse, diff --git a/src/app/modules/webhook/__tests__/webhook.validation.spec.ts b/src/app/modules/webhook/__tests__/webhook.validation.spec.ts index eec2425228..a8853b1dbf 100644 --- a/src/app/modules/webhook/__tests__/webhook.validation.spec.ts +++ b/src/app/modules/webhook/__tests__/webhook.validation.spec.ts @@ -1,9 +1,9 @@ import { promises as dns } from 'dns' import { mocked } from 'ts-jest/utils' +import config from 'src/app/config/config' import { WebhookValidationError } from 'src/app/modules/webhook/webhook.errors' import { validateWebhookUrl } from 'src/app/modules/webhook/webhook.validation' -import config from 'src/config/config' jest.mock('dns', () => ({ promises: { diff --git a/src/app/modules/webhook/webhook.factory.ts b/src/app/modules/webhook/webhook.factory.ts index dc974b6011..9e2db715d3 100644 --- a/src/app/modules/webhook/webhook.factory.ts +++ b/src/app/modules/webhook/webhook.factory.ts @@ -3,7 +3,7 @@ import { errAsync } from 'neverthrow' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../core/core.errors' import * as WebhookService from './webhook.service' diff --git a/src/app/modules/webhook/webhook.service.ts b/src/app/modules/webhook/webhook.service.ts index 682501d96b..5632573728 100644 --- a/src/app/modules/webhook/webhook.service.ts +++ b/src/app/modules/webhook/webhook.service.ts @@ -3,13 +3,13 @@ import { get } from 'lodash' import mongoose from 'mongoose' import { errAsync, okAsync, ResultAsync } from 'neverthrow' -import formsgSdk from '../../../config/formsg-sdk' -import { createLoggerWithLabel } from '../../../config/logger' import { IEncryptedSubmissionSchema, ISubmissionSchema, IWebhookResponse, } from '../../../types' +import formsgSdk from '../../config/formsg-sdk' +import { createLoggerWithLabel } from '../../config/logger' import { getEncryptSubmissionModel } from '../../models/submission.server.model' import { transformMongoError } from '../../utils/handle-mongo-error' import { hasProp } from '../../utils/has-prop' diff --git a/src/app/modules/webhook/webhook.validation.ts b/src/app/modules/webhook/webhook.validation.ts index 5e355927d6..b899efe0c3 100644 --- a/src/app/modules/webhook/webhook.validation.ts +++ b/src/app/modules/webhook/webhook.validation.ts @@ -1,8 +1,8 @@ import { promises as dns } from 'dns' import ip from 'ip' -import config from '../../../config/config' import { isValidHttpsUrl } from '../../../shared/util/url-validation' +import config from '../../config/config' import { WebhookValidationError } from './webhook.errors' diff --git a/src/app/routes/api/v3/auth/auth.routes.ts b/src/app/routes/api/v3/auth/auth.routes.ts index b931d9d6fb..bf144dc9fb 100644 --- a/src/app/routes/api/v3/auth/auth.routes.ts +++ b/src/app/routes/api/v3/auth/auth.routes.ts @@ -1,7 +1,7 @@ import { celebrate, Joi, Segments } from 'celebrate' import { Router } from 'express' -import { rateLimitConfig } from '../../../../../config/config' +import { rateLimitConfig } from '../../../../config/config' import * as AuthController from '../../../../modules/auth/auth.controller' import { limitRate } from '../../../../utils/limit-rate' diff --git a/src/app/services/captcha/captcha.factory.ts b/src/app/services/captcha/captcha.factory.ts index 87d4c55caf..95d9f59f2c 100644 --- a/src/app/services/captcha/captcha.factory.ts +++ b/src/app/services/captcha/captcha.factory.ts @@ -5,7 +5,7 @@ import { okAsync, ResultAsync } from 'neverthrow' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../../modules/core/core.errors' import { diff --git a/src/app/services/captcha/captcha.service.ts b/src/app/services/captcha/captcha.service.ts index bea868387e..a29c4865d9 100644 --- a/src/app/services/captcha/captcha.service.ts +++ b/src/app/services/captcha/captcha.service.ts @@ -1,7 +1,7 @@ import axios from 'axios' import { errAsync, okAsync, ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../../config/logger' +import { createLoggerWithLabel } from '../../config/logger' import { GOOGLE_RECAPTCHA_URL } from './captcha.constants' import { diff --git a/src/app/services/captcha/captcha.util.ts b/src/app/services/captcha/captcha.util.ts index 3ec3bd64b6..9edb7f0add 100644 --- a/src/app/services/captcha/captcha.util.ts +++ b/src/app/services/captcha/captcha.util.ts @@ -1,7 +1,7 @@ import { StatusCodes } from 'http-status-codes' -import { createLoggerWithLabel } from '../../../config/logger' import { MapRouteError } from '../../../types' +import { createLoggerWithLabel } from '../../config/logger' import { MissingFeatureError } from '../../modules/core/core.errors' import { diff --git a/src/app/services/intranet/__tests__/intranet.factory.spec.ts b/src/app/services/intranet/__tests__/intranet.factory.spec.ts index 74991e0b8f..83669d3d01 100644 --- a/src/app/services/intranet/__tests__/intranet.factory.spec.ts +++ b/src/app/services/intranet/__tests__/intranet.factory.spec.ts @@ -1,7 +1,7 @@ import { mocked } from 'ts-jest/utils' +import { FeatureNames } from 'src/app/config/feature-manager' import { MissingFeatureError } from 'src/app/modules/core/core.errors' -import { FeatureNames } from 'src/config/feature-manager' import { createIntranetFactory } from '../intranet.factory' import { IntranetService } from '../intranet.service' diff --git a/src/app/services/intranet/intranet.factory.ts b/src/app/services/intranet/intranet.factory.ts index 32860b2eea..97c8cdd92b 100644 --- a/src/app/services/intranet/intranet.factory.ts +++ b/src/app/services/intranet/intranet.factory.ts @@ -3,7 +3,7 @@ import { err, ok, Result } from 'neverthrow' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../../modules/core/core.errors' import { IntranetService } from './intranet.service' diff --git a/src/app/services/intranet/intranet.middleware.ts b/src/app/services/intranet/intranet.middleware.ts index fd9ea74409..679ae3f2ec 100644 --- a/src/app/services/intranet/intranet.middleware.ts +++ b/src/app/services/intranet/intranet.middleware.ts @@ -1,6 +1,6 @@ import { RequestHandler } from 'express-serve-static-core' -import { createLoggerWithLabel } from '../../../config/logger' +import { createLoggerWithLabel } from '../../config/logger' import { createReqMeta, getRequestIp } from '../../utils/request' import { IntranetFactory } from './intranet.factory' diff --git a/src/app/services/intranet/intranet.service.ts b/src/app/services/intranet/intranet.service.ts index 91d957231b..d38e5db6f2 100644 --- a/src/app/services/intranet/intranet.service.ts +++ b/src/app/services/intranet/intranet.service.ts @@ -1,7 +1,7 @@ import fs from 'fs' -import { IIntranet } from '../../../config/feature-manager' -import { createLoggerWithLabel } from '../../../config/logger' +import { IIntranet } from '../../config/feature-manager' +import { createLoggerWithLabel } from '../../config/logger' const logger = createLoggerWithLabel(module) diff --git a/src/app/services/mail/mail.service.ts b/src/app/services/mail/mail.service.ts index 03bff3b4a6..5275dfd913 100644 --- a/src/app/services/mail/mail.service.ts +++ b/src/app/services/mail/mail.service.ts @@ -5,8 +5,6 @@ import Mail from 'nodemailer/lib/mailer' import promiseRetry from 'promise-retry' import validator from 'validator' -import config from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' import { HASH_EXPIRE_AFTER_SECONDS } from '../../../shared/util/verification' import { BounceType, @@ -14,6 +12,8 @@ import { IEmailFormSchema, ISubmissionSchema, } from '../../../types' +import config from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import { EMAIL_HEADERS, EmailType } from './mail.constants' import { MailGenerationError, MailSendError } from './mail.errors' diff --git a/src/app/services/mail/mail.utils.ts b/src/app/services/mail/mail.utils.ts index b24caaa360..d6df270e53 100644 --- a/src/app/services/mail/mail.utils.ts +++ b/src/app/services/mail/mail.utils.ts @@ -5,9 +5,9 @@ import { ResultAsync } from 'neverthrow' import puppeteer from 'puppeteer-core' import validator from 'validator' -import config from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' import { BounceType } from '../../../types' +import config from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import { MailGenerationError, MailSendError } from './mail.errors' import { diff --git a/src/app/services/sms/__tests__/sms.factory.spec.ts b/src/app/services/sms/__tests__/sms.factory.spec.ts index 42b7ead403..ff9945ef15 100644 --- a/src/app/services/sms/__tests__/sms.factory.spec.ts +++ b/src/app/services/sms/__tests__/sms.factory.spec.ts @@ -3,12 +3,12 @@ import { okAsync } from 'neverthrow' import { mocked } from 'ts-jest/utils' import Twilio from 'twilio' -import { MissingFeatureError } from 'src/app/modules/core/core.errors' import { FeatureNames, ISms, RegisteredFeature, -} from 'src/config/feature-manager' +} from 'src/app/config/feature-manager' +import { MissingFeatureError } from 'src/app/modules/core/core.errors' import { createSmsFactory } from '../sms.factory' import * as SmsService from '../sms.service' diff --git a/src/app/services/sms/sms.factory.ts b/src/app/services/sms/sms.factory.ts index 6f2ee6c7c8..737f430ada 100644 --- a/src/app/services/sms/sms.factory.ts +++ b/src/app/services/sms/sms.factory.ts @@ -4,7 +4,7 @@ import Twilio from 'twilio' import FeatureManager, { FeatureNames, RegisteredFeature, -} from '../../../config/feature-manager' +} from '../../config/feature-manager' import { MissingFeatureError } from '../../modules/core/core.errors' import { diff --git a/src/app/services/sms/sms.service.ts b/src/app/services/sms/sms.service.ts index 0e9e03ce7b..95fd568f8b 100644 --- a/src/app/services/sms/sms.service.ts +++ b/src/app/services/sms/sms.service.ts @@ -4,10 +4,10 @@ import { errAsync, okAsync, ResultAsync } from 'neverthrow' import NodeCache from 'node-cache' import Twilio from 'twilio' -import config from '../../../config/config' -import { createLoggerWithLabel } from '../../../config/logger' import { isPhoneNumber } from '../../../shared/util/phone-num-validation' import { AdminContactOtpData, FormOtpData } from '../../../types' +import config from '../../config/config' +import { createLoggerWithLabel } from '../../config/logger' import getFormModel from '../../models/form.server.model' import { DatabaseError, diff --git a/src/app/utils/field-validation/index.ts b/src/app/utils/field-validation/index.ts index 2ae3bc4366..cd553dda5d 100644 --- a/src/app/utils/field-validation/index.ts +++ b/src/app/utils/field-validation/index.ts @@ -8,11 +8,11 @@ import { ProcessedSingleAnswerResponse, ProcessedTableResponse, } from '../../../app/modules/submission/submission.types' -import { createLoggerWithLabel } from '../../../config/logger' import { FIELDS_TO_REJECT } from '../../../shared/resources/basic' import { IFieldSchema, ITableFieldSchema } from '../../../types/field' import { isTableField } from '../../../types/field/utils/guards' import { ResponseValidator } from '../../../types/field/utils/validation' +import { createLoggerWithLabel } from '../../config/logger' import { ValidateFieldError } from '../../modules/submission/submission.errors' import { diff --git a/src/app/utils/field-validation/validators/__tests__/email-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/email-validation.spec.ts index 764b083ad0..1a29fb2a9d 100644 --- a/src/app/utils/field-validation/validators/__tests__/email-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/email-validation.spec.ts @@ -1,7 +1,7 @@ +import formsgSdk from 'src/app/config/formsg-sdk' import { ValidateFieldError } from 'src/app/modules/submission/submission.errors' import { ProcessedFieldResponse } from 'src/app/modules/submission/submission.types' import { validateField } from 'src/app/utils/field-validation' -import formsgSdk from 'src/config/formsg-sdk' import { IFieldSchema } from 'src/types' import { BasicField } from 'src/types/field/fieldTypes' import { ISingleAnswerResponse } from 'src/types/response' diff --git a/src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts b/src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts index 0f6449cc1c..ccb9fdd978 100644 --- a/src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts +++ b/src/app/utils/field-validation/validators/__tests__/mobile-num-validation.spec.ts @@ -1,6 +1,6 @@ +import formsgSdk from 'src/app/config/formsg-sdk' import { ValidateFieldError } from 'src/app/modules/submission/submission.errors' import { validateField } from 'src/app/utils/field-validation' -import formsgSdk from 'src/config/formsg-sdk' import { IFieldSchema } from 'src/types' import { BasicField } from 'src/types/field/fieldTypes' diff --git a/src/app/utils/field-validation/validators/common.ts b/src/app/utils/field-validation/validators/common.ts index 14778c1c18..9b130b512f 100644 --- a/src/app/utils/field-validation/validators/common.ts +++ b/src/app/utils/field-validation/validators/common.ts @@ -4,7 +4,7 @@ import { ProcessedSingleAnswerResponse } from 'src/app/modules/submission/submis import { IEmailFieldSchema, IMobileFieldSchema } from 'src/types/field' import { ResponseValidator } from 'src/types/field/utils/validation' -import formsgSdk from '../../../../config/formsg-sdk' +import formsgSdk from '../../../config/formsg-sdk' /** * A function which returns a validator to check if single answer has a non-empty response diff --git a/src/app/utils/hash.ts b/src/app/utils/hash.ts index 7f1a7bfcd8..4e4e840375 100644 --- a/src/app/utils/hash.ts +++ b/src/app/utils/hash.ts @@ -1,7 +1,7 @@ import bcrypt from 'bcrypt' import { ResultAsync } from 'neverthrow' -import { createLoggerWithLabel } from '../../config/logger' +import { createLoggerWithLabel } from '../config/logger' import { ApplicationError } from '../modules/core/core.errors' const logger = createLoggerWithLabel(module) diff --git a/src/app/utils/limit-rate.ts b/src/app/utils/limit-rate.ts index 9a97358882..c11ca9e95e 100644 --- a/src/app/utils/limit-rate.ts +++ b/src/app/utils/limit-rate.ts @@ -5,7 +5,7 @@ import RateLimit, { import { StatusCodes } from 'http-status-codes' import { merge } from 'lodash' -import { createLoggerWithLabel } from '../../config/logger' +import { createLoggerWithLabel } from '../config/logger' import { createReqMeta } from './request' diff --git a/src/server.ts b/src/server.ts index 9b3de0eabd..b72a87aa7b 100755 --- a/src/server.ts +++ b/src/server.ts @@ -1,6 +1,6 @@ -import config from './config/config' -import { createLoggerWithLabel } from './config/logger' -import loadApp from './loaders' +import config from './app/config/config' +import { createLoggerWithLabel } from './app/config/logger' +import loadApp from './app/loaders' const logger = createLoggerWithLabel(module) diff --git a/tests/integration/helpers/express-setup.ts b/tests/integration/helpers/express-setup.ts index e51319da6a..943592354d 100644 --- a/tests/integration/helpers/express-setup.ts +++ b/tests/integration/helpers/express-setup.ts @@ -4,11 +4,11 @@ import express, { Express, Router } from 'express' import session from 'express-session' import nocache from 'nocache' +import errorHandlerMiddlewares from 'src/app/loaders/express/error-handler' +import helmetMiddlewares from 'src/app/loaders/express/helmet' +import loggingMiddleware from 'src/app/loaders/express/logging' +import parserMiddlewares from 'src/app/loaders/express/parser' import { AuthRouter } from 'src/app/modules/auth/auth.routes' -import errorHandlerMiddlewares from 'src/loaders/express/error-handler' -import helmetMiddlewares from 'src/loaders/express/helmet' -import loggingMiddleware from 'src/loaders/express/logging' -import parserMiddlewares from 'src/loaders/express/parser' // Special session middleware that only uses the memory store. const testSessionMiddlewares = () => { From 988f65b7e9a9dacad61500d349f2893d9c809368 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:25:30 +0800 Subject: [PATCH 6/8] chore: fix mock paths --- src/app/loaders/express/__tests__/helmet.spec.ts | 4 ++-- src/app/modules/bounce/__tests__/bounce.service.spec.ts | 2 +- src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts | 2 +- src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts | 2 +- src/app/modules/spcp/__tests__/spcp.controller.spec.ts | 2 +- .../verification/__tests__/verification.service.spec.ts | 2 +- src/app/modules/webhook/__tests__/webhook.validation.spec.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/loaders/express/__tests__/helmet.spec.ts b/src/app/loaders/express/__tests__/helmet.spec.ts index bfb3fb4528..e41cf98247 100644 --- a/src/app/loaders/express/__tests__/helmet.spec.ts +++ b/src/app/loaders/express/__tests__/helmet.spec.ts @@ -11,9 +11,9 @@ import helmetMiddlewares from '../helmet' describe('helmetMiddlewares', () => { jest.mock('helmet') const mockHelmet = mocked(helmet, true) - jest.mock('src/config/feature-manager') + jest.mock('src/app/config/feature-manager') const mockFeatureManager = mocked(featureManager, true) - jest.mock('src/config/config') + jest.mock('src/app/config/config') const mockConfig = mocked(config, true) const cspCoreDirectives = { diff --git a/src/app/modules/bounce/__tests__/bounce.service.spec.ts b/src/app/modules/bounce/__tests__/bounce.service.spec.ts index 47724c6959..b04642b9dc 100644 --- a/src/app/modules/bounce/__tests__/bounce.service.spec.ts +++ b/src/app/modules/bounce/__tests__/bounce.service.spec.ts @@ -31,7 +31,7 @@ import { makeBounceNotification, MOCK_SNS_BODY } from './bounce-test-helpers' jest.mock('axios') const mockAxios = mocked(axios, true) -jest.mock('src/config/logger') +jest.mock('src/app/config/logger') const MockLoggerModule = mocked(LoggerModule, true) jest.mock('src/app/services/mail/mail.service') const MockMailService = mocked(MailService, true) diff --git a/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts b/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts index e59ef14b21..0c87e6b5c9 100644 --- a/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts +++ b/src/app/modules/myinfo/__tests__/myinfo.factory.spec.ts @@ -15,7 +15,7 @@ jest.mock('../myinfo.service', () => ({ MyInfoService: jest.fn(), })) const MockMyInfoService = mocked(MyInfoServiceModule, true) -jest.mock('src/config/config') +jest.mock('src/app/config/config') const MockConfig = mocked(config, true) MockConfig.nodeEnv = MOCK_NODE_ENV as Environment MockConfig.app = { diff --git a/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts b/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts index 99c3673d46..c09a9df56d 100644 --- a/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts +++ b/src/app/modules/myinfo/__tests__/myinfo_hash.model.spec.ts @@ -8,7 +8,7 @@ import config from 'src/app/config/config' import dbHandler from '../../../../../tests/unit/backend/helpers/jest-db' -jest.mock('src/config/config') +jest.mock('src/app/config/config') const MockConfig = mocked(config, true) // eslint-disable-next-line import/first diff --git a/src/app/modules/spcp/__tests__/spcp.controller.spec.ts b/src/app/modules/spcp/__tests__/spcp.controller.spec.ts index 31fba20d34..31c07bdc37 100644 --- a/src/app/modules/spcp/__tests__/spcp.controller.spec.ts +++ b/src/app/modules/spcp/__tests__/spcp.controller.spec.ts @@ -48,7 +48,7 @@ jest.mock('../../billing/billing.factory') const MockBillingFactory = mocked(BillingFactory, true) jest.mock('src/app/modules/form/form.service') const MockFormService = mocked(FormService, true) -jest.mock('src/config/config') +jest.mock('src/app/config/config') const MockConfig = mocked(config, true) MockConfig.isDev = false diff --git a/src/app/modules/verification/__tests__/verification.service.spec.ts b/src/app/modules/verification/__tests__/verification.service.spec.ts index 93cf7f5d24..12558383ea 100644 --- a/src/app/modules/verification/__tests__/verification.service.spec.ts +++ b/src/app/modules/verification/__tests__/verification.service.spec.ts @@ -47,7 +47,7 @@ import { const VerificationModel = getVerificationModel(mongoose) // Set up mocks -jest.mock('src/config/formsg-sdk') +jest.mock('src/app/config/formsg-sdk') const MockFormsgSdk = mocked(formsgSdk, true) jest.mock('src/app/services/sms/sms.factory') const MockSmsFactory = mocked(SmsFactory, true) diff --git a/src/app/modules/webhook/__tests__/webhook.validation.spec.ts b/src/app/modules/webhook/__tests__/webhook.validation.spec.ts index a8853b1dbf..bb237dfea8 100644 --- a/src/app/modules/webhook/__tests__/webhook.validation.spec.ts +++ b/src/app/modules/webhook/__tests__/webhook.validation.spec.ts @@ -13,7 +13,7 @@ jest.mock('dns', () => ({ const MockDns = mocked(dns, true) const MOCK_APP_URL = 'https://example.com' -jest.mock('src/config/config') +jest.mock('src/app/config/config') const MockConfig = mocked(config, true) MockConfig.app.appUrl = MOCK_APP_URL From f80e770b20d5ea367b076cf5d45d4dc1ec4f15d9 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Fri, 9 Apr 2021 10:25:53 +0800 Subject: [PATCH 7/8] docs: update ARCHITECTURE.md --- docs/ARCHITECTURE.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 3b6a7679d0..1ff2eb9229 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -13,12 +13,9 @@ identities, and E-mail servers hosted in Government Data Centres. ## Backend -FormSG is currently in the process of migrating its backend to TypeScript, so you will find -a mixture of `.js` and `.ts` files in the backend. - -The backend for FormSG is bootstrapped using `src/server.ts` and `src/loaders`. -It sets up express.js routes defined in `src/app/routes/*.(j|t)s`, with business logic -defined in `src/app/controllers/*.(j|t)s` and mongoose models defined in `src/app/models/*.(j|t)s`. +The backend for FormSG is bootstrapped using `src/server.ts` and `src/app/loaders`. +It sets up express.js routes defined in `src/app/**/*.routes.ts`, with business logic +defined in `src/app/**/*.controller.ts` and mongoose models defined in `src/app/**/*.model.ts`. ### Security From b338b7cbf0957224a3ef6fcacaa93eb0b691bd70 Mon Sep 17 00:00:00 2001 From: Antariksh Date: Mon, 12 Apr 2021 10:47:40 +0800 Subject: [PATCH 8/8] chore: move shared tests into shared --- src/{app/utils => shared/util}/__tests__/file-validation.spec.ts | 0 src/{app/utils => shared/util}/__tests__/logic.spec.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{app/utils => shared/util}/__tests__/file-validation.spec.ts (100%) rename src/{app/utils => shared/util}/__tests__/logic.spec.ts (100%) diff --git a/src/app/utils/__tests__/file-validation.spec.ts b/src/shared/util/__tests__/file-validation.spec.ts similarity index 100% rename from src/app/utils/__tests__/file-validation.spec.ts rename to src/shared/util/__tests__/file-validation.spec.ts diff --git a/src/app/utils/__tests__/logic.spec.ts b/src/shared/util/__tests__/logic.spec.ts similarity index 100% rename from src/app/utils/__tests__/logic.spec.ts rename to src/shared/util/__tests__/logic.spec.ts