Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(deps): update mongoose to 6 #6832

Merged
merged 66 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
8325f00
chore: bump mongoose to 6.12
foochifa Sep 22, 2023
75b4ac7
fix: type mismatch on cursorquery, objectid
KenLSM Sep 28, 2023
dc2eedb
fix: required and validator shape in user and form model
foochifa Sep 29, 2023
d2273d4
fix: use try catch block for mongoose connect loader
foochifa Sep 29, 2023
bb290a9
fix: add missing goLinkSuffix property in IForm
foochifa Sep 29, 2023
25fe76c
fix: overwrite typing of IPaymentSchema for mongoose Id
foochifa Sep 29, 2023
0454c98
fix: querycursor import in submission.ts
foochifa Sep 29, 2023
203e079
fix: removed undefined in AgencySchema causing schema methods to be n…
foochifa Sep 29, 2023
266ff9c
fix: schema typings in form logic and sms types
foochifa Sep 29, 2023
dcb1c18
fix: replace ConnectionOptions with ConnectOptions
foochifa Sep 29, 2023
bd9a8ac
fix: remove deprecated connect options
foochifa Sep 29, 2023
9200683
fix: objectid imports
KenLSM Sep 29, 2023
ec2537f
chore: remove mongodb package, upgrade connect-mongo to 4.6.0
KenLSM Sep 29, 2023
6a70385
chore: replace mongoerror import reference
KenLSM Sep 29, 2023
55671d3
fix: typescript errors
KenLSM Sep 29, 2023
944be5b
chore: change nModified to modifiedCount
foochifa Oct 20, 2023
5206b01
fix: typeerror on form_statistics_total.server.model
KenLSM Oct 20, 2023
925c42c
fix: typeerror on bouncemodel
KenLSM Oct 20, 2023
fe335ee
fix: form server model, only fixed affected methods
KenLSM Oct 20, 2023
327250c
fix: mongoerror is now mongoservererror
KenLSM Oct 23, 2023
6a7a988
fix: execPopulate no longer required to be called
KenLSM Oct 23, 2023
f4722b8
fix: verification.model
KenLSM Oct 23, 2023
4e1bdb8
fix: replace enforcedocument to hydrateddocument
KenLSM Oct 23, 2023
53d376d
fix: duplicateFormFieldByIdAndIndex
KenLSM Oct 23, 2023
8763919
fix: util/logic.ts type inference errors
KenLSM Oct 23, 2023
4db93ce
refactor: swap bson with bson-ext
KenLSM Oct 23, 2023
3a13652
chore: update test db configs
KenLSM Oct 24, 2023
bd87cae
refactor: remove bson reference
KenLSM Oct 24, 2023
5bb4277
refactor: gloal replacement of bson
KenLSM Oct 24, 2023
95785ff
chore: remove execPopulate
KenLSM Oct 24, 2023
822974e
fix: void promise returns
KenLSM Oct 24, 2023
2e84a26
fix: remove bson reference with mongoose
KenLSM Oct 24, 2023
b187dec
fix: replace more bson on admin-forms.form.routes.specs
KenLSM Oct 24, 2023
d864725
fix: test failures on admin-forms.submissions.routes.spec
KenLSM Oct 24, 2023
8381975
fix: test failures on src/app/models
KenLSM Oct 24, 2023
11ee860
fix: test failures on src/app/modules/payments
KenLSM Oct 24, 2023
4d12328
fix: test failures on src/app/modules/issues
KenLSM Oct 24, 2023
3e25025
fix: form model always defaulting to private mode on save
KenLSM Oct 24, 2023
c719271
chore: remove bson in jest-db
KenLSM Oct 24, 2023
448bf63
fix: lint and type errors in loader
KenLSM Oct 24, 2023
82f923e
chore: remove unused typedef
KenLSM Oct 24, 2023
06cc9c0
chore: remove commented out BSON code
KenLSM Oct 24, 2023
ff4dffc
fix: playwright mongod init failure
KenLSM Oct 25, 2023
6e9de19
refactor: rename constants
KenLSM Oct 25, 2023
8406b22
fix: mongoose loader
KenLSM Oct 25, 2023
73a7ff5
fix: removed form model business field to be required
KenLSM Oct 25, 2023
68b2487
fix: e2e email-submission tests
KenLSM Oct 25, 2023
00cfaf4
fix: make mongoose.connect to be async
KenLSM Oct 25, 2023
56d302b
fix: add specific db connection uri
KenLSM Oct 27, 2023
205cbce
fix: restore missing _id in table column
KenLSM Oct 30, 2023
c89f46e
fix: workspace model support
KenLSM Oct 30, 2023
c1d5598
chore: add verbose playwight reporting
KenLSM Oct 30, 2023
3f66dad
chore: update bson-ext to bson for workspace-related code
KenLSM Oct 31, 2023
7e33c91
fix: dburi should not be random
KenLSM Oct 31, 2023
b1ea692
fix: drop form collection instead of the whole db
KenLSM Oct 31, 2023
e5db025
chore: update hosting port from 5000 to 5001 for playwright
KenLSM Oct 31, 2023
50566ad
Merge remote-tracking branch 'origin/develop' into chore/mongoose-bump-6
KenLSM Jan 2, 2024
d5ff128
fix: replace bson-ext with bson
KenLSM Jan 2, 2024
e7fb8f9
Revert "chore: update hosting port from 5000 to 5001 for playwright"
KenLSM Jan 2, 2024
4647e20
fix: workspace spec, exists returning null and doc instead of boolean
KenLSM Jan 3, 2024
71db042
chore: remove commented code
KenLSM Jan 4, 2024
609439f
chore: remove confusing statement
KenLSM Jan 4, 2024
32c3349
chore: remove unneeded comments
KenLSM Jan 4, 2024
016a3f6
Merge remote-tracking branch 'origin/chore/mongoose-bump-6' into chor…
KenLSM Jan 4, 2024
66f638f
chore: remove duplicated typedef
KenLSM Jan 4, 2024
2215ac2
Revert "chore: remove duplicated typedef"
KenLSM Jan 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/e2e/email-submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test.describe('Email form submission', () => {
})
test.afterAll(async () => {
// Clean up db
db.models = {}
await db.dropCollection(Form.collection.name)
await db.close()
})

Expand Down
2 changes: 1 addition & 1 deletion __tests__/e2e/encrypt-submission.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test.describe('Storage form submission', () => {
})
test.afterAll(async () => {
// Clean up db
db.models = {}
await db.dropCollection(Form.collection.name)
await db.close()
})

Expand Down
11 changes: 2 additions & 9 deletions __tests__/e2e/setup/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ async function globalSetup(): Promise<void> {
checkMD5: true,
},
})
await mongod.start()

const uri = await mongod.getUri(true)
const uri = mongod.getUri()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(global as any).__MONGOINSTANCE = mongod
process.env.MONGO_URI = `${uri.slice(0, uri.lastIndexOf('/'))}/${
Expand All @@ -27,14 +28,6 @@ async function globalSetup(): Promise<void> {

// The following is to make sure the database is clean before an test starts
await mongoose.connect(process.env.MONGO_URI, {
// Avoid using deprecated URL string parser in MongoDB driver
useNewUrlParser: true,
useUnifiedTopology: true,
// Avoid using deprecated collection.ensureIndex internally
useCreateIndex: true,
// upgrade to mongo driver's native findOneAndUpdate function instead of
// findAndModify.
useFindAndModify: false,
promiseLibrary: global.Promise,
})
await mongoose.disconnect()
Expand Down
11 changes: 4 additions & 7 deletions __tests__/e2e/utils/database.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import mongoose, { Model } from 'mongoose'

const dbUri = 'mongodb://127.0.0.1:3000/formsg'

// Get absolute path of file
const spec = (path: string): any => {
const fullPath = `${process.env.PWD}/${path}`
Expand All @@ -11,11 +9,10 @@ const spec = (path: string): any => {
/**
* Connects to mongo-memory-server instance.
*/
export const makeMongooseFixtures = async (): Promise<mongoose.Connection> => {
const connection = await mongoose.createConnection(dbUri, {
reconnectTries: 5,
useNewUrlParser: true,
})
export const makeMongooseFixtures = (): Promise<mongoose.Connection> => {
const dbUri = 'mongodb://127.0.0.1:3000/test' // TODO: hardcoding uri as the port and path are fixed and doesn't respect values in __tests__/e2e/setup/setupConfig.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const dbUri = 'mongodb://127.0.0.1:3000/test' // TODO: hardcoding uri as the port and path are fixed and doesn't respect values in __tests__/e2e/setup/setupConfig.ts
const dbUri = 'mongodb://127.0.0.1:3000/test'


const connection = mongoose.createConnection(dbUri).asPromise()
return connection
}

Expand Down
3 changes: 1 addition & 2 deletions __tests__/setup/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class MemoryDatabaseServer {
checkMD5: true,
},
instance: {},
autoStart: false,
})
}

Expand All @@ -21,7 +20,7 @@ class MemoryDatabaseServer {
}

getConnectionString() {
return this.mongod.getUri(true)
return this.mongod.getUri()
}
}

Expand Down
40 changes: 17 additions & 23 deletions __tests__/unit/backend/helpers/jest-db.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import MemoryDatabaseServer from '__tests__/setup/database'
import { ObjectID } from 'bson'
import mongoose from 'mongoose'
import mongoose, { Schema, Types } from 'mongoose'
import { FormResponseMode } from 'shared/types'

import getAgencyModel from 'src/app/models/agency.server.model'
Expand Down Expand Up @@ -31,14 +30,9 @@ import {
* Connect to the in-memory database
*/
const connect = async (): Promise<typeof mongoose> => {
const dbUrl = await MemoryDatabaseServer.getConnectionString()

const conn = await mongoose.connect(dbUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false,
})
await MemoryDatabaseServer.start()
const dbUrl = MemoryDatabaseServer.getConnectionString()
const conn = await mongoose.connect(dbUrl)
return conn
}

Expand Down Expand Up @@ -91,8 +85,8 @@ const insertUser = async ({
mailName = 'test',
apiToken,
}: {
agencyId: ObjectID
userId?: ObjectID
agencyId: Schema.Types.ObjectId
userId?: Schema.Types.ObjectId
mailName?: string
mailDomain?: string
apiToken?: UserApiToken
Expand Down Expand Up @@ -122,7 +116,7 @@ const insertFormCollectionReqs = async ({
betaFlags,
apiToken,
}: {
userId?: ObjectID
userId?: Schema.Types.ObjectId
mailName?: string
mailDomain?: string
shortName?: string
Expand All @@ -139,7 +133,7 @@ const insertFormCollectionReqs = async ({

const user = await User.create({
email: `${mailName}@${mailDomain}`,
_id: userId ?? new ObjectID(),
_id: userId ?? new Types.ObjectId(),
agency: agency._id,
flags,
betaFlags,
Expand All @@ -157,8 +151,8 @@ const insertEmailForm = async ({
shortName = 'govtest',
formOptions = {},
}: {
formId?: ObjectID
userId?: ObjectID
formId?: Schema.Types.ObjectId
userId?: Schema.Types.ObjectId
mailName?: string
mailDomain?: string
shortName?: string
Expand Down Expand Up @@ -201,8 +195,8 @@ const insertEncryptForm = async ({
formOptions = {},
userBetaFlags,
}: {
formId?: ObjectID
userId?: ObjectID
formId?: Schema.Types.ObjectId
userId?: Schema.Types.ObjectId
mailName?: string
mailDomain?: string
shortName?: string
Expand Down Expand Up @@ -248,8 +242,8 @@ const insertFormWithMsgSrvcName = async ({
formOptions = {},
msgSrvcName = 'mockMsgSrvcname',
}: {
formId?: ObjectID
userId?: ObjectID
formId?: Schema.Types.ObjectId
userId?: Schema.Types.ObjectId
mailName?: string
mailDomain?: string
shortName?: string
Expand Down Expand Up @@ -294,7 +288,7 @@ const insertFormSubmission = async ({
version = '1',
encryptedContent = 'encryptedContent',
}: {
formId?: ObjectID
formId?: Schema.Types.ObjectId
submissionType?: string
version?: string
encryptedContent?: string
Expand All @@ -320,8 +314,8 @@ const insertFormFeedback = async ({
rating = '5',
comment = 'FormSG rocks!',
}: {
formId?: ObjectID
submissionId?: ObjectID
formId?: Schema.Types.ObjectId
submissionId?: Schema.Types.ObjectId
rating?: string
comment?: string
} = {}): Promise<{
Expand Down
Loading
Loading